Reputation: 1388
I created a file gradle.properties
in .gradle
folder, and added a variable:
MyOpenWeatherMapApiKey=”b86b2******a2cc***a5fa***ae14c30”
(Some letters starred for security)
And here is my build.gradle
file:
apply plugin: 'com.android.application'
android {
compileSdkVersion 23
buildToolsVersion "23.0.3"
defaultConfig {
applicationId "com.example.android.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', MyOpenWeatherMapApiKey
}
}
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
compile 'com.android.support:appcompat-v7:23.3.0'
}
It says
Error:(21, 0) Could not find property 'MyOpenWeatherMapApiKey' on
com.android.build.gradle.AppExtension_Decorated@12b151b.`
Why isn't the variable from gradle.properties
recognized?
Upvotes: 1
Views: 2259
Reputation: 795
It seem the file gradle.properties
should be already there. If you are using Android Studio
it should be at the bottom after gradle
folder and before External libraries
. It shouldn't be in .gradle
.
Upvotes: 1