我有这个gradle错误
错误:(21,0)未找到Gradle DSL方法:'buildConfigField()' 可能的原因:
<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>
我的build.gradle代码在这里
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'
}
谁有任何想法?
提前谢谢
答案 0 :(得分:2)
buildConfigField
定义如下
void buildConfigField(String type, String name, String value)
它需要一个类型,字段的名称和值。如果有前两个,而不是第三个。您可以阅读更多相关信息here
答案 1 :(得分:0)
在build.gradle代码上添加'OPEN_WEATHER_MAP_API_KEY'值
buildTypes.each {
it.buildConfigField 'String', 'OPEN_WEATHER_MAP_API_KEY', 'xxxx'
}
答案 2 :(得分:0)
只需在list
块中添加它:
seq
答案 3 :(得分:-1)
复制粘贴MyOpenWeatherAPIKey
时,您可能错过了parenthisis最初它看起来像
buildTypes.each {
it.buildConfigField 'String', 'OPEN_WEATHER_MAP_API_KEY', MyOpenWeatherAPIKey
}
从https://home.openweathermap.org/api_keys复制MyOpenWeatherAPIKey后,它应该
buildTypes.each {
it.buildConfigField 'String', 'OPEN_WEATHER_MAP_API_KEY', 'xxxxxxxxxxxxxxxxxxxxxxxxxxxx'
}