简体   繁体   English

Gradle失败:找不到支持的Gradle DSL方法:'exclude()'

[英]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. 我正在尝试将我最近编码的Google端点(Python)中的类包含到我的Android项目(Android Studio - 最新版,Gradle)中。 The server side is all tested and working. 服务器端都经过测试和工作。

I'm not used to Gradle, therefore I'm following the documentation at Google Developers . 我不习惯Gradle,因此我正在关注Google Developers的文档。 After changing the build.gradle file under src (as instructed by the doc) to: src下的build.gradle文件(按文档指示)更改为:

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 returns the following error: 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

It doesn't like how you've set up the exclude statements for your dependencies. 它不喜欢你如何为依赖项设置exclude语句。 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. 在初始compile坐标中使用压缩格式是很好的。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 找不到Gradle DSL方法:exclude() - Gradle DSL method not found: exclude() 找不到:找不到 Gradle DSL 方法:'complite()' - Failed To Found: Gradle DSL method not found: 'complite()' android错误:Gradle同步失败:未找到Gradle DSL方法:'classpath()' - android error : Gradle sync failed: Gradle DSL method not found: 'classpath()' Gradle 错误:找不到 Gradle DSL 方法:'executeWithoutThrowingTaskFailure()' - Gradle Error:Gradle DSL method not found: 'executeWithoutThrowingTaskFailure()' 找不到Gradle DSL方法:storeFile() - Gradle DSL method not found: storeFile() 找不到Gradle DSL方法:“ compileOptions()” - Gradle DSL method not found:'compileOptions()' 找不到 Gradle DSL 方法:'ooapply()' - Gradle DSL method not found: 'ooapply()' 找不到Gradle DSL方法:“ appengine()” - Gradle DSL method not found: 'appengine()' 找不到Gradle DSL方法:testCompile() - Gradle DSL Method not found: testCompile() 升级后,Android Studio“错误:生成脚本错误,找到了不受支持的Gradle DSL方法:>'getProguard()'!” - Android Studio “Error:Build script error, unsupported Gradle DSL method found: > 'getProguard()'!” after upgrading
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM