7

Contrary to many other posts on this topic, I want to exclude a native library from an Android build with Gradle.

libfoo.so resides in a library project in the default directory thelib/src/main/jniLibs. In my main project's build.gradle I try to exlude the file as follows:

sourceSets {
    all{
        jniLibs {
            exclude '**/libfoo.so'
        }
    }
}

This does not work though, the file is still in the final APK. I tried different path specifications already, but none of them work.

Is this even possible, or is there a workaround?

langerhans
  • 769
  • 7
  • 19

1 Answers1

8

I know this is an old question, i solved my problem with the following

packagingOptions {
 exclude 'lib/arm64-v8a/libfoo.so'
}

Hope it helps someones...

Note: On further searching someone had already solved a similar issue; Gradle exclude arm64 libs

Community
  • 1
  • 1
user3689913
  • 382
  • 4
  • 10
  • Thanks for the reply anyway! I later encountered this error: https://code.google.com/p/android/issues/detail?id=185982 , but since your solution technically works for the simple case I described, I'll accept your answer. – langerhans May 09 '16 at 21:18
  • @langerhans thanks for that... in my case i never encountered the dependency issue but what i did was to add a conditional flag to my build.gradle and do something like this in my dependencies section if(flag_is_set) compile 'com.foo:libfoo:1.0.0'; and also in my packagingOptions section; if(flag_is_set) exclude 'lib/arm64-v8a/libfoo.so' – user3689913 May 10 '16 at 08:39
  • I have to admit my use case is a bit odd, but the dependency is required regardless as it holds a fallback implementation of the native libs features. Thanks anyway! – langerhans May 10 '16 at 10:09