gpt4 book ai didi

Android Studio 更新 0.4.0 找不到 buildConfig()

转载 作者:IT老高 更新时间:2023-10-28 21:56:53 63 4
gpt4 key购买 nike

将 Android Studio 升级到 0.4.0 版后,我遇到了一个新错误:

我通过 gradle-wrapper.properties 升级到 gradle 1.9

distributionUrl=http\://services.gradle.org/distributions/gradle-1.9-all.zip

并在 build.gradle 中升级了 gradle 版本

dependencies {
classpath 'com.android.tools.build:gradle:0.7.+'
}

现在我的项目正在重新构建。

我为不同的 productFlavors 定义了一些字符串常量:

productFlavors {
local {
buildConfig "public static final String MY_KEY = \"\";"
}

alpha {
buildConfig "public static final String MY_KEY = \"XXXXX-XXXXX-XXX\";"
}

beta {
buildConfig "public static final String MY_KEY = \"YYYYY-YYYYY-YYY\";"
}
}

这是新的错误

Could not find method buildConfig() for arguments [public static final String MY_KEY = "";] on GroupableProductFlavorDsl_Decorated{name=local, minSdkVersion=-1, targetSdkVersion=-1, renderscriptTargetApi=-1, renderscriptSupportMode=null, renderscriptNdkMode=null, versionCode=-1, versionName=null, packageName=null, testPackageName=null, testInstrumentationRunner=null, testHandleProfiling=null, testFunctionalTest=null, signingConfig=null, resConfig=null}.

一切都在 Android Studio 3.7 上运行

最佳答案

我无法使用评论(太长)。您可以在 gradle 1.9 的新增功能中找到它。

DSL Changes: buildConfigLine is replaced by buildConfigField:

buildConfigField "boolean", "MY_FLAG", "true"

You can override fields defined in default config in flavors or build types. See 'basic' sample.

Build Config also now automatically contain more constants for PACKAGE_NAME, VERSION_CODE, VERSION_NAME, BUILD_TYPE, FLAVOR as well as FLAVOR_<group> if there are several flavor dimensions.

所以如果你有这样的一行:

buildConfig "public static final boolean MY_FLAG = true;"

您现在应该将其替换为以下内容:

buildConfigField "boolean", "MY_FLAG", "true"

在你的情况下:

buildConfigField "String" , "MY_KEY" ,  "\"XXXXX-XXXXX-XXX\""

2015 年 12 月 9 日更新:

使用新的实验性插件 (0.2.1),您必须使用:

buildConfigFields.with {
create() {
type = "String"
name = "MY_KEY"
value = "MY_VALUE"
}
}

关于Android Studio 更新 0.4.0 找不到 buildConfig(),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20678118/

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