Android Studio update to 1.0 corrupts MultiDex

亡梦爱人 提交于 2019-12-04 15:17:28

问题


Hi Have similar error like duplicate entry.

FAILURE: Build failed with an exception.

  • What went wrong: Execution failed for task ':eBooks:packageAllDebugClassesForMultiDex'.

    java.util.zip.ZipException: duplicate entry: android/support/annotation/AttrRes.class

  • Try: Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output.

BUILD FAILED

Total time: 1 mins 46.13 secs

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

Can anyone tell me how to find where the duplicate class file is available in jar file and how to get output like the following

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


回答1:


I was able to reproduce this in a test project just by including the aviary-sdk library. I didn't need multi-dex, and I didn't investigate different SDK versions, which seems a little mysterious to me.

If you don't have multi-dex, you get the classic "multiple dex files define..." error which means you've included the same symbol more than once in your build, which you're not allowed to do.

These problems can take a little bit of sleuthing; that's where the gradle dependencies task can be very handy. If you go into your module's directory (not the top-level directory) and run this task:

../gradlew dependencies

you get:

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 (*)

If you look carefully, you'll see both:

commons-io:commons-io:2.4

and

org.apache.commons:commons-io:1.3.2

in there, which I didn't confirm, but I assume are different packagings of the same classes which include org/apache/commons/io/CopyUtils.class.

If you exclude commons-io via:

compile ('com.aviary.android.feather.sdk:aviary-sdk:3.4.3.351') {
    exclude group: 'commons-io'
}

it will build. I haven't tried to run it, so I don't know if there will be missing symbols at runtime; if there are, you could try to be more surgical about what you exclude from the dependency, or perhaps you could repackage the dependency to fix the errors, or contact its author.



来源:https://stackoverflow.com/questions/27436641/android-studio-update-to-1-0-corrupts-multidex

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!