【问题标题】:Gradle failed: unsupported Gradle DSL method found: 'exclude()'Gradle 失败:找到不受支持的 Gradle DSL 方法:'exclude()'
【发布时间】:2014-03-24 13:53:43
【问题描述】:

我正在尝试将我最近编写的来自 Google Endpoints (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

【问题讨论】:

    标签: java android google-app-engine google-cloud-endpoints


    【解决方案1】:

    它不喜欢您为依赖项设置 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')
    }
    

    在初始compile坐标中使用压缩格式就可以了。

    【讨论】:

    • 你有什么指南可以告诉我如何使用exclude(group: '', module: '') 吗?请告诉我。我不知道如何确切地使用它。我总是得到错误。
    • 但是 gradle 指南特别没有排除的括号。这两种方法都不适合我。
    • @Almo,你有没有找到解决办法?
    • 这是我修复它的方法:stackoverflow.com/questions/29518216/…
    • 如果我想排除一个文件怎么办?编译 ('com.fasterxml.jackson.core:jackson-databind:2.9.0'){ 排除 "META-INF/LICENSE.txt" }
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-04-16
    • 2016-02-28
    • 2014-09-03
    • 1970-01-01
    • 2019-10-21
    相关资源
    最近更新 更多