Android Studio create a build variant / type excluding jniLibs?

倖福魔咒の 提交于 2021-02-07 13:30:19

问题


I have an Android application that uses a native JNI library. I put it into app/src/main/jniLibs/armeabi-v7a without any gradle configuration and Android studio happily bundles it into the APK.

I have a requirement where all native libraries cannot be bundled with a certain distribution. Is it possible to create a build variant or build type that simply excludes all native libraries (maybe even by name .so).

The fact that the native library is missing in this distribution doesn't matter because it's not used. The alternative is to physically remove the files, run the build, put them back. However, this is painful and error prone.


回答1:


From your build.gradle, we may be able to know what is to be done precisely.

I have used productFlavours, combined with flavorDimensions to implement builds which may or may not include jni libraries.

From what i understood, gist of it is: productFlavors enable you to have n variants of x, y... type, adding flavorDimensions would enable 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 multiple build variants , product flavors depending on flavorDimension.

prod flavor would be a build variant or build type that simply excludes all native libraries

Sources for topics ndk, jniLibs, buildFlavours... :
- Mastering "Product Flavors" on Android
- ndk-with-android-studio
- multi flavor setup



来源:https://stackoverflow.com/questions/30995947/android-studio-create-a-build-variant-type-excluding-jnilibs

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!