Does Android Studio create build option / type excluding jniLibs?

I have an Android app that uses its own JNI library. I put it in app/src/main/jniLibs/armeabi-v7a without any gradle configuration, and Android Studio happily associates it with the APK.

I have a requirement when all the native libraries cannot be associated with a particular distribution. Is it possible to create an assembly variant or an assembly type that simply excludes all native libraries (possibly even by the name of .so ).

The fact that the native library is missing from this distribution does not matter because it is not used. An alternative is the physical removal of files, the start of the assembly, their return. However, it is painful and error prone.

+5
source share
1 answer

From your build.gradle we can find out what needs to be done exactly.

I used productFlavours in combination with flavorDimensions to implement assemblies that may or may not include jni libraries.

From what I understand, the gist of this is: productFlavors allows you to have n variants of x, y ... type, adding flavorDimensions will allow you to have n variants of xy type.

Eg. Inside build.gradle ,

  flavorDimensions "abi", "version" //this is what can help you build with/w/o jni libraries productFlavors { devel { flavorDimension "abi" //keep a dimension common with arm, armv7 applicationId "com.packagename.dev" } prod { flavorDimension "version" // this would be your build w/o the ndk support then applicationId "com.packageName" } armv7 { ndk { flavorDimension "abi" abiFilter "armeabi-v7a" } } arm { ndk { flavorDimension "abi" abiFilter "armeabi" } } } 

As you can see, you will have several build options, product tastes depending on flavorDimension .

prod flavor will be a build option or build type that just excludes all native libraries

Sources for ndk, jniLibs, buildFlavours ... themes:
- Mastering "Product Flavors" on Android
- ndk-with-android-studio
- setting multiple flavors

+2
source

All Articles