6

My app has a dev and production flavor defined in Gradle. In my production flavor, I would like the resulting APK file to NOT have my x86 jniLibs binaries. I only use them for testing in genymotion, and some of them are large so I really need the space.

The only way I can get this to kinda work is by manually deleting my src/main/jniLibs/x86 folder then building, but I then have to do this every time I build, and then restore the libs later. Is there a simpler way using gradle/proguard/something?

2 Answers 2

15

Here is the configuration to exclude x86 SO file for RELEASE build variant:

android {
    buildTypes {
        release {
            ndk {
                abiFilters "armeabi-v7a", "armeabi" // includes ARM SO files only, so no x86 SO file
            }
        }
    }
}

And, there is x86 SO in the "debug" build variant output since no filter is set.

2
  • 3
    Thank you so much for putting the full android.buildTypes.release.ndk structure in there: it drives me up the wall when folks assume familiarity with the whole thing and only cite the last couple of components. (Is there some chart with all the components listed that everyone else knows about and I didn't receive in the post?) Oct 27, 2016 at 7:34
  • The ndk section is also allowed in flavor sections thus also in defaultConfig. To completely filter out all processors you can write: ndk { abiFilters "" }
    – qwlice
    Jan 11, 2019 at 14:46
3

Move the lib from app/src/main/jniLibs/x86 to app/src/debug/jniLibs/x86

6
  • I created app/src/debug/jniLibs and copied armeabi, armeabi-v7a, and x86 folders into it. I removed x86/ from app/src/main/jniLibs. When I rebuild and run, I get "Failure [INSTALL_FAILED_NO_MATCHING_ABIS]". Also, the jniLibs reside in my library android app, not the specific module.
    – John D.
    Jun 12, 2015 at 3:44
  • Are you building in release or debug mode? Error says no matching abis, does your code need those libs (when cross compiling for arm architecture)? If yes, you should leave the armeabi-* in main, as it'll be used in any flavor. Only move the x86 libs outta main.
    – mbmc
    Jun 12, 2015 at 4:08
  • I'm building in debug mode. It seems like the build process is ignoring this new src/debug/jniLibs folder because I removed x86 and now it fails on genymotion. But if I install on a phone, it works fine, because it can still find the armeabi files. How can I tell it to package the new src/debug/jniLibs folder when in debug variant?
    – John D.
    Jun 12, 2015 at 4:14
  • Ok. How about you tell gradle to look into the debug folder when building for x86: productFlavors { x86 { sourceSets.debug { jniLibs.srcDir 'src/debug/jniLibs' } } }
    – mbmc
    Jun 12, 2015 at 4:22
  • 1
    The behavior I'm seeing is very strange. I removed src/main/jniLibs, created src/debug/jniLibs and src/release/jniLibs, and regardless of what I put into my gradle file, it uses src/release/jniLibs whenever I build, even if my Android Studio's Build Varients view has everything set to debug. Maybe it's a gradle-android bug? Who knows...
    – John D.
    Jun 12, 2015 at 22:34

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.