How to import only selected native library ABIs from AAR?

DoDo picture DoDo · Jun 19, 2015 · Viewed 8.9k times · Source

I have a bit unusual problem - my Android app contains native libs and I build native libs for armeabi-v7a and x86. However, now I need to integrate a third party library into my app which also contains native libraries (third party library is Crashlytics which I included via Maven from my build.gradle.). The problem is that third party library's AAR provides all arhitectures (armeabi, arm64-v8a, armeabi-v7a, mips, mips64, x86 and x86_64) and my app only supports armeabi-v7a and x86 (arm64-v8a is planned for near future), so when final apk is built it contains 3rd party library's all ABI's and only x86 and armeabi-v7a ABI's of my native code. This causes my app to crash when launched on arm64 device like Galaxy S6.

My question is: is it possible to include only selected ABI's from 3rd party AAR?

Please note that I am aware of APK splits, but this only solves my problem partially, i.e. it works only if I distribute my app via Play Store. Although Play Store supports beta test distribution, the propagation of updated APK is rather slow, so prior pushing an update to app's PlayStore beta channel, we push an update via Crashlytics' beta distribution system, which is much faster. The problem is that Crashlytics' distibution system does not support APK splits (or am I wrong?). Therefore, I actually need to build an "universal" APK that will contain only selected ABIs. How to achieve that?

Although I would be satisfied even with Crashlytics'-specific answers (like for example, how to distribute APK splits via their beta channel), I would be much more satisfied with solution for building "universal" APK that contains only selected ABIs, because at our company we also provide SDKs to our clients as AAR archives that contain only supported architectures and we would like to instruct them how to handle case when they integrate our SDK with other SDKs that have different ABI's supported.

I am using latest stable Android studio (1.2.1.1), gradle 2.4 and android gradle plugin version 1.2.3.

Answer

mksaint13 picture mksaint13 · Jan 11, 2016
packagingOptions {
    exclude 'lib/arm64-v8a/libcrashlytics-envelope.so'
    exclude 'lib/arm64-v8a/libcrashlytics.so'
    exclude 'lib/armeabi/libcrashlytics-envelope.so'
    exclude 'lib/armeabi/libcrashlytics.so'
    exclude 'lib/mips64/libcrashlytics-envelope.so'
    exclude 'lib/mips64/libcrashlytics.so'
    exclude 'lib/mips/libcrashlytics-envelope.so'
    exclude 'lib/mips/libcrashlytics.so'
    exclude 'lib/x86_64/libcrashlytics-envelope.so'
    exclude 'lib/x86_64/libcrashlytics.so'
}