是否可以使用Gradle将AndroidManifest添加到特定的buildType(而不是产品风味)? [英] Is it possible to add an AndroidManifest to a specific buildType with Gradle (not product flavor)?

查看:76
本文介绍了是否可以使用Gradle将AndroidManifest添加到特定的buildType(而不是产品风味)?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我们正在努力设置一些活动检测测试,以在构建服务器上运行.由于这需要唤醒设备,因此我发现的选项似乎是:

We're working on setting up some Activity instrumentation tests to run on a build server. Since this requires the device to be awake, the options that I've found seem to be:

  1. 将设备设置为保持清醒"并禁用屏幕锁定

  1. Set the devices to "Stay Awake" and disable the screen lock

在测试用例中以编程方式禁用Keyguard(如此处)

Disable the Keyguard programmatically in the test case (as described here)

选项1看起来不太好,因为它浪费了电池,并最终会导致设备显示屏上的烙印.选项2似乎更可取,但我宁愿严格保留DISABLE_KEYGUARD权限来调试构建(而不是发行版),以便所有产品类型都可以测试,但是从不要求对发行版本进行许可.

Option 1 doesn't seem great as it wastes the battery and will eventually cause burn-in on the device displays. Option 2 seems preferable, but I'd rather keep the DISABLE_KEYGUARD permission strictly to debug builds (not release) so that all product flavors are testable, but the permission is never requested for a release build.

我知道我们可以添加清单以使用 sourceSets 进行合并:

I know we can add manifests to merge using sourceSets:

android.sourceSets.development {
    manifest.srcFile 'development/AndroidManifest.xml'
}

但是我还没有找到一种仅针对特定构建类型的等效方法-像这样(无效):

But I've not yet found an equivalent way to do so only for specific build types -- something like this (which isn't valid):

buildTypes {
    debug {
         manifest.srcFile 'debug/AndroidManifest.xml'
    }
}

有官方的方法吗?还有其他建议吗?谢谢!

Is there an official way to do this? Any other recommendations? Thanks!

推荐答案

对于构建类型,您可以具有与风味相同的sourceSets.这应该起作用:

You can have sourceSets for build types the same way as for flavors. This should work:

android.sourceSets.debug {
    manifest.srcFile 'debug/AndroidManifest.xml'
}

话虽如此,目录结构意味着除非使用非默认布局,否则无需手动配置sourceSet.在标准结构中,您可以执行此操作,而根本不在构建文件中配置sourceSets:

Having said that, the directory structure means that you shouldn't need to manually configure sourceSets unless you're using a non-default layout. In the standard structure you can do this and not configure sourceSets in your build file at all:

module_directory
+--src
   +--main
      +--AndroidManifest.xml
      +--java
      +--res
   +--flavor1
      +--AndroidManifest.xml
      +--java
      +--res
   +--debug
      +--AndroidManifest.xml
      +--java
      +--res
   +--release          
      +--AndroidManifest.xml
      +--java
      +--res

这篇关于是否可以使用Gradle将AndroidManifest添加到特定的buildType(而不是产品风味)?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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