Android Studio是否创建排除jniLib的构建变体/类型? [英] Android Studio create a build variant / type excluding jniLibs?

查看:103
本文介绍了Android Studio是否创建排除jniLib的构建变体/类型?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个使用本机JNI库的Android应用程序.我将它放入没有任何gradle配置的 app/src/main/jniLibs/armeabi-v7a 中,Android Studio高兴地将其捆绑到APK中.

我有一个要求,即所有本机库不能与特定发行版捆绑在一起.是否有可能创建一个仅排除所有本机库的构建变体或构建类型(甚至可能按名称 .so ).

此发行版中缺少本机库这一事实并不重要,因为未使用它.另一种方法是物理删除文件,运行构建,然后将它们放回原处.但是,这很痛苦且容易出错.

解决方案

从您的 build.gradle 中,我们也许能够准确地知道要做什么.

我使用了 productFlavours flavorDimensions 组合来实现可能包含或不包含jni库的构建.

据我了解,要点是: productFlavors 使您可以拥有x,y ...类型的n个变体,添加 flavorDimensions 可以使您拥有xy类型的n个变体.

例如.内 build.gradle

  flavourDimensions"abi","version"//这可以帮助您使用/不使用jni库进行构建productFlavors {开发{flavourDimension"abi"//保持与arm,armv7相同的尺寸applicationId"com.packagename.dev"}产品{flavourDimension版本"//这是没有ndk支持的构建applicationId"com.packageName"}armv7 {ndk {flavourDimension"abi"abiFilter"armeabi-v7a"}}手臂 {ndk {flavourDimension"abi"abiFilter"armeabi"}}} 

如您所见,您将有多种版本,产品口味取决于 flavorDimension .

prod 风格将是一种构建变体或构建类型,它仅排除了所有本机库

ndk,jniLibs,buildFlavours ...主题的来源:
-在Android上掌握产品风味"
- ndk-with-android-studio
-多种口味设置

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.

解决方案

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

这篇关于Android Studio是否创建排除jniLib的构建变体/类型?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆