2016-02-27 140 views
0
dependencies { 
    compile fileTree(include: ['*.jar'], dir: 'libs') 
    testCompile 'junit:junit:4.12' 

    compile('com.google.android.gms:play-services-gcm:8.4.0') { 
     exclude group: 'com.android.support', module: 'support-v4' 
     exclude group: 'com.google.android.gms' 
    } 
    compile ('com.google.android.gms:play-services-base:8.4.0') { 
     exclude group: 'com.android.support', module: 'support-v4' 
     exclude group: 'com.google.android.gms' 
    } 

    compile('com.android.support:appcompat-v7:23.2.0') { 
     exclude module: 'animated-vector-drawable' 
    } 

    compile 'com.jakewharton:butterknife:7.0.1' 
    compile 'se.emilsjolander:stickylistheaders:2.7.0' 
    compile 'com.google.code.gson:gson:2.5' 
    compile('com.koushikdutta.ion:ion:2.+') { 
     exclude module: 'gson' 
    } 
    compile 'com.github.JakeWharton:ViewPagerIndicator:[email protected]' 
    compile 'com.github.androidprogresslayout:library:[email protected]' 
    compile 'com.squareup.picasso:picasso:2.5.2' 
    compile 'com.nineoldandroids:library:2.4.0' 
    compile 'com.daimajia.slider:library:[email protected]' 
} 

但每次我得到這個錯誤:搖籃錯誤:執行失敗的任務 ':應用程序:transformClassesWithJarMergingForDebug'

Error:Execution failed for task ':app:transformClassesWithJarMergingForDebug'. 
> com.android.build.api.transform.TransformException: 
    java.util.zip.ZipException: 
     duplicate entry: android/support/v4/widget/SimpleCursorAdapter$CursorToStringConverter.class 

下面是gradlew -q dependencies App:dependencies --configuration compile結果:

enter image description here

從底部,你可以看到,我還沒有添加com.google.android.gms:play-services-measurement庫,但它顯示沒有理由?

找到了解決辦法

我的gradle檢查的控制檯,而其德興的依賴,我看到了;

Dexing \app\build\intermediates\exploded-aar\com.github.JakeWharton\ViewPagerIndicator\2.4.1\jars\libs\android-support-v4.jar took 1499 

哪個是最舊的support-v4 lib作爲jar添加的。我已經從build.gradle中刪除了ViewPagerIndicator依賴項,並手動添加它的類。

現在最奇怪的問題解決了。

+1

您是否使用了一些罐子? –

+0

@GabrieleMariotti其實我沒有使用任何罐子。但不知何故,我創建了一個新的空項目,並將類和res文件複製到新項目中。雖然gradle是德興,我看到Dexing \ app \ build \ intermediates \ exploded-aar \ com.github.JakeWharton \ ViewPagerIndicator \ 2.4.1 \ jars \ libs \ android-support-v4.jar花了1499年 這是添加支持-v4罐最老的一個。我從依賴項列表中刪除了viewpagerindicator lib並手動添加了它的類。現在奇怪的問題解決了。 –

+0

這並不奇怪。您使用兩次不同的版本添加了同一個類 –

回答

2

您正在添加兩倍的支持庫v4。

這是因爲你使用

compile 'com.github.JakeWharton:ViewPagerIndicator:[email protected]' 

你得到從jitpack這個庫。
This library將支持庫添加爲jar而不是gradle依賴項。

這意味着pom文件沒有依賴關係,並且您不能使用gradle排除jar文件,因爲該jar文件位於aar文件中(沒有pom,gradle如何知道應該排除這些文件? )。

您可以查看文件的jitpack回購:

+0

我不知道。非常感謝你的解釋,下次我會小心爲這類問題添加依賴關係。 –

相關問題