Android Studio更新到1.0后破坏了MultiDex。

3

您好,出现了类似于重复条目的错误。

失败:构建异常出现。

  • 问题所在: 执行任务': eBooks:packageAllDebugClassesForMultiDex'时失败。

    java.util.zip.ZipException: 重复条目:android/support/annotation/AttrRes.class

  • 尝试: 使用--stacktrace选项运行以获取堆栈跟踪。 使用--info或--debug选项运行以获取更多日志输出。

构建失败。

总时间:1分钟46.13秒

apply plugin: 'com.android.application'

dependencies {
    compile fileTree(dir: 'libs', include: '*.jar')
    compile project(':ui-reader')

    compile "com.android.support:support-v4:23.1.1"
    compile "com.android.support:support-v13:20.0.0"
    compile files('libs/Flurry_3.2.1.jar')
}

android {
    compileSdkVersion 21
    buildToolsVersion "20.0.0"

    configurations {
        all*.exclude group: 'com.android.support', module: 'support-v4'
    }

    defaultConfig {
        // Enabling multidex support.
        multiDexEnabled true
    }

    lintOptions {
        abortOnError false
    }

    sourceSets {

        main {
            manifest.srcFile 'AndroidManifest.xml'
            java.srcDirs = ['src']
            resources.srcDirs = ['src']
            aidl.srcDirs = ['src']
            renderscript.srcDirs = ['src']
            res.srcDirs = ['res']
            assets.srcDirs = ['assets']
        }

        // Move the tests to tests/java, tests/res, etc...
        instrumentTest.setRoot('tests')

        // Move the build types to build-types/<type>
        // For instance, build-types/debug/java, build-types/debug/AndroidManifest.xml, ...
        // This moves them out of them default location under src/<type>/... which would
        // conflict with src/ being used by the main source set.
        // Adding new build types or product flavors should be accompanied
        // by a similar customization.
        debug.setRoot('build-types/debug')
        release.setRoot('build-types/release')
    }
}

请问如何在jar文件中查找重复的类文件,并获得以下输出结果:

com.squareup.okhttp:okhttp:1.6.0 | | | +--- com.intellij:annotations:+ -> 12.0


1
你能给我们看一下你的构建文件吗? - Scott Barta
是的,绝对可以让我在这里发布它们。奇怪的是,当我的min sdk为21时,问题似乎不会出现。一旦我选择14(devDebug口味),它就无法工作。 - Stephane Maarek
1个回答

6
我能够通过包含aviary-sdk库在一个测试项目中重现这个问题。我不需要multi-dex,并且我也没有调查不同的SDK版本,这对我来说有点神秘。
如果您没有使用multi-dex,那么您会得到经典的“multiple dex files define…”错误,这意味着您在构建中多次包含了相同的符号,这是不允许的。
这些问题可能需要一些侦探工作;这就是gradle dependencies任务非常有用的地方。如果您进入模块的目录(而不是顶级目录)并运行此任务:
../gradlew dependencies

你将获得:

compile - Classpath for compiling the main sources.
+--- com.aviary.android.feather.sdk:aviary-sdk:3.4.3.351
|    \--- com.aviary.android.feather.sdk:sdk-library:3.5.1
|         +--- it.sephiroth.android.library.hlistviewanimations:hlistviewanimations-library:1.0.1
|         |    +--- it.sephiroth.android.library.horizontallistview:hlistview:1.2.2
|         |    |    \--- com.android.support:support-v4:19.1.+ -> 21.0.3
|         |    |         \--- com.android.support:support-annotations:21.0.3
|         |    \--- com.nineoldandroids:library:2.4.0
|         +--- com.nineoldandroids:library:2.4.0
|         +--- it.sephiroth.android.library.disklruimagecache:DiskLruImageCache:1.0.2
|         |    +--- org.apache.commons:commons-io:1.3.2
|         |    \--- com.jakewharton:disklrucache:2.0.2
|         +--- com.aviary.android.feather.sdk:cds-library:3.2.4
|         |    +--- com.aviary.android.feather.sdk:common-library:3.1.2 -> 3.1.8.1
|         |    |    +--- org.apache.commons:commons-lang3:3.3.2
|         |    |    +--- com.squareup.okhttp:okhttp-urlconnection:1.6.0
|         |    |    |    \--- com.squareup.okhttp:okhttp:1.6.0
|         |    |    +--- com.squareup.okhttp:okhttp:1.6.0
|         |    |    +--- com.intellij:annotations:+ -> 12.0
|         |    |    \--- commons-io:commons-io:2.4
|         |    \--- com.android.support:support-v4:19.+ -> 21.0.3 (*)
|         +--- it.sephiroth.android.library.disklrumulticache:disklrumulticache:1.0.2
|         |    +--- org.apache.commons:commons-io:1.3.2
|         |    \--- com.jakewharton:disklrucache:2.0.2
|         +--- it.sephiroth.android.library.picasso:picasso:2.3.3.2
|         |    +--- com.squareup.okhttp:okhttp-urlconnection:1.6.0 (*)
|         |    +--- com.squareup.okhttp:okhttp:1.6.0
|         |    \--- com.intellij:annotations:12.0
|         +--- com.android.support:support-v4:19.+ -> 21.0.3 (*)
|         +--- it.sephiroth.android.exif:android-exif-extended:1.0.2
|         |    +--- org.apache.commons:commons-lang3:3.3.2
|         |    \--- org.apache.commons:commons-io:1.3.2
|         +--- it.sephiroth.android.library.imagezoom:imagezoom:1.0.5
|         |    \--- it.sephiroth.android.library.easing:android-easing:1.0.3
|         +--- com.aviary.android.feather.sdk:receipt-library:2.0.2
|         |    +--- com.aviary.android.feather.sdk:common-library:3.1.2 -> 3.1.8.1 (*)
|         |    +--- it.sephiroth.android.library.ab:ab-test:2.0.3
|         |    \--- com.android.support:support-v4:19.+ -> 21.0.3 (*)
|         +--- com.aviary.android.feather.sdk:common-library:3.1.2 -> 3.1.8.1 (*)
|         +--- it.sephiroth.android.library.horizontallistview:hlistview:1.2.2 (*)
|         +--- it.sephiroth.android.library.fork.listviewanimations:listviewanimations-library-core:2.6.1
|         |    \--- com.nineoldandroids:library:2.4.0
|         +--- com.aviary.android.feather.sdk:tracking-library:3.0.1
|         |    \--- com.aviary.android.feather.sdk:common-library:3.1.8.1 (*)
|         \--- com.aviary.android.feather.sdk:headless-library:3.4.002000000
|              \--- com.aviary.android.feather.sdk:common-library:3.1.2 -> 3.1.8.1 (*)

如果你仔细查看,你会发现它们都包含了以下两个依赖项:

commons-io:commons-io:2.4

org.apache.commons:commons-io:1.3.2

我没有确认,但我认为它们是相同的类的不同打包方式,其中包括 org/apache/commons/io/CopyUtils.class
如果你想排除 commons-io 的话,请使用以下方法:
compile ('com.aviary.android.feather.sdk:aviary-sdk:3.4.3.351') {
    exclude group: 'commons-io'
}

它将被构建。我还没有尝试运行它,所以我不知道在运行时是否会出现缺少符号的情况;如果有缺失,您可以尝试更精细地排除依赖项,或者重新打包依赖项以修复错误,或联系其作者。


非常感谢你,Scott!奇怪的是,这个库在之前的所有版本上都可以编译通过。我猜它不喜欢切换到Android 1.0(也许是正在执行的某个规则?)我会联系Adobe(他们拥有Aviary),并确保将它们指向这里。 - Stephane Maarek

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接