在 com.android.build.gradle.AppExtension_Decorated 上找不到属性“xxxx" [英] Could not find property 'xxxx' on com.android.build.gradle.AppExtension_Decorated
问题描述
将这些行添加到我的 gradle 文件后,出现此错误:
I got this error after I added these lines to my gradle file:
buildTypes.each {
it.buildConfigField 'String', 'OPEN_WEATHER_MAP_API_KEY', MyOpenWeatherMapApiKey
}
然后日志显示:
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?
推荐答案
由于您使用的是 String
,因此您必须使用以下语法:
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\""
第一种情况会在您的 BuildConfig
文件中生成一个常量.
第二种情况生成可以使用 @string/OPEN_WEATHER_MAP_API_KEY
注释访问的字符串资源值.
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.
这篇关于在 com.android.build.gradle.AppExtension_Decorated 上找不到属性“xxxx"的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!