簡體   English   中英

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

[英]Gradle failed: unsupported Gradle DSL method found: 'exclude()'

我正在嘗試將我最近編碼的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

它不喜歡你如何為依賴項設置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坐標中使用壓縮格式是很好的。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM