Android Studio 创建不包括 jniLibs 的构建变体/类型? [英] Android Studio create a build variant / type excluding jniLibs?

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

问题描述

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

我有一个要求,即所有本机库都不能与某个发行版捆绑在一起.是否可以创建一个简单地排除所有本机库的构建变体或构建类型(甚至可以通过名称 .so).

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

解决方案

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

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

据我所知,它的要点是:productFlavors 使您能够拥有 x、y... 类型的 n 个变体,添加 flavorDimensions 将使您能够拥有n 个 xy 类型的变体.

例如.build.gradle 里面,

 flavorDimensions "abi", "version"//这可以帮助您使用/不使用 jni 库进行构建产品风味{开发{flavorDimension "abi"//保持一个与 arm、armv7 相同的维度applicationId "com.packagename.dev"}产品{风味维度版本"//这将是没有 ndk 支持的构建applicationId "com.packageName"}armv7 {ndk{风味维度abi"abiFilter "armeabi-v7a"}}手臂 {ndk{风味维度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 创建不包括 jniLibs 的构建变体/类型?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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