I have developed Ionic v3.20 APK and want to integrate it in another third party android app. I was able to create android library(.aar) from existing Ionic project but having issues while running from another app.
I have few ionic native plugins(HTTP, WebIntent, etc…) and these plugins are not bundled with .aar file. Can any one suggest the approach to bundle the Cordova plugins while generating android library(SDK).
I have followed this link to generate .aar file,
Showing the below error while calling web intent,
2022-05-17 15:22:57.618 18126-18126/com.example.sdkproj D/SystemWebChromeClient: file:///android_asset/www/build/vendor.js: Line 1704 : ERROR Error: Uncaught (in promise): TypeError: Cannot read properties of undefined (reading ‘getUri’)
Android doesn’t support loading AARs from other AARs. Instead, what I’ve found that works, is use
compileOnly in your library to reference the other AARs, and then have the developer use
implementation to reference those AARs in their
Hope that gives you a lead to pursue!
Thanks @max. Can you please explain or provide any reference to do this? For example, I have installed ionic native plugin(GitHub - silkimen/cordova-plugin-advanced-http: Cordova / Phonegap plugin for communicating with HTTP servers. Allows for SSL pinning!) and want to bundle this plugin while creating
.aar. Actually one of my client want to integrate this library in to their android app.
I did not found any solution to achieve this. It would be great some one from Ionic team can help us to create a Ionic library from existing APK?
Cordova plugins aren’t AARs, they’re just a loose association of source files that are copied into your app project. So, you would copy those files into an Android Library project (AAR) and then distribute that AAR to app developers who would then reference that AAR in their Android app (APK)
@max : Thanks for your support.
We are developing Ionic apps since almost 4years but lack of experience in SDK implementation.
Basically we were doing the below changes while creating android library(.aar)
apply plugin: 'com.android.library’ in build.gradle
Commenting the applicationId privateHelpers.extractStringFromManifest(“package”)
And finally running this command in android studio: gradlew assemble
Successfully created the .aar file but could not see the Cordova plugins(plugins are listed but JS files are not copied) in `www\plugins\com.virtualartifacts.webintent\www’ folder.
Can you please tell where we can copy the Cordova plugins while creating .aar file?
I’m not sure if/how this will work with Cordova, since it’ll require the Cordova/Capacitor Cordova compat tooling to understand the AAR and look into it to load JS files, which I don’t think will work.
You can definitely get the native code side of this to work, but would probably need to handle the JS files differently. Probably more trouble than it’s worth for a Cordova plugin. Probably much more doable for capacitor plugins