2016-09-21 75 views
0

我想補充OkHttp到我的項目,我同時下載OkHttpOkio庫,並將其添加到libs目錄。OkHttp添加到我的項目

比我添加編譯方法:

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

     compile 'com.squareup.okhttp3:okhttp:3.4.1' 

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

allprojects { 
    repositories { 
     jcenter() 
    } 
} 

task clean(type: Delete) { 
    delete rootProject.buildDir 
} 

我嘗試建立的應用程序,我得到這個錯誤:

Error:(27, 1) A problem occurred evaluating root project 'APP'. 
> Could not find method compile() for arguments [com.squareup.okhttp3:okhttp:3.4.1] on object of type org.gradle.api.internal.artifacts.dsl.dependencies.DefaultDependencyHandler. 

任何想法可能是什麼問題?我使用過Android Studio OM MAC OS

回答

2

刪除此行根gradle這個的:

compile 'com.squareup.okhttp3:okhttp:3.4.1' 

這對你的依賴的應用程序的模塊添加的build.gradle

1

有兩種基本的build.gradle文件在我們的項目中。

  1. 頂級gradle這個(可在項目目錄中找到)
  2. 模塊級gradle這個(目前該項目的應用程序文件夾中)

這裏的問題是,你正在整理okHttp 嘗試將頂層gradle文件中的compile 'com.squareup.okhttp3:okhttp:3.4.1'放入您的模塊級gradle中。此外,如果您正在使用gradle導入庫,則不必將其添加到lib文件夾中明確指定

Google gradle documentation