I have an android project with several dependencies. Two of them (let's call them dependency A and B) have native libraries (.so files).
Dependency A has the following architectures: arm64-v8a, armeabi, armeabi-v7a, x86 and x86_64. Dependency B has the following architectures: armeabi, x86
Thus when my app runs on an armeabi-v7a device (for instance), and dependency B calls a native method, it cannot find the relevant library to get it from (as it is not present in armeabi-v7a folder and does not fall back automatically to armeabi where the library is).
Is there any way to work around this? For instance, can I add some configuration to my build.gradle file in order for arm64-v8a, armeabi-v7a, and x86_64 folders not to be integrated to my final apk?
I have tried packagingOptions / exclude, but with no results : the folders in questions are still there.
Option 1) per-dependency exclude rules. When you specify a dependency in your build script, you can provide an exclude rule at the same time telling Gradle not to pull in the specified transitive dependency. For example, say we have a Gradle project that depends on Google's Guava library, or more specifically com.
The AAR format. is the binary distribution of an Android Library Project. As described here in the official Android Tools documentation. In your case, when adding a compile dependency in an Android Gradle project, adding "@aar" means that you would like to fetch the @aar file and not a regular JAR file.
Group and module are properties for looking up libraries within maven repositories. For your dependency com.google.http-client:google-http-client:1.20.0. Group is com.google.http-client , module is google-http-client and the version is 1.20.0 .
Try a clean build, I didn't and it was still picking up the files from the previous build. I ended up deleting my app/build/ folder just to be sure.
android { packagingOptions { exclude 'lib/armeabi-v7a/libSomeLibYouDontWant.so' } }
Worked for me on an app that was previously crashing.
An alternative would be to use
android{ defaultConfig{ ndk{ abiFilters "armeabi", "x86" } } }
There are some similar questions which might be helpful
Gradle exclude arm64 libs
How to use 32-bit native libraries on 64-bit Android device
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