独立于 buildType 或 productFlavor 设置 resValue? [英] Set resValue independently of buildType or productFlavor?
问题描述
有没有办法独立使用 resValue
,i.e.除了任何 buildType
或 productFlavor
?
Is there a way to use resValue
independently of, i. e. outside of, any buildType
or productFlavor
?
我的 Android 项目中有一些 String 资源,我想从我的 build.gradle
中创建这些资源,这些资源不会随构建类型或产品风格而变化.例如,下面这行存储了当前 git commit 的 hash,以便它可以在设置中显示
I have some String resources in my Android project that I would like to create from within my build.gradle
which don't vary with either build type or product flavor. For example, the following line stores the hash of the current git commit so that it can displayed in the settings
resValue "string", "source_git_hash", gitHash
我发现我可以在 buildTypes
或 productFlavors
块中使用 all
块,但是这样,一切仍然执行一次对于每种构建类型/产品风格.
I found that I can use the all
block in either the buildTypes
or the productFlavors
block but this way, everything is still executed once for each build type/product flavor.
有没有办法全局写入资源值,所有构建只需一次?
Is there a way to write the resource value globally, just once for all builds?
推荐答案
defaultConfig
允许您在全局范围内设置相同种类的事情,而您无法针对每个产品风格进行设置.因此,将您的 resValue
和 buildConfigField
语句放在那里,以定义用于所有构建变体的默认值.
defaultConfig
allows you to set the same sorts of things globally that you can do no a per-product-flavor basis. So, put your resValue
and buildConfigField
statements in there, to define the defaults to be used for all build variants.
这篇关于独立于 buildType 或 productFlavor 设置 resValue?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!