I am currently using the OpenCV (OpenCV4Android) library which does not use the NDK (there is no C or C++ code). However, there are .so files for armeabi, armeabi-v7a, mips, and x86. If I include all of these in the project, the app size is 30mb, whereas if I include only 1, the app size is only 9mb. If I try to run the app on a device that doesn't have that device's architecture's .so file included, it crashes, whereas if I have it's .so file included, it works.
Therefore, I am wanting to release multiple APKs to different device architectures to reduce the file sizes. From what I've seen, this can only be done in the Application.mk file, but my library does not have one. Is there another way to target different Android architectures?
I am currently using the OpenCV (OpenCV4Android) library which does not use the NDK (there is no C or C++ code). However, there are .so files for armeabi, armeabi-v7a, mips, and x86.
As immibis put it, if there are .so
files, then it is using the NDK.
If I try to run the app on a device that doesn't have that device's architecture's .so file included, it crashes, whereas if I have it's .so file included, it works.
That depends upon the device. Many x86 devices have libhoudini
, which can run ARM NDK binaries, albeit more slowly than they would run native x86 binaries. Similarly, an armeabi-v7
device can run armeabi
NDK binaries, though perhaps more slowly, particularly if floating-point processing is used.
Therefore, I am wanting to release multiple APKs to different device architectures to reduce the file sizes. From what I've seen, this can only be done in the Application.mk file, but my library does not have one.
The Application.mk
file only controls what gets compiled, not what gets distributed.
Is there another way to target different Android architectures?
Use Gradle for Android, perhaps in conjunction with Android Studio, and the abi
split:
android {
...
splits {
abi {
enable true
reset()
include 'x86', 'armeabi-v7a', 'mips'
universalApk true
}
}
}
The abi
closure in the splits
closure:
opts into having different APK files per CPU architecture
sets up a whitelist of the architectures that you want
also requests a "universal APK" that contains all of the architectures, for use with distribution channels that do not support separate APKs by architecture
The result of your build will be separate APKs by CPU architecture, plus the universal one.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With