MAGx2
MAGx2

Reputation: 3189

Cannot add buildConfigField in productFlavors

In my android{} section I tried to put two different build types for may free and paid app.

Sadly I'm getting gradle error:

Gradle 'android-Transport' project refresh failed: Build script error, unsupported Gradle DSL method found: 'buildConfigField()'! Possible causes could be: - you are using Gradle version where the method is absent - you didn't apply Gradle plugin which provides the method - or there is a mistake in a build script

This is my android{} section in gradle build:

android {
    compileSdkVersion 19
    buildToolsVersion "19.0.3"

    defaultConfig {
        minSdkVersion 10
        targetSdkVersion 19
        versionCode 1
        versionName "1.0"
    }

    compileOptions {
        sourceCompatibility JavaVersion.VERSION_1_6
        targetCompatibility JavaVersion.VERSION_1_6
    }

    buildTypes {
        release {
            runProguard true
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.txt'
        }

        debug {
            debuggable true
            runProguard false
        }
    }

    productFlavors {
        free {
            packageName "pl.grzeslowski.transport.free"
            buildConfigField "transport.product_flavors.MonetizationType" "MONETIAZATION_TYPE" "transport.product_flavors.MonetizationType.FREE"
        }

        paid {
            packageName "pl.grzeslowski.transport.paid"
            buildConfigField "transport.product_flavors.MonetizationType" "MONETIAZATION_TYPE" "transport.product_flavors.MonetizationType.PAID"
        }
    }
}

And this is my console log:

Executing tasks: [:transport:compileDebugJava]

Configuration on demand is an incubating feature. Download http://repo1.maven.org/maven2/com/android/tools/build/gradle/0.8.3/gradle-0.8.3.pom Download http://repo1.maven.org/maven2/com/android/tools/lint/lint/22.5.3/lint-22.5.3.pom Download http://repo1.maven.org/maven2/com/android/tools/build/builder/0.8.3/builder-0.8.3.pom Download http://repo1.maven.org/maven2/com/android/tools/lint/lint-checks/22.5.3/lint-checks-22.5.3.pom Download http://repo1.maven.org/maven2/com/android/tools/sdklib/22.5.3/sdklib-22.5.3.pom Download http://repo1.maven.org/maven2/com/android/tools/ddms/ddmlib/22.5.3/ddmlib-22.5.3.pom Download http://repo1.maven.org/maven2/com/android/tools/build/builder-model/0.8.3/builder-model-0.8.3.pom Download http://repo1.maven.org/maven2/com/android/tools/build/manifest-merger/22.5.3/manifest-merger-22.5.3.pom Download http://repo1.maven.org/maven2/com/android/tools/sdk-common/22.5.3/sdk-common-22.5.3.pom Download http://repo1.maven.org/maven2/com/android/tools/build/builder-test-api/0.8.3/builder-test-api-0.8.3.pom Download http://repo1.maven.org/maven2/com/android/tools/common/22.5.3/common-22.5.3.pom Download http://repo1.maven.org/maven2/com/android/tools/lint/lint-api/22.5.3/lint-api-22.5.3.pom Download http://repo1.maven.org/maven2/com/android/tools/dvlib/22.5.3/dvlib-22.5.3.pom Download http://repo1.maven.org/maven2/com/android/tools/layoutlib/layoutlib-api/22.5.3/layoutlib-api-22.5.3.pom Download http://repo1.maven.org/maven2/com/android/tools/build/gradle/0.8.3/gradle-0.8.3.jar Download http://repo1.maven.org/maven2/com/android/tools/lint/lint/22.5.3/lint-22.5.3.jar Download http://repo1.maven.org/maven2/com/android/tools/build/builder/0.8.3/builder-0.8.3.jar Download http://repo1.maven.org/maven2/com/android/tools/lint/lint-checks/22.5.3/lint-checks-22.5.3.jar

FAILURE: Build failed with an exception.

  • Where: Build file 'D:\Programowanie\GitProjects\transport\android-Transport\transport\build.gradle' line: 77

  • What went wrong: A problem occurred evaluating project ':transport'.

    Could not find method buildConfigField() for arguments [transport.product_flavors.MonetizationType] on GroupableProductFlavorDsl_Decorated{name=free, minSdkVersion=-1, targetSdkVersion=-1, renderscriptTargetApi=-1, renderscriptSupportMode=null, renderscriptNdkMode=null, versionCode=-1, versionName=null, packageName=transport.free, testPackageName=null, testInstrumentationRunner=null, testHandleProfiling=null, testFunctionalTest=null, signingConfig=null, resConfig=null}.

  • Try: Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output.

BUILD FAILED

Total time: 9.781 secs

Upvotes: 14

Views: 10312

Answers (2)

Louis Nguyen
Louis Nguyen

Reputation: 345

In my case:

buildConfigField ("transport.product_flavors.MonetizationType", "MONETIAZATION_TYPE", "transport.product_flavors.MonetizationType.FREE")

Upvotes: 1

Peter Niederwieser
Peter Niederwieser

Reputation: 123910

The correct syntax for the buildConfigField lines is:

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

In other words, the strings need to be separated by commas.

Upvotes: 34

Related Questions