我有这个 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>
Run Code Online (Sandbox Code Playgroud)
我的 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'
}
Run Code Online (Sandbox Code Playgroud)
有人有什么想法吗?提前致谢
这是一个非常烦人的gradle 工作方式问题。以供参考:
buildConfigField("String", "API_BASE_URL", "https://x.x.x.com/v2/")
将导致:
有必要应用转义引号,例如:
buildConfigField("String", "API_BASE_URL", "\"https://x.x.x.com/v2/\"")
buildConfigField定义如下
void buildConfigField(String type, String name, String value)
Run Code Online (Sandbox Code Playgroud)
它需要一个类型、字段名称和值。如果有前两个,就没有第三个。你可以在这里读更多关于它的内容
| 归档时间: |
|
| 查看次数: |
11361 次 |
| 最近记录: |