2015-04-21 83 views
3

當我想將新庫添加到build.gradle文件時,它會生成一個錯誤。 這是我的build.gradle文件:在Android Studio中添加依賴項時出錯

// Top-level build file where you can add configuration options common to all sub-projects/modules. 

buildscript { 
    repositories { 
     jcenter() 
    } 
    dependencies { 
     classpath 'com.android.tools.build:gradle:1.0.0' 

     compile 'com.mcxiaoke.volley:library:1.0.+' 
     // NOTE: Do not place your application dependencies here; they belong 
     // in the individual module build.gradle files 
    } 
} 

allprojects { 
    repositories { 
     jcenter() 
    } 
} 

,這是錯誤

C:\Users\Fakher\Documents\Play_Store_WS\VolleyJson\build.gradle Error:Error:line (10)Gradle DSL method not found: 'compile()' Possible causes:

  • The project 'VolleyJson' may be using a version of Gradle that does not contain the method. Gradle settings
  • The build file may be missing a Gradle plugin. Apply Gradle plugin
  • 回答

    1

    它不工作,因爲你把依賴放錯了地方,那個build.gradle中沒有插件來處理你的依賴,你應該在你的app模塊中的build.gradle中添加你的依賴。

    更好地解釋:

    有一個叫應用您的項目文件夾裏面,這就是你的應用程序模塊,它裏面應該有一個的build.gradle,在那裏的build.gradle應該是像這樣:

    apply plugin: 'com.android.application' 
    
    android { 
        compileSdkVersion 21 
        buildToolsVersion "21.1.2" 
        defaultConfig { 
        // bla bla bla 
        } 
    } 
    dependencies { 
    compile fileTree(dir: 'libs', include: ['*.jar']) 
    //put your dependencies here 
    } 
    

    希望我能幫助你....

    +0

    很好的解釋。謝謝 – Fakher

    2

    您需要使用您的模塊,而不是你的項目的build.gradle。

    1

    看看這個:

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

    圍棋在您的「應用程序」模塊的build.gradle然後地方:

    compile 'com.mcxiaoke.volley:library:1.0.+' 
    
    1

    必須在buil.gradle下添加應用程序/沒有你的依賴在build.gradle下你的項目

    相關問題