Reputation: 7900
I am trying to add OkHttp
to my project, i download both OkHttp
and Okio
library and add it to the libs
directory.
than i add the compile methods:
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
}
I try to Build the App and i get this error:
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.
Any idea what can be the problem? i am using Android Studio om mac OS
Upvotes: 1
Views: 6190
Reputation: 852
There are basically two build.gradle files in our project.
Here the problem is you are compiling the okHttp
compile 'com.squareup.okhttp3:okhttp:3.4.1'
in the Top level gradle file try to place it in your Module level gradle. Also if you are importing a library using gradle you don't have to add it in the lib folder explicitly
Upvotes: 1
Reputation: 297
Delete this line of your root gradle :
compile 'com.squareup.okhttp3:okhttp:3.4.1'
And Add this to your dependencies's app's module build.gradle
Upvotes: 3