vtloc
vtloc

Reputation: 181

Gradle DSL method not found: "classpath()"

I am working on an Android project, which used Gradle as mentioned below.

buildscript {
    repositories {
        mavenCentral()
    }
    dependencies {
        classpath 'com.android.tools.build:gradle:0.12.+'
    }
}

allprojects {
    repositories {
        mavenCentral()
    }
}

dependencies {
    classpath 'com.android.tools.build:gradle:0.12.+'
    compile fileTree(dir: 'libs', include: '*.jar')
    compile project(':workspace:darkmoon:darul-android:vitamio:vitamio')
    compile project(':Dev:adt-bundle-mac-x86_64:sdk:extras:google:google_play_services:libproject:google-play-services_lib')
}

android {
    compileSdkVersion 19
    buildToolsVersion "20.0.0"

    sourceSets {
        main {
            manifest.srcFile 'AndroidManifest.xml'
            java.srcDirs = ['src']
            resources.srcDirs = ['src']
            aidl.srcDirs = ['src']
            renderscript.srcDirs = ['src']
            res.srcDirs = ['res']
            assets.srcDirs = ['assets']
        }

        // Move the tests to tests/java, tests/res, etc...
        instrumentTest.setRoot('tests')

        // Move the build types to build-types/<type>
        // For instance, build-types/debug/java, build-types/debug/AndroidManifest.xml, ...
        // This moves them out of them default location under src/<type>/... which would
        // conflict with src/ being used by the main source set.
        // Adding new build types or product flavors should be accompanied
        // by a similar customization.
        debug.setRoot('build-types/debug')
        release.setRoot('build-types/release')
    }
}

But when I build it, keep receiving this error: "Gradle DSL method not found", and it pointed to the following line:

dependencies {
    classpath 'com.android.tools.build:gradle:0.12.+'
    compile fileTree(dir: 'libs', include: '*.jar')
    compile project(':workspace:epsilonmobile:darul-android:vitamio:vitamio')
    compile project(':Dev:adt-bundle-mac-x86_64:sdk:extras:google:google_play_services:libproject:google-play-services_lib')
}

Apologize if this question is a bit noob, I'm new to both Gradle and Android Studio

Upvotes: 13

Views: 12114

Answers (2)

ben75
ben75

Reputation: 28726

In a gradle script, the buildscript is a special section where you can declare dependencies of the build script itself (i.e. binaries required by the build process).

The gradle build process is nothing more than a java process and so it supports normal classpath dependencies.

com.android.tools.build:gradle:0.12.+ identify a binary required by the build process (it contains code able to understand/execute the android section of the build script).

The android apk that will be build by this script don't needs the binary com.android.tools.build:gradle:0.12.+ to run on your android device (i.e. the apk is of course already build when it run on the device) : there is no reason to declare it again in the top level dependencies (those are the dependencies required by your app)

Upvotes: 5

Peter Niederwieser
Peter Niederwieser

Reputation: 123950

A classpath configuration is only available for buildscript dependencies. You need to get rid of the line classpath 'com.android.tools.build:gradle:0.12.+' in the top-level dependencies block. (Gradle plugins need to be declared under buildscript { dependencies { ... } }.)

Upvotes: 15

Related Questions