Gradle构建失败:发现不支持的Gradle DSL方法:'exclude()'。

3
我正在尝试将我最近编写的Google端点(Python)中的类包含到我的Android项目(Android Studio - 最新版本,Gradle)中。服务器端已经测试并且可以正常工作。
由于我不熟悉Gradle,因此我遵循Google Developers上的文档进行操作。根据文档中的指示,在src下更改build.gradle文件如下:
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返回以下错误:

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
1个回答

2

你的依赖项exclude语句设置可能有问题。如果你更仔细地按照指南中的示例操作,就可以解决这个问题。

例如,改成:

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: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')
}

在初始的编译坐标中使用紧凑格式是可以的。


你有没有关于如何使用 exclude(group: '', module: '') 的教程可以告诉我?请告诉我。我不太清楚如何正确使用它,总是出现错误。 - Huy Tower
1
但是Gradle指南明确表示不需要使用括号来排除依赖项。无论哪种方式都对我不起作用。 - Almo
@Almo,你最终解决了这个问题吗? - Sauron
这是我修复它的方式:http://stackoverflow.com/questions/29518216/gradle-unsupported-gradle-dsl-method-found-exclude - Almo
如果我想要排除一个文件怎么办?编译('com.fasterxml.jackson.core:jackson-databind:2.9.0'){ 排除 "META-INF/LICENSE.txt" } - Arda Kara

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接