4
votes

I followed instruction from http://developer.android.com/tools/support-library/setup.html to add the support library to my android project, but got an build error like this

Gradle: A problem occurred evaluating project ':projectname'.

No signature of method: org.gradle.api.internal.artifacts.dsl.dependencies.DefaultDependencyHandler.compile() is applicable for argument types: (java.lang.String) values: [com.android.support:appcompat-v7:18.0.+] Possible solutions: module(java.lang.Object)

Does anyone know the reason for that? Is it a syntax error in gradle? Below is a piece of code in my build.gradle.

buildscript {
    repositories {
        mavenCentral()
    }
    dependencies {
        classpath 'com.android.tools.build:gradle:0.6.+'
        compile 'com.android.support:appcompat-v7:18.0.+'
    }
}
1
I think you should add it in the main "dependencies" section, the one you find at the bottom of your build.gradle file and not under "buildscript". - fasteque
Right, 'appcompat-v7:18.0.+' should be placed outside of your buildscript block. - IgorGanapolsky

1 Answers

11
votes

This should be like this:

buildscript {
    repositories {
        mavenCentral()
    }

    dependencies {
        classpath 'com.android.tools.build:gradle:0.6.+'
        // this is for Gradle build system so it finds
        // android plugin used below
    }
}

apply plugin: 'android'

repositories {
    mavenCentral()
}

dependencies {
    compile 'com.android.support:appcompat-v7:18.0.+'
    // this is for your application
}

Don't forget to install Android Support Repository in Android SDK Manager.