2017-06-15 78 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)。

    相关问题