我想使用Gson和Retrofit與API進行交互。根據該文檔,我加論文線到我的項目的build.gradle:未找到gradle dsl方法'compile()'錯誤:(10,0)
// Top-level build file where you can add configuration options common to all sub-projects/modules.
buildscript {
repositories {
jcenter()
mavenCentral() //this line
}
dependencies {
classpath 'com.android.tools.build:gradle:2.3.3'
compile 'com.google.code.gson:gson:2.7' //this line
compile 'com.squareup.retrofit:retrofit:1.9.0' //this line
// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
}
}
allprojects {
repositories {
jcenter()
mavenCentral() //and this line
}
}
task clean(type: Delete) {
delete rootProject.buildDir
}
但我有這些錯誤:
Error:(10, 0) Gradle DSL method not found: 'compile()' Possible causes:
The project 'TempoEDF' may be using a version of the Android Gradle plug-in that does not contain the method (e.g. 'testCompile' was added in 1.1.0). Upgrade plugin to version 2.3.3 and sync project The project 'TempoEDF' may be using a version of Gradle that does not contain the method. Open Gradle wrapper file The build file may be missing a Gradle plugin. Apply Gradle plugin
所以我用的搖籃插件像我的IDE希望:
dependencies {
classpath 'com.android.tools.build:gradle:2.3.3'
apply plugin: 'gradle'
compile 'com.google.code.gson:gson:2.7'
compile 'com.squareup.retrofit:retrofit:1.9.0'
// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
}
但我有此錯誤:
Error:(10, 0) Plugin with id 'gradle' not found. Open File
我做錯了什麼?
將這些行添加到應用程序級gradle文件 – Onkar