For compiling native prebuilt libraries we use NDK toolchain with these two options -DANDROID_ABI
and -DANDROID_PLATFORM
, so in case if we support android-28
, android-29
platforms and armeabi-v7a
, arm64-v8a
, x86
, x86_6
ABIs we will have to sets of produced libraries:
.
├── android-28
│?? ├── arm64-v8a
│?? │?? └── libMy.so
│?? ├── armeabi-v7a
│?? │?? └── libMy.so
│?? ├── x86
│?? │?? └── libMy.so
│?? └── x86_64
│?? └── libMy.so
└── android-29
├── arm64-v8a
│?? └── libMy.so
├── armeabi-v7a
│?? └── libMy.so
├── x86
│?? └── libMy.so
└── x86_64
└── libMy.so
We can easily use such obtained prebuilts in Android cmake, because it supports${ANDROID_PLATFORM}
and ${ANDROID_ABI}
variables, e.g. CMakeLists.txt
:
...
list(APPEND CMAKE_FIND_ROOT_PATH ${THIRDPARTY_PREBUILT_DIR}/${ANDROID_PLATFORM}/${ANDROID_ABI}/mylib)
...
But packaging these prebuilts into APK seems not clear for me because app/src/main/jniLibs
doesn't support platform hierarchy but only ABI:
.
└── jniLibs
├── arm64-v8a
│?? └── libMy.so
├── armeabi-v7a
│?? └── libMy.so
├── x86
│?? └── libMy.so
└── x86_64
└── libMy.so
And also the same structure in output app-debug.apk/lib
.
So the question: Why do we have in toolchain and Android cmake options to differ platforms but packaging of native libraries (jni libraries) ignores them?
I use Android Studio 3.6.3
with Gradle 5.6.4
.
question from:
https://stackoverflow.com/questions/66061317/how-to-package-native-prebuilts-libraries-for-android-different-platforms 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…