How to import only selected native library ABIs from AAR?

10.1k views Asked by At

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.

4

There are 4 answers

3
mksaint13 On BEST ANSWER
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'
}
4
Mike Bonnell On

Mike from Fabric and Crashlytics here. With Splits, currently, we don't know in advance which density to provide the tester, so just add this line to your specific flavor or variant, to use the universal APK that is generated.

ext.betaDistributionApkFilePath = "path to the universal split APK"

Also, if you're using NDK crash reporting, in case it matches the crash you're seeing, check out this link.

1
Manuel Schmitzberger On

This works for me:

(e.g: only armeabi & armeabi-v7a)

build.gradle

android{
    defaultConfig{
        ndk{
            abiFilters "armeabi", "armeabi-v7a"
        }
    }
}
5
Jorge Galvão On

I had the same problem as you, but you actually helped me with the link you posted about APK Splits! In your case, try to add the following to your build.gradle inside the android closure:

    splits {
        abi {
            enable true
            reset()
            include 'armeabi-v7a', 'x86'
            universalApk true
        }
    }

The trick in there is to set the universalApk to true in order to generate only one APK with all the defined architectures, instead of splitting them up in several APKs.

Also don't forget the reset() which removes all the default values.