问题描述
有关我的编译系统,我需要建立多个应用程序的变种,每个请求一组不同的权限。怎么可以这样跟摇篮完成,而无需调用一个单独的脚本?
For my build system, I need to build several app variants, each requesting a different set of permissions. How can this be done with Gradle, without invoking a separate script?
推荐答案
我勉强通过在我的摇篮文件不同的口味,以做到这一点:
I just managed to do this by having different flavors in my gradle file:
free {
packageName 'com.sample.free'
buildConfigField "boolean", "HAS_AD", "true"
}
paid {
packageName 'com.sample.paid'
buildConfigField "boolean", "HAS_AD", "false"
}
然后我创建src下一个新的文件夹,名为自由,并根据一个所谓的资源文件夹
and then I created a new folder under src called "free" and under that a folder called "res"
src/
+ free/
| + res/
+ src/
和该文件夹中在其中创建一个新的文件AndroidManifest.xml中具有以下code:
and in that folder create a new file "AndroidManifest.xml" with the following code in it:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.sample" >
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
</manifest>
据在Android工具项目网站摇篮Plugin用户指南:
要生成类型相似,产品口味也有助于code和 通过自己sourceSets资源
和
在所有使用的sourcesets处理以下规则使用 建立一个单一的APK:
- 所有的源$ C $ C(SRC / * / JAVA)一起使用的多个文件夹中生成一个输出。
- 的舱单全部合并成一个单一的清单。这使得产品的香精具有不同的组件和/或 权限,类似于生成类型。的
- 所有的资源(安卓资源和资产)使用覆盖优先权的生成类型覆盖了产品的风味,用这 覆盖主要sourceSet。
- 在每一个变化范围产生自己的研发从资源类(或其他产生源$ C $ C)。没有什么是共享 变种。
- All source code (src/*/java) are used together as multiple folders generating a single output.
- Manifests are all merged together into a single manifest. This allows Product Flavors to have different components and/or permissions, similarly to Build Types.
- All resources (Android res and assets) are used using overlay priority where the Build Type overrides the Product Flavor, which overrides the main sourceSet.
- Each Build Variant generates its own R class (or other generated source code) from the resources. Nothing is shared between variants.
这意味着您可以创建在src每种口味名称的文件夹,并把你的自定义文件在其中。如果说,文件是一个AndroidManifest摇篮将合并其与表现为主。
meaning that you can create a folder with each flavor name under src and put your custom files in them. If said file is an AndroidManifest gradle will merge it with the manifest in the main.
这篇关于摇篮:如何定制Android清单的权限?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!