Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Gradle DSL method not found: 'buildConfigField()'

Tags:

android

gradle

I had this gradle error

Error:(21, 0) Gradle DSL method not found: 'buildConfigField()' Possible causes:

<ul><li>The project 'Sunshine' may be using a version of Gradle that does not contain the method.

<a href="openGradleSettings">Gradle settings</a></li><li>The build file may be missing a Gradle plugin.

<a href="apply.gradle.plugin">Apply Gradle plugin</a></li>

my build.gradle code is here

apply plugin: 'com.android.application'

android {
    compileSdkVersion 23
    buildToolsVersion "23.0.3"

    defaultConfig {
        applicationId "com.example.boxerrebellion.sunshine.app"
        minSdkVersion 15
        targetSdkVersion 23
        versionCode 1
        versionName "1.0"
    }
    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
    }
    buildTypes.each {
         it.buildConfigField 'String', 'OPEN_WEATHER_MAP_API_KEY'
    }
}

dependencies {
    compile fileTree(dir: 'libs', include: ['*.jar'])
    compile 'com.android.support:appcompat-v7:23.3.0'
}

anyone having any idea? thanks in advance


1 Answers

This is a very annoying how gradle works issue. For reference:

buildConfigField("String", "API_BASE_URL", "https://x.x.x.com/v2/")

Will result in:

enter image description here

It's necessary to apply escaped quotes like:

buildConfigField("String", "API_BASE_URL", "\"https://x.x.x.com/v2/\"")

like image 78
william xyz Avatar answered Oct 20 '25 06:10

william xyz



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!