有条件地将元数据包含在Android清单文件中 [英] Conditionally include meta-data in Android manifest file
问题描述
是否可以根据Gradle中设置的值在Android清单文件中有条件地包含meta-data
元素.我能够执行以下操作(在build.gradle
中使用resValue
设置<some_value>
),但无法找到方法来包含/排除完整的meta-data
元素.
Is there way to conditionally include meta-data
element in Android manifest file based on value set in Gradle. I am able to do following (using resValue
to set <some_value>
in build.gradle
) but haven't been able to find way to include/exclude complete meta-data
element.
<meta-data
android:name="<some_setting>"
android:value="@string/<some_value>" />
推荐答案
某种程度上,但我能够解决此问题的唯一方法是在build.gradle
(我在具有不同构建风格的情况下使用了此功能,但并不依赖于此)...我认为围绕清单合并可以做一些其他的聪明事,这也将使它变得更干净. myFlag
来自我作为Fastlane
脚本一部分传递的project.hasProperty()
值
Somewhat of a hack but only way I've been able to address this is by having something like following (have changed names in example) in build.gradle
(am using this in context of having different build flavors as well but isn't dependent on that)...I think there's probably some additional smarts that can be done around manifest merging that would make this a bit cleaner as well. myFlag
is coming from a project.hasProperty()
value I'm passing in as part of Fastlane
script
sourceSets {
flavor1 {
if (myFlag == "true") {
manifest.srcFile "src/flavor1_flag/AndroidManifest.xml"
} else {
manifest.srcFile "src/flavor1/AndroidManifest.xml"
}
}
}
这篇关于有条件地将元数据包含在Android清单文件中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!