java - Gradle 失败 : unsupported Gradle DSL method found: 'exclude()'

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

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

最佳答案

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

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

关于java - Gradle 失败 : unsupported Gradle DSL method found: 'exclude()' ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22611406/

相关文章:

android - 应用程序 onCreate() 从未调用过

android - 如何通过 XML 将 textview 的背景颜色设置为全息绿光?

python - Google App Engine remote_api 使用 remote_api_shell.py 返回 404

python - 当应用引擎上的任务队列为空时运行函数

Java逻辑困惑

java.security.InvalidAlgorithmParameterException : the trustAnchors parameter must be non-empty on Linux, 或为什么默认信任库为空

android - Recyclerview 不保留我的滚动位置

python - 使用 Beautiful Soup 从网站抓取数据并在 jinja2 中显示

java - 使用带注释的复合主键进行元素映射

java.lang.ClassCastException : [Ljava. lang.Object;与 com.spring.model.Instruction 不兼容