Question

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

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

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

and upgraded the gradle version in build.gradle

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

Now my project is building again.

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

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}.

Everything was working with Android Studio 3.7

Was it helpful?

Solution

I can't use the comment (too long). You can find it in the what's new in 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.

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"

In your case:

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

UPDATE 12/09/2015:

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

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

OTHER TIPS

This version introduces a change:

buildConfigField "<type>", "<name>", "<value>"

If you have a line like this:

buildConfig "public static final boolean FLAG = true;"

Now you have to use:

buildConfigField "boolean", "FLAG", "true"

For String values you can use:

buildConfigField "String", "FOO", "\"foo\""

note: The previous DSL proprety:

buildConfigLine "<value>"

has changed to

buildConfigField "<type>", "<name>", "<value>"
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top