重复的 Zip 条目 MultiDex.class
Posted
技术标签:
【中文标题】重复的 Zip 条目 MultiDex.class【英文标题】:Duplicate Zip entry MultiDex.class 【发布时间】:2018-04-15 01:01:39 【问题描述】:我有一个刚刚超过方法限制的 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 插件 3.0.0。
我尝试不明确地将依赖项放在依赖项部分,我尝试从“设计”中排除(据我所知,这是唯一可传递带来 multidex 的依赖项),我尝试使用 multidex 1.0.1、1.0.2但似乎没有任何效果。
我的想法已经用完了。如果我切换到“开发”风格,它会神秘地起作用。
【问题讨论】:
我遇到了这个问题,因为您使用的是两个或多个使用不同版本的 multidex 类编译的库。 @AbuQauod 我检查了 app:dependencies 并且只有 support-design 正在使用 multidex,我尝试排除它(如您在我的 build.gradle 中看到的) 你有什么发现吗?我遇到了同样的问题,我似乎无法找出到底是什么原因造成的。 【参考方案1】:您可能不需要自己导入 Multidex。 Multidex 包含在 android.support
中,它可能与您尝试自己导入的 multidex 冲突。尝试删除该行,看看它是否有效。
此外,“构建风格”起作用的原因是您的发布构建指向要遵循的 proguard 文件。我很好奇你的 proguard 文件是否有 -keep class android.support.*
,这就是 multidex 对你失败的原因。
希望这会有所帮助!
【讨论】:
【参考方案2】:对于这个完全相同的问题,我们有一个绝对值得面对的原因:
debugImplementation "com.android.support:multidex:1.0.2"
在我们的项目中有一个 release
为 android.support.multidex.MultiDex
构建风味特定的实现,其中包含包和所有内容,这是一个空存根(什么都不做)。
因此删除有问题的类修复了构建。
implementation "com.android.support:multidex:1.0.2"
【讨论】:
【参考方案3】:最近,我遇到了这个问题,下面是我收到的异常消息
(Duplicate zip entry [multidex.jar:android/support/multidex/MultiDex$V14.class]))
我不知道这个问题的背景,但这个问题的根本原因是
-
从 google repo 添加 maven 依赖项(我们在 gradle 同步期间获得的添加 maven 依赖项的提示)
删除并尝试构建 APK 后,它成功了!
!相当hacky的解决方案!
【讨论】:
以上是关于重复的 Zip 条目 MultiDex.class的主要内容,如果未能解决你的问题,请参考以下文章
Gradle Plugin v0.13.1 后重复的 Zip 条目
java.util.zip.ZipException:重复条目
如何解决 Android 中的“TransformException:java.util.zip.ZipException:重复条目”?
Cordova Android 应用程序构建问题 - 重复的 zip 条目
如何修复 java.util.zip.ZipException:重复条目:com/google/firebase/FirebaseApiNotAvailableException.class?