apache / cordova-android

Apache Cordova Android
https://cordova.apache.org/
Apache License 2.0
3.59k stars 1.52k forks source link

Specify target architecture at build time #1643

Closed tanukki2929 closed 2 months ago

tanukki2929 commented 8 months ago

Even if I specify the options at build time as shown below, the output apk is created for all Arch's, not just arm64. In Cordova-Android11, only the specified arm64 was output.

--gradleArg=-PcdvBuildMultipleApks=true --gradleArg=-PcdvBuildArch=arm64 --packageType=apk

Is there something wrong with the procedure or has something changed in Cordova-Android12? I would be grateful if you could enlighten me.

breautek commented 8 months ago

or has something changed in Cordova-Android12?

I don't think this changed at all for years but it was primarily used to support crosswalk which all maintenance and support of that project stopped in 2017. Crosswalk plugin did use this but it also had it's own gradle config so it's possible that the pure cordova implementation was always broken and the crosswalk plugin just worked around it.

In modern development, android bundles should replace the need to manually create manual APK variants. The produced bundle is what you normally would upload to Google Play. But you can also use bundletool (the tool used by Google Play itself) to create apk sets and extract either a universal or device-specific APKs.

May I ask your use case for wanting to use the feature and why bundle tools doesn't fit your needs?

tanukki2929 commented 8 months ago

On the following page, the properties (cdvBuildArch and cdvBuildMultipleApks) appeared to still exist, but are they gone after 12 years? I would like to know the alternative method.

https://cordova.apache.org/docs/en/latest/guide/platforms/android/index.html#setting-gradle-properties

breautek commented 8 months ago

Sorry for the misunderstanding. They do still exist, as you can see here and here (among other places in the gradle script). But what I'm saying is what primary used by third-party tools that supplied native shared libraries that was architecture specific, and those tools aren't around anymore so I don't think these are used very often and they aren't really maintained or tested.

Additionally using mulltiple APKs today is obsolete, even if you have shared libraries embedded that are architecture specific. That's because the android app bundles provides a way to create a device-specific APK on the fly so each device can get the most optimized version of the APK as possible.

Cordova by default will produce an APK when building a debug version, since it assumes you're going to deploy to a local device or emulator. By default it will produce an AAB (Android App Bundle) file when building with --release flag as Google Play expects bundle files, not APKs.

I do not know if cdvBuildMultipleApks actually works or not, but bundles should replace the need to manage multiple APKs manually.