Gradle DSL method not found: 'compile()'

As the note of your project's build.gradle file suggests:

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

Remove the 2 compile statements in that gradle file:

compile 'com.android.support:appcompat-v7:20.+'
compile 'com.google.android.gms:play-services:6.5.+'

And then make your other (module's) build.gradle dependencies look like this:

dependencies {
    compile fileTree(dir: 'libs', include: ['*.jar'])
    compile 'com.android.support:appcompat-v7:21.0.3'
    compile 'com.google.android.gms:play-services:6.5.+'
}

Its really silly problem and I got solution:

as compile statements goes in one line

compile "com.squareup.okhttp3:okhttp:$okHttpVersion"    compile "com.squareup.okhttp3:okhttp-urlconnection:$okHttpVersion"    compile "com.squareup.okhttp3:logging-interceptor:$okHttpVersion"    compile "com.google.code.gson:gson:$gsonVersion"

I just changed next by next line and solved my problem:

compile "com.squareup.okhttp3:okhttp:$okHttpVersion"
compile "com.squareup.okhttp3:okhttp-urlconnection:$okHttpVersion"
compile "com.squareup.okhttp3:logging-interceptor:$okHttpVersion"
compile "com.google.code.gson:gson:$gsonVersion"

Hope it will helps you. Thank you.


I am using Android studio based on IntelliJ Idea and I have changed Settings on when and how to wrap code. Also I had 'reformat automatically' options which lead to formatting Gradle files randomly. So it lead to something like this:

    compile 'de.greenrobot:eventbus:2.4.0' compile 'com.jakewharton:butterknife:7.0.1'

Gradle then fails to find compile() for the second compile. As you only allowed to write one dependency per line.


Check your build.gradle files, sometimes when you add a module to your current module using the project settings, the build.gradle of current module is corrupted, and indents are broken, just check current build.gradle and check if all the compile statements are issued in a new line!

Tags:

Android