复制Zip条目MultiDex.class

时间:2017-11-02 13:22:17

标签: android proguard multidex android-multidex

我有一个刚刚超过方法限制的Android应用程序,所以我尝试启用multidex。一旦我这样做,我得到以下错误:

org.gradle.api.tasks.TaskExecutionException: Execution failed for task ':app:transformClassesWithMultidexlistForProdDebug'.
    at org.gradle.api.internal.tasks.execution.ExecuteActionsTaskExecuter.executeActions(ExecuteActionsTaskExecuter.java:100)
    at org.gradle.api.internal.tasks.execution.ExecuteActionsTaskExecuter.execute(ExecuteActionsTaskExecuter.java:70)
    at org.gradle.api.internal.tasks.execution.SkipUpToDateTaskExecuter.execute(SkipUpToDateTaskExecuter.java:63)
    at org.gradle.api.internal.tasks.execution.ResolveTaskOutputCachingStateExecuter.execute(ResolveTaskOutputCachingStateExecuter.java:54)
    at org.gradle.api.internal.tasks.execution.ValidatingTaskExecuter.execute(ValidatingTaskExecuter.java:58)
    at org.gradle.api.internal.tasks.execution.SkipEmptySourceFilesTaskExecuter.execute(SkipEmptySourceFilesTaskExecuter.java:88)
    at org.gradle.api.internal.tasks.execution.ResolveTaskArtifactStateTaskExecuter.execute(ResolveTaskArtifactStateTaskExecuter.java:52)
    at org.gradle.api.internal.tasks.execution.SkipTaskWithNoActionsExecuter.execute(SkipTaskWithNoActionsExecuter.java:52)
    at org.gradle.api.internal.tasks.execution.SkipOnlyIfTaskExecuter.execute(SkipOnlyIfTaskExecuter.java:54)
    at org.gradle.api.internal.tasks.execution.ExecuteAtMostOnceTaskExecuter.execute(ExecuteAtMostOnceTaskExecuter.java:43)
    at org.gradle.api.internal.tasks.execution.CatchExceptionTaskExecuter.execute(CatchExceptionTaskExecuter.java:34)
    at org.gradle.execution.taskgraph.DefaultTaskGraphExecuter$EventFiringTaskWorker$1.run(DefaultTaskGraphExecuter.java:248)
    at org.gradle.internal.progress.DefaultBuildOperationExecutor$RunnableBuildOperationWorker.execute(DefaultBuildOperationExecutor.java:336)
    at org.gradle.internal.progress.DefaultBuildOperationExecutor$RunnableBuildOperationWorker.execute(DefaultBuildOperationExecutor.java:328)
    at org.gradle.internal.progress.DefaultBuildOperationExecutor.execute(DefaultBuildOperationExecutor.java:197)
    at org.gradle.internal.progress.DefaultBuildOperationExecutor.run(DefaultBuildOperationExecutor.java:107)
    at org.gradle.execution.taskgraph.DefaultTaskGraphExecuter$EventFiringTaskWorker.execute(DefaultTaskGraphExecuter.java:241)
    at org.gradle.execution.taskgraph.DefaultTaskGraphExecuter$EventFiringTaskWorker.execute(DefaultTaskGraphExecuter.java:230)
    at org.gradle.execution.taskgraph.DefaultTaskPlanExecutor$TaskExecutorWorker.processTask(DefaultTaskPlanExecutor.java:124)
    at org.gradle.execution.taskgraph.DefaultTaskPlanExecutor$TaskExecutorWorker.access$200(DefaultTaskPlanExecutor.java:80)
    at org.gradle.execution.taskgraph.DefaultTaskPlanExecutor$TaskExecutorWorker$1.execute(DefaultTaskPlanExecutor.java:105)
    at org.gradle.execution.taskgraph.DefaultTaskPlanExecutor$TaskExecutorWorker$1.execute(DefaultTaskPlanExecutor.java:99)
    at org.gradle.execution.taskgraph.DefaultTaskExecutionPlan.execute(DefaultTaskExecutionPlan.java:625)
    at org.gradle.execution.taskgraph.DefaultTaskExecutionPlan.executeWithTask(DefaultTaskExecutionPlan.java:580)
    at org.gradle.execution.taskgraph.DefaultTaskPlanExecutor$TaskExecutorWorker.run(DefaultTaskPlanExecutor.java:99)
    at org.gradle.internal.concurrent.ExecutorPolicy$CatchAndRecordFailures.onExecute(ExecutorPolicy.java:63)
    at org.gradle.internal.concurrent.ManagedExecutorImpl$1.run(ManagedExecutorImpl.java:46)
    at org.gradle.internal.concurrent.ThreadFactoryImpl$ManagedThreadRunnable.run(ThreadFactoryImpl.java:55)
Caused by: java.lang.RuntimeException: java.io.IOException: Can't write [/Users/user/dev/myapp/app/build/intermediates/multi-dex/prod/debug/componentClasses.jar] (Can't read [/Users/user/dev/myapp/app/build/intermediates/transforms/desugar/prod/debug/65.jar(;;;;;;**.class)] (Duplicate zip entry [65.jar:android/support/multidex/MultiDex.class]))
    at com.android.builder.profile.Recorder$Block.handleException(Recorder.java:55)
    at com.android.builder.profile.ThreadRecorder.record(ThreadRecorder.java:104)
    at com.android.build.gradle.internal.pipeline.TransformTask.transform(TransformTask.java:213)
    at org.gradle.internal.reflect.JavaMethod.invoke(JavaMethod.java:73)
    at org.gradle.api.internal.project.taskfactory.DefaultTaskClassInfoStore$IncrementalTaskAction.doExecute(DefaultTaskClassInfoStore.java:173)
    at org.gradle.api.internal.project.taskfactory.DefaultTaskClassInfoStore$StandardTaskAction.execute(DefaultTaskClassInfoStore.java:134)
    at org.gradle.api.internal.project.taskfactory.DefaultTaskClassInfoStore$StandardTaskAction.execute(DefaultTaskClassInfoStore.java:121)
    at org.gradle.api.internal.tasks.execution.ExecuteActionsTaskExecuter$1.run(ExecuteActionsTaskExecuter.java:122)
    at org.gradle.internal.progress.DefaultBuildOperationExecutor$RunnableBuildOperationWorker.execute(DefaultBuildOperationExecutor.java:336)
    at org.gradle.internal.progress.DefaultBuildOperationExecutor$RunnableBuildOperationWorker.execute(DefaultBuildOperationExecutor.java:328)
    at org.gradle.internal.progress.DefaultBuildOperationExecutor.execute(DefaultBuildOperationExecutor.java:197)
    at org.gradle.internal.progress.DefaultBuildOperationExecutor.run(DefaultBuildOperationExecutor.java:107)
    at org.gradle.api.internal.tasks.execution.ExecuteActionsTaskExecuter.executeAction(ExecuteActionsTaskExecuter.java:111)
    at org.gradle.api.internal.tasks.execution.ExecuteActionsTaskExecuter.executeActions(ExecuteActionsTaskExecuter.java:92)
    ... 27 more
Caused by: java.io.IOException: Can't write [/Users/user/dev/myapp/app/build/intermediates/multi-dex/prod/debug/componentClasses.jar] (Can't read [/Users/user/dev/myapp/app/build/intermediates/transforms/desugar/prod/debug/65.jar(;;;;;;**.class)] (Duplicate zip entry [65.jar:android/support/multidex/MultiDex.class]))
    at proguard.OutputWriter.writeOutput(OutputWriter.java:187)
    at proguard.OutputWriter.execute(OutputWriter.java:79)
    at proguard.ProGuard.writeOutput(ProGuard.java:427)
    at proguard.ProGuard.execute(ProGuard.java:175)
    at com.android.build.gradle.internal.transforms.BaseProguardAction.runProguard(BaseProguardAction.java:61)
    at com.android.build.gradle.internal.transforms.MainDexListTransform.shrinkWithProguard(MainDexListTransform.java:232)
    at com.android.build.gradle.internal.transforms.MainDexListTransform.transform(MainDexListTransform.java:184)
    at com.android.build.gradle.internal.pipeline.TransformTask$2.call(TransformTask.java:222)
    at com.android.build.gradle.internal.pipeline.TransformTask$2.call(TransformTask.java:218)
    at com.android.builder.profile.ThreadRecorder.record(ThreadRecorder.java:102)
    ... 39 more
Caused by: java.io.IOException: Can't read [/Users/user/dev/myapp/app/build/intermediates/transforms/desugar/prod/debug/65.jar(;;;;;;**.class)] (Duplicate zip entry [65.jar:android/support/multidex/MultiDex.class])
    at proguard.InputReader.readInput(InputReader.java:188)
    at proguard.InputReader.readInput(InputReader.java:158)
    at proguard.OutputWriter.writeOutput(OutputWriter.java:176)
    ... 48 more
Caused by: java.io.IOException: Duplicate zip entry [65.jar:android/support/multidex/MultiDex.class]
    at proguard.io.JarWriter.getOutputStream(JarWriter.java:138)
    at proguard.io.FilteredDataEntryWriter.getOutputStream(FilteredDataEntryWriter.java:106)
    at proguard.io.FilteredDataEntryWriter.getOutputStream(FilteredDataEntryWriter.java:106)
    at proguard.io.FilteredDataEntryWriter.getOutputStream(FilteredDataEntryWriter.java:92)
    at proguard.io.ClassRewriter.read(ClassRewriter.java:68)
    at proguard.io.FilteredDataEntryReader.read(FilteredDataEntryReader.java:87)
    at proguard.io.FilteredDataEntryReader.read(FilteredDataEntryReader.java:87)
    at proguard.io.FilteredDataEntryReader.read(FilteredDataEntryReader.java:87)
    at proguard.io.JarReader.read(JarReader.java:65)
    at proguard.io.DirectoryPump.readFiles(DirectoryPump.java:65)
    at proguard.io.DirectoryPump.pumpDataEntries(DirectoryPump.java:53)
    at proguard.InputReader.readInput(InputReader.java:184)
    ... 50 more

这是我的gradle构建文件:

def versionMajor = 1
def versionMinor = 0
def versionPatch = 0
def versionBuild = 0 // bump for dogfood builds, public betas, etc.


apply plugin: 'com.android.application'
apply plugin: 'kotlin-android'
apply plugin: 'kotlin-android-extensions'
apply plugin: 'kotlin-kapt' // Use experimental kapt implementation

apply plugin: 'com.jakewharton.hugo'

def gitSha() {
    def p = 'git rev-parse --short HEAD'.execute([], project.rootDir)
    p.waitFor()
    if (p.exitValue() != 0) {
        throw new RuntimeException(p.errorStream.text)
    }

    return p.text.trim()
}

def gitTimestamp() {
    def p = 'git log -n 1 --format=%at'.execute([], rootDir)
    p.waitFor()
    if (p.exitValue() != 0) {
        throw new RuntimeException(p.errorStream.text)
    }

    return p.text.trim()
}


repositories {
    mavenCentral()
    maven {
        url "http://dl.bintray.com/ttymsd/maven"
    }
    maven { url 'https://jitpack.io' }
}
android {
    compileSdkVersion versions.compileSdk
    buildToolsVersion versions.buildTools

    defaultConfig {
        applicationId "tv.myapp"

        minSdkVersion versions.minSdk
        targetSdkVersion versions.targetSdk

        buildConfigField 'String', 'GIT_SHA', "\"${gitSha()}\""
        buildConfigField 'long', 'GIT_TIMESTAMP', "${gitTimestamp()}L"

        versionCode versionMajor * 10000 + versionMinor * 1000 + versionPatch * 100 + versionBuild
        versionName "${versionMajor}.${versionMinor}.${versionPatch}"

        testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
        vectorDrawables.useSupportLibrary = true
        multiDexEnabled = true
    }

    sourceSets {
        main.java.srcDirs += 'src/main/java'
    }


    buildTypes {
        debug {
            applicationIdSuffix '.debug'
        }

        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
    }

    flavorDimensions "environment"

    productFlavors {
        prod {
            dimension "environment"
            buildConfigField 'boolean', 'FABRIC', 'true'
            buildConfigField 'String', 'ENV', '"PRODUCTION"'
            applicationId = "tv.myapp"
        }

        beta {
            dimension "environment"
            buildConfigField 'boolean', 'FABRIC', 'true'
            buildConfigField 'String', 'ENV', '"PRODUCTION"'
            applicationId = "tv.myapp.beta"
        }

        dev {
            dimension "environment"
            buildConfigField 'boolean', 'FABRIC', 'false'
            buildConfigField "String", "ENV", '"STAGING"'
            applicationId = "tv.myapp.dev"
        }

    }

    compileOptions {
        sourceCompatibility JavaVersion.VERSION_1_8
        targetCompatibility JavaVersion.VERSION_1_8
    }

    lintOptions {
        textReport true
        textOutput 'stdout'
        lintConfig rootProject.file('lint.xml')
        // We run a full lint analysis as build part in CI, so skip vital checks for assemble tasks.
        checkReleaseBuilds false
    }


    dataBinding {
        enabled = true
    }

    buildToolsVersion '26.0.2'
    dependencies {

        //Kotlin
        implementation deps.kotlin.core
        implementation deps.kotlin.reflect

        //UI
        implementation deps.sectionedRecyclerview
        implementation deps.support.constraint
        implementation deps.support.cardview

        //Support
        implementation deps.support.appCompat
        implementation(deps.support.design) {
            exclude group: "com.android.support", module: 'multidex'
        }
        implementation deps.support.v4
        implementation deps.support.fragment
        implementation deps.support.recyclerView
        implementation deps.support.vector

        //Cast
        implementation deps.cast.mediarouter
        implementation deps.cast.playServices

        //Net
        implementation deps.retrofit.core
        implementation deps.retrofit.gson
        implementation deps.retrofit.rxjava

        implementation deps.okhttp.core
        implementation deps.okhttp.urlConnection
        implementation deps.okhttp.logger

        implementation deps.picasso

        //Logging
        compile deps.timber

        //Gson
        implementation deps.gson

        //Rx
        implementation deps.rx.core
        implementation deps.rx.android
        implementation deps.rx.kotlin
        implementation deps.rx.rxDelay

        // DEPENDENCY INJECTION LIBRARIES
        kapt deps.dagger.compiler
        implementation deps.dagger.runtime

        // Databinding
        kapt deps.databinding

        implementation deps.exoplayer

        //Test
        testImplementation deps.junit
        testImplementation deps.espresso.core
        testImplementation deps.espresso.contrib


        implementation deps.multidex
    }
}

这是依赖关系定义:

ext.versions = [
            'buildTools'    : '26.0.2',
            'minSdk'        : 17,
            'targetSdk'     : 26,
            'compileSdk'    : 26,
            'supportLibrary': '26.0.0',

            'dagger'        : '2.9',
            //Net
            'okHttp'        : '3.4.2',
            'retrofit'      : '2.3.0',
            'retrorx'       : '1.0.0',

            'gson'          : '2.4',
            'picasso'       : '2.5.2',

            //Rx
            'rxjava'        : '2.1.0',
            'rxandroid'     : '2.0.1',
            'rxkotlin'      : '2.1.0',
            'rxpreferences' : '1.0.2',

            //App dependencies
            'junit'         : '4.12',
            'espresso'      : '2.2.2',

            //UI
            'coordinator'   : '0.3.3',
            'playServices'  : '10.2.0',

            'kotlin'        : '1.1.3-2',

    ]

    ext.deps = [
            'support'              : [
                    'annotations' : "com.android.support:support-annotations:${versions.supportLibrary}",
                    'v4'          : "com.android.support:support-v4:${versions.supportLibrary}",
                    'appCompat'   : "com.android.support:appcompat-v7:${versions.supportLibrary}",
                    'design'      : "com.android.support:design:${versions.supportLibrary}",
                    'recyclerView': "com.android.support:recyclerview-v7:${versions.supportLibrary}",
                    'fragment'    : "com.android.support:support-fragment:${versions.supportLibrary}",
                    'vector'      : "com.android.support:animated-vector-drawable:${versions.supportLibrary}",
                    'cardview'    : "com.android.support:cardview-v7:${versions.supportLibrary}",
                    'constraint'  : "com.android.support.constraint:constraint-layout:1.0.2",

            ],
            'dagger'               : [
                    'compiler': "com.google.dagger:dagger-compiler:${versions.dagger}",
                    'runtime' : "com.google.dagger:dagger:${versions.dagger}",
            ],
            'okhttp'               : [
                    'core'         : "com.squareup.okhttp3:okhttp:${versions.okHttp}",
                    'logger'       : "com.squareup.okhttp3:logging-interceptor:${versions.okHttp}",
                    'urlConnection': "com.squareup.okhttp3:okhttp-urlconnection:${versions.okHttp}"
            ],
            'retrofit'             : [
                    'core'  : "com.squareup.retrofit2:retrofit:${versions.retrofit}",
                    'mock'  : "com.squareup.retrofit2:retrofit-mock:${versions.retrofit}",
                    'gson'  : "com.squareup.retrofit2:converter-gson:${versions.retrofit}",
                    'rxjava': "com.jakewharton.retrofit:retrofit2-rxjava2-adapter:${versions.retrorx}",
            ],
            'rx'                   : [
                    'core'       : "io.reactivex.rxjava2:rxjava:${versions.rxjava}",
                    'android'    : "io.reactivex.rxjava2:rxandroid:${versions.rxandroid}",
                    'preferences': "com.f2prateek.rx.preferences:rx-preferences:${versions.rxpreferences}",
                    'kotlin'     : "io.reactivex.rxjava2:rxkotlin:${versions.rxkotlin}",
                    'rxDelay'    : 'com.github.Plastix.RxDelay:rx2:0.5.0',
            ],
            'cast'                 : [
                    'mediarouter' : "com.android.support:mediarouter-v7:${versions.supportLibrary}",
                    'playServices': 'com.google.android.gms:play-services-cast-framework:10.2.1',
            ],
            'kotlin'               : [
                    'core'  : "org.jetbrains.kotlin:kotlin-stdlib-jre7:${versions.kotlin}",
                    'reflect': "org.jetbrains.kotlin:kotlin-reflect:${versions.kotlin}"
            ],

            'sectionedRecyclerview': 'com.afollestad:sectioned-recyclerview:0.5.0',
            'targetTooltip'        : 'it.sephiroth.android.library.targettooltip:target-tooltip-library:1.3.15',

            'picasso'              : "com.squareup.picasso:picasso:${versions.picasso}",
            'timber'               : 'com.jakewharton.timber:timber:4.1.2',
            'gson'                 : "com.google.code.gson:gson:${versions.gson}",
            'databinding'          : "com.android.databinding:compiler:$android_plugin_version",
            'exoplayer'            : 'com.google.android.exoplayer:exoplayer:r2.5.1',
            'junit'                : "junit:junit:${versions.junit}",

            'espresso'             : [
                    'core'   : "com.android.support.test.espresso:espresso-core:${versions.espresso}",
                    'contrib': "com.android.support.test.espresso:espresso-contrib:${versions.espresso}",
            ],
            'multidex': "com.android.support:multidex:1.0.2"
    ]

项目正在Kotlin开发,使用Android Studio 3.0,gradle plugin 3.0.0。

我试过没有明确地将依赖关系放在依赖关系部分,我尝试从“设计”中排除(据我所知,这是唯一依赖传递带来multidex的依赖),我尝试使用multidex 1.0.1,1.0.2但似乎没什么用。

我已经没想完了。如果我切换到“开发”味道,神秘地起作用。

3 个答案:

答案 0 :(得分:0)

您可能不需要自行导入Multidex。 Multidex包含在android.support中,它可能与您尝试自行导入的multidex冲突。尝试删除该行,看看它是否有效。

此外,"构建口味的原因"工作是因为您的发布版本指向要遵循的proguard文件。如果你的proguard文件有-keep class android.support.*,我很好奇,这就是multidex失败的原因。

希望这有帮助!

答案 1 :(得分:0)

对于这个完全相同的问题,我们有一个绝对值得称赞的原因:

debugImplementation "com.android.support:multidex:1.0.2"

我们项目中的release有一个android.support.multidex.MultiDex构建风味特定实现,包含所有包,所有内容都是空的(无效)。

因此删除违规类会修复构建。

implementation "com.android.support:multidex:1.0.2"

答案 2 :(得分:0)

最近,我遇到了这个问题,下面是我收到的异常消息

(Duplicate zip entry [multidex.jar:android/support/multidex/MultiDex$V14.class]))

我不知道此问题的背景,但此问题的根本原因是

  1. 从Google存储库添加Maven依赖项(我们在gradle同步期间收到的添加Maven依赖项的提示)

当删除并尝试构建APK时,它起作用了!

!不错的解决方案!