Android的Studio更新0.4.0找不到buildConfig() [英] Android Studio Update 0.4.0 could not find buildConfig()

查看:2510
本文介绍了Android的Studio更新0.4.0找不到buildConfig()的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在升级Android的工作室到0.4.0版本,我得到了一个新的错误:

After upgrading Android Studio to version 0.4.0 I got a new error:

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

I upgraded to gradle 1.9 via the gradle-wrapper.properties

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

和升级的摇篮版本build.gradle

and upgraded the gradle version in build.gradle

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

现在我的项目是建设了。

Now my project is building again.

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

I have some String constants defined for different 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\";"
    }
}

这里是新的错误

And here is the new error

找不到方法buildConfig()的参数 [公共静态最后弦乐MY_KEY =;]上GroupableProductFlavorDsl_Decorated {名称=本地,的minSdkVersion = -1,targetSdkVersion = -1,renderscriptTargetApi = - 1,renderscriptSupportMode = NULL,renderscriptNdkMode = NULL,版本code = -1,VERSIONNAME = NULL,的packageName = NULL,testPackageName = NULL,testInstrumentationRunner = NULL,testHandleProfiling = NULL,testFunctionalTest = NULL,signingConfig = NULL,resConfig = NULL }

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工作室3.7

Everything was working with Android Studio 3.7

推荐答案

我不能使用注释(太长了)。 你可以找到它在什么新的摇篮1.9。

I can't use the comment (too long). You can find it in the what's new in gradle 1.9.

DSL变化: buildConfigLine 替换 buildConfigField

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

您可以覆盖默认配置的口味定义的字段或生成类型。见基本的样本。

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

建立配置现在也自动包含 PACKAGE_NAME VERSION_ code ,<$ C $多个常量C> VERSION_NAME , BUILD_TYPE 以及 FLAVOR_&LT ;组&gt; 如果有多个口味尺寸

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.

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

So if you have a line like this:

buildConfig "public static final boolean MY_FLAG = true;"

您现在应该取代它的是这样的:

You should now replace it for something like this:

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

在你的情况:

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

更新2015年12月9号:

随着新的实验插件(0.2.1),你必须使用:

With the new experimental plugin (0.2.1) you have to use:

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

这篇关于Android的Studio更新0.4.0找不到buildConfig()的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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