25

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.

Mathieu Gardere
  • 273
  • 1
  • 3
  • 8

1 Answers1

40

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

Community
  • 1
  • 1
Deji
  • 536
  • 5
  • 8
  • 2
    Additionally, you can use the following syntax to **ignore an entire ABI folder**, for example, for `armeabi-v7a` folder: `exclude "lib/armeabi-v7a/**"` (See [PackagingOptions](https://google.github.io/android-gradle-dsl/current/com.android.build.gradle.internal.dsl.PackagingOptions.html)) – Eido95 Jun 19 '17 at 17:09
  • 4
    this will completely exclude 'lib/armeabi-v7a/libSomeLibYouDontWant.so' from project what if we need to exclude in particular dependency. – venkatesh venkey Dec 28 '18 at 06:12