gpt4 book ai didi

android - 为每个 Build Variant 使用不同的 manifestPlaceholder

转载 作者:IT老高 更新时间:2023-10-28 22:20:40 25 4
gpt4 key购买 nike

我首先要说我对 Gradle 很陌生,所以如果这个问题已经得到解答,我深表歉意。

我正在开发一个使用 API key 访问第三方工具的 Android 应用程序。根据应用的flavor构建类型,需要使用不同的 API key 。

这是我正在尝试做的基本概述:

android {
defaultConfig {
manifestPlaceholders = [ apiKey:"DEBUG_KEY" ]
}

buildTypes{
debug{
// Some debug setup
}
release{
// Some release setup
}
}

productFlavors {
// List of flavor options
}
productFlavors.all{ flavor->
if (flavor.name.equals("someFlavor")) {
if (buildType.equals("release")) {
manifestPlaceholders = [ apiKey:"RELEASE_KEY_1" ]
} else {
manifestPlaceholders = [ apiKey:"DEBUG_KEY" ]
}
} else {
if (buildType.equals("release")) {
manifestPlaceholders = [ apiKey:"RELEASE_KEY_2" ]
} else {
manifestPlaceholders = [ apiKey:"DEBUG_KEY" ]
}
}
}
}

到目前为止,manifestPlaceholders 语句在一个非常简单的情况下工作,但我不知道如何从 productFlavors 中引用 buildType strong> block ,以便我可以将其用作条件。

最佳答案

您可以通过访问特定 applicationVariant 的mergedFlavor 来在 applicationVariants 中设置 manifestPlaceholders。

android.applicationVariants.all { variant ->
def mergedFlavor = variant.getMergedFlavor()
mergedFlavor.manifestPlaceholders = [appPackageId: "myPackageExample"]
}

如果您使用的是 Kotlin DSL,则应该使用如下内容:

android.applicationVariants.all { // don't put 'variant ->' here or you'll get the 'all' extension function
// no need to define 'mergedFlavor' because 'this' _is_ the variant so 'mergedFlavor' is already available.
mergedFlavor.manifestPlaceholders = ...
}

关于android - 为每个 Build Variant 使用不同的 manifestPlaceholder,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31461267/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com