【问题标题】:Gradle Error:Execution failed for task ':app:transformClassesWithJarMergingForDebug'Gradle 错误:任务“:app:transformClassesWithJarMergingForDebug”执行失败
【发布时间】:2016-02-27 08:10:00
【问题描述】:
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:2.4.1@aar'
    compile 'com.github.androidprogresslayout:library:2.0.2@aar'
    compile 'com.squareup.picasso:picasso:2.5.2'
    compile 'com.nineoldandroids:library:2.4.0'
    compile 'com.daimajia.slider:library:1.1.5@aar'
}  

但是每次我得到这个错误:

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 结果:

从底部你可以看到,我没有添加com.google.android.gms:play-services-measurement lib,却无故显示?

找到解决方案

我检查了 gradle 的控制台,同时它对依赖项进行索引,我看到了;

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

将最旧的 support-v4 库添加为 jar。我已经从 build.gradle 中删除了 ViewPagerIndicator 依赖项并手动添加它的类。

现在最奇怪的问题解决了。

【问题讨论】:

  • 你在用一些罐子吗?
  • @GabrieleMariotti 实际上我没有使用任何罐子。但不知何故,我创建了新的空项目并将类和 res 文件复制到新项目中。当 gradle 进行 dexing 时,我看到 Dexing \app\build\intermediates\exploded-aar\com.github.JakeWharton\ViewPagerIndicator\2.4.1\jars\libs\android-support-v4.jar 花了 1499 来添加 support-v4罐子里最古老的。我从依赖项列表中删除了 viewpagerindicator 库并手动添加了它的类。现在奇怪的问题解决了。
  • 这并不奇怪。您两次添加了具有不同版本的同一类
  • 但我使用了 gradle 中的 exclude 标签,但实际上并没有用。
  • 检查下面的答案。它解释了为什么在这种情况下排除标记不起作用。

标签: java android gradle support-v4


【解决方案1】:

您添加了两倍的支持库 v4。

这是因为你正在使用

compile 'com.github.JakeWharton:ViewPagerIndicator:2.4.1@aar'

您从 jitpack 中获取此库。
This library 将支持库添加为 jar,而不是作为 gradle 依赖项。

这意味着pom文件没有依赖关系,你不能用gradle排除jar文件,因为jar在aar文件里面(没有pom,gradle怎么知道这些文件应该被排除?) .

你可以查看jitpack repo中的文件:

【讨论】:

  • 我不知道。非常感谢您的解释,下次我在为此类问题添加依赖项时会小心。
猜你喜欢
  • 1970-01-01
  • 2016-01-17
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2018-06-18
相关资源
最近更新 更多