Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

buildTypes.each String for API's in Android Gradle configuration

Tags:

android

I'm working on Google's Udacity course for new Android Devs, and I've come into some trouble with the Gradle build and defining a constant in it. I've tried surrounding the field with multiple variations of ", ', and \'s that I say recommended online, but nothing seems to work. I was wondering how to format the line inside buildTypes.each, seen here?

buildTypes.each {
    it.buildConfigField "String", "OPEN_WEATHER_MAP_API_KEY", **APICodeHere**
}

Here's the entirety of the code for the app's gradle build.

android {
compileSdkVersion 21
buildToolsVersion "21.1.2"

defaultConfig {
    applicationId "com.example.android.sunshine.app"
    minSdkVersion 10
    targetSdkVersion 21
    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", **APICodeHere**
}

}

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

Thanks!!!

like image 855
PianoFingers Avatar asked May 20 '16 02:05

PianoFingers


1 Answers

I am also taking this course and I had the same problem. The formatting that eventually worked for me is this:

it.buildConfigField 'String', 'OPEN_WEATHER_MAP_API_KEY', "\"6df0...9ac\""

Paste your hexadecimal Open Weather API Key instead of the 6df0...9ac above. Hope that helps!

like image 112
noobist Avatar answered Oct 11 '22 08:10

noobist