Jal Panchal
Jal Panchal

Reputation: 17

Android Studio Gradle DSL method not found: 'compile()'

I am getting the following error:

Error:(4, 0) Gradle DSL method not found: 'compile()'
Possible causes:The project 'Jp' may be using a version of Gradle that does not contain the method.
Open Gradle wrapper file.The build file may be missing a Gradle plugin.

I tried looking to other similar questions, but nothing worked. My build.gradle(Project:JP) file is below:
Error:(4, 0) Gradle DSL method not found: 'compile()'

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

        // 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
}

build.gradle(Module:app)

apply plugin: 'com.android.application'

android {
    compileSdkVersion 26
    buildToolsVersion "26.0.0"

    defaultConfig {
        applicationId "com.example.jal.jp"
        minSdkVersion 19
        targetSdkVersion 26
        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 project(":sdk-audio-1.60.1")

    testCompile 'junit:junit:4.12'
   compile 'com.android.support:appcompat-v7:26.0.0-alpha1'
    compile 'com.android.support:design:26.0.0-alpha1'
}

build.gradle(sdk-audio-1.60.1)

android {
    compileSdkVersion 26
    buildToolsVersion "26.0.0"

    defaultConfig {
        applicationId "com.example.jal.jp"
        minSdkVersion 19
        targetSdkVersion 26
        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 project(":sdk-audio-1.60.1")

    testCompile 'junit:junit:4.12'
   compile 'com.android.support:appcompat-v7:26.0.0-alpha1'
    compile 'com.android.support:design:26.0.0-alpha1'
}

settings.gradle:

include ':app', ':sdk-audio-1.60.1'

can anyone help me to fix this?

Thanks

Upvotes: 1

Views: 2222

Answers (1)

ישו אוהב אותך
ישו אוהב אותך

Reputation: 29783

Your build gradle tools seem too old, change the following line in the root build.gradle:

classpath 'com.android.tools.build:gradle:1.5.0'

to

classpath 'com.android.tools.build:gradle:2.3.3'

And don't forget to add google maven to your build.gradle too:

maven { url "https://maven.google.com" }

This is because all support library are moved to maven as in the release note at https://developer.android.com/topic/libraries/support-library/revisions.html:

Important: The support libraries are now available through Google's Maven repository. You do not need to download the support repository from the SDK Manager. For more information, see Support Library Setup.

So then your root build.gradle will be something like this:

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

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

allprojects {
    repositories {
        jcenter()
        maven { url "https://maven.google.com" }
    }
}

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

Upvotes: 1

Related Questions