DinhNgocHien DinhNgocHien - 3 months ago 31x
Android Question

Could not find property 'xxxx' on com.android.build.gradle.AppExtension_Decorated

I got this error after I added these lines to my gradle file:

buildTypes.each {
it.buildConfigField 'String', 'OPEN_WEATHER_MAP_API_KEY', MyOpenWeatherMapApiKey

then the log show:

Could not find property 'MyOpenWeatherMapApiKey' on com.android.build.gradle.AppExtension_Decorated@c3b784

The solutions on google that I searched cannot solve my problem. Please show me where I was wrong?


Since you are using a String you have to use this syntax:

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

The last parameter has to be a String

Otherwise you can use something like this:

resValue "string", "OPEN_WEATHER_MAP_API_KEY", "\"XXXXX-XXXXX-XXX\""

The first case generates a constants iin your BuildConfig file.
The second case generates a string resource value that can be accessed using the @string/OPEN_WEATHER_MAP_API_KEY annotation.