Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Gradle DSL method not found: 'compile()'

Tags:

android

I had this gradle error.

Error:(9, 0) Gradle DSL method not found: 'compile()'

I have tried refering to similar questions but it did not work.

Android gradle build Error:(9, 0) Gradle DSL method not found: 'compile()'.

Getting Error "Gradle DSL method not found: 'compile()'" when Syncing Build.Gradle

Unsupported Gradle DSL method found: 'compile()'!

My build.gradle code is here

buildscript {
    repositories {
        jcenter()
    }
    dependencies {
        classpath 'com.android.tools.build:gradle:1.0.0'
        compile 'com.android.support:appcompat-v7:20.+'
        compile 'com.google.android.gms:play-services:6.5.+'
        // NOTE: Do not place your application dependencies here; they belong
        // in the individual module build.gradle files
    }
}

allprojects {
    repositories {
        jcenter()
    }
}

build.gradle(Module.app)

apply plugin: 'com.android.application'

android {
    compileSdkVersion 21
    buildToolsVersion "21.1.1"

    defaultConfig {
        applicationId "com.example.simplemaker.pushtest"
        minSdkVersion 9
        targetSdkVersion 21
        versionCode 1
        versionName "1.0"
    }
    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
    }
}

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

What's wrong with my code?

like image 903
T.Akashi Avatar asked Dec 23 '14 09:12

T.Akashi


2 Answers

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.+'
}
like image 119
Simas Avatar answered Nov 12 '22 19:11

Simas


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.

like image 36
Bato-Bair Tsyrenov Avatar answered Nov 12 '22 21:11

Bato-Bair Tsyrenov