2014-03-24 39 views
3

我試圖將我最近編寫的來自Google Endpoints(Python)的類包含到我的Android項目(Android Studio - latest,Gradle)中。服務器端全部經過測試和工作。Gradle失敗:發現不支持的Gradle DSL方法:'exclude()'

我不習慣Gradle,因此我遵循Google Developers的文檔。改變下的build.gradle文件SRC(如指示由DOC)後:

的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 

回答

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

它的優良使用壓縮格式的初始compile座標。

+0

是否有任何指導告訴我如何使用'exclude(group:'',module:'')'?請告訴我。我不知道如何使用它。我總是得到錯誤。 –

+1

http://www.gradle.org/docs/current/userguide/dependency_management.html –

+1

但Gradle指南特別沒有排除的對象。這兩種方式都不適合我。 – Almo

相關問題