2017-06-15 101 views
0

我想使用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

    我做錯了什麼?

    +0

    將這些行添加到應用程序級gradle文件 – Onkar

    回答

    0

    so according to the documentations i add theses lines into the build.gradle of my project

    請注意該文件中的註釋:

    // NOTE: Do not place your application dependencies here; they belong 
        // in the individual module build.gradle files 
    

    我不知道什麼是「單證」你讀了叫你把這些東西在項目級build.gradle文件。請考慮提供鏈接,以便我們可以修復該材料。

    要解決此問題,請刪除對此文件所做的更改。然後,將這些依賴關係添加到模塊的build.gradle文件(例如,典型Android Studio項目中的app/build.gradle)。

    相關問題