I’ve seen this guide on how to build split APKs for each ABI.
However my app embeds a bunch of native executables as assets. Is it possible to filter them based on the ABI?
Relevant parts of build.gradle
:
android {
...
splits {
abi {
enable true
}
}
externalNativeBuild {
cmake {
path "CMakeLists.txt"
// builds assets and places them in src/main/assets
}
}
sourceSets {
main {
assets.srcDirs = ['src/main/assets']
}
}
}
Sample app tree after building native executables with CMake:
src
+ main
+ assets
+ x86
| + native-x86.bin
+ x86_64
| + native-x86_64.bin
+ armeabi-v7a
| + native-arm.bin
+ arm64-v8a
+ native-aarch64.bin
Each ABI directory contains native binaries
I would like each split APK to contain only the ABI-specific assets directory, with the other ones filtered. For example, for the arm64 APK:
assets
+ arm64-v8a
+ native-aarch64.bin
check this Android documentation
One solution is to use Flavors.(didn’t test this)
productFlavors {
x86 {
jniLibs.srcDir = /path/to/native-x86.bin
//or maybe
assets.srcDirs = /path/to/native-x86.bin
ndk {
abiFilter "x86"
}
}
armv7 {
jniLibs.srcDir = /path/to/native-arm.bin
ndk {
abiFilter "armeabi-v7a"
}
}
Hope that will help you.
Tags: androidandroid