简体   繁体   中英

Gradle failed: unsupported Gradle DSL method found: 'exclude()'

I'm trying to include into my Android project (Android Studio - latest, Gradle) the classes from the Google Endpoints (Python) that I recently coded. The server side is all tested and working.

I'm not used to Gradle, therefore I'm following the documentation at Google Developers . After changing the build.gradle file under src (as instructed by the doc) to:

build.gradle:

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

apply plugin: 'android'

repositories {
    maven {
        url 'http://google-api-client-libraries.appspot.com/mavenrepo'
    }
    mavenCentral()
    mavenLocal()
}

android {
    compileSdkVersion 19
    buildToolsVersion "19.0.2"

    defaultConfig {
        minSdkVersion 17
        targetSdkVersion 19
        versionCode 1
        versionName "1.0"
    }
    buildTypes {
        release {
            runProguard false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.txt'
        }
    }
}

dependencies {
    compile 'com.android.support:support-v4:+'
    compile 'com.google.android.gms:play-services:4.+'

    compile('com.google.api-client:google-api-client:1.17.0-rc') {
        // Exclude artifacts that the Android SDK/Runtime provides.
        exclude('xpp3:xpp3')
        exclude('org.apache.httpcomponents:httpclient')
        exclude('junit:junit')
        exclude('com.google.android:android')
    }

    compile('com.google.api-client:google-api-client-android:1.17.0-rc') {
        // Exclude play services, since we're not using this yet.
        exclude('com.google.android.google-play-services:google-play-services')
    }

    compile('com.google.http-client:google-http-client-android:1.17.0-rc') {
        exclude('com.google.android:android')
    }

    // This is used by the Google HTTP client library.
    compile('com.google.guava:guava:14.0.+')
}

Android Studio returns the following error:

Gradle 'Project' project refresh failed:
Build script error, unsupported Gradle DSL method found: 'exclude()'!
Possible causes could be:  
- you are using Gradle version where the method is absent 
- you didn't apply Gradle plugin which provides the method
- or there is a mistake in a build script
Build file '/Project/Android/build.gradle' line: 44
: Gradle settings

It doesn't like how you've set up the exclude statements for your dependencies. If you follow the example in the guide more closely, it should work.

For example, instead of:

compile('com.google.api-client:google-api-client:1.17.0-rc') {
    // Exclude artifacts that the Android SDK/Runtime provides.
    exclude('xpp3:xpp3')
    exclude('org.apache.httpcomponents:httpclient')
    exclude('junit:junit')
    exclude('com.google.android:android')
}

use this:

compile('com.google.api-client:google-api-client:1.17.0-rc') {
    // Exclude artifacts that the Android SDK/Runtime provides.
    exclude(group: 'xpp3', module: 'xpp3')
    exclude(group: 'org.apache.httpcomponents', module: 'httpclient')
    exclude(group: 'junit', module: 'junit')
    exclude(group: 'com.google.android', module: 'android')
}

It's fine to use the condensed format in the initial compile coordinates.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM