合并 dex 程序类型已存在时出错:android.support.v4.os.ResultReceiver$MyRes

Error while merging dex Program type already present: android.support.v4.os.ResultReceiver$MyResultReceiver(合并 dex 程序类型已存在时出错:android.support.v4.os.ResultReceiver$MyResultReceiver)
本文介绍了合并 dex 程序类型已存在时出错:android.support.v4.os.ResultReceiver$MyResultReceiver的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

问题描述

合并dex时出错

以下是依赖项.

ext {anko_version='0.10.5'support_lib='1.0.0-alpha1'room_lib = "1.1.0"}依赖{实施org.jetbrains.kotlin:kotlin-stdlib-jdk8:$kotlin_version"实现androidx.cardview:cardview:$support_lib"实施com.google.android.material:material:$support_lib"实现androidx.appcompat:appcompat:$support_lib"实施org.jetbrains.anko:anko:$anko_version"实现androidx.lifecycle:lifecycle-extensions:2.0.0-alpha1"实现android.arch.persistence.room:runtime:$room_lib"annotationProcessor "android.arch.persistence.room:compiler:$room_lib"}

错误

  • 出了什么问题:任务 ':app:transformDexArchiveWithExternalLibsDexMergerForDebug' 执行失败.<块引用>

    com.android.builder.dexing.DexArchiveMergerException:合并 dex 档案时出错:/app/build/intermediates/transforms/dexBuilder/debug/0.jar,程序类型已存在:android.support.v4.os.ResultReceiver$1

解决方案

这是因为你搞砸了依赖关系.您必须要么完全迁移到 AndroidX 依赖项,要么继续使用支持库的依赖项.因此,而不是

实现android.arch.persistence.room:runtime:$room_lib"annotationProcessor "android.arch.persistence.room:compiler:$room_lib"

使用

实现androidx.room:room-runtime:2.0.0-alpha1"annotationProcessor "androidx.room:room-compiler:2.0.0-alpha1"

另外一定要检查你的 gradle.properties 项目文件是否包含

android.useAndroidX=trueandroid.enableJetifier=true

Jetifier 帮助依赖旧支持包的库使用新的 AndroidX 包.

什么是喷射器?这是一个在构建阶段调用的 Android Gradle 插件任务(现在也可以用作独立工具).AGP (>= 3.2.0) 会自动应用依赖转换,它会重写字节码和 JAR 和 AAR 依赖(以及传递依赖)的资源,以引用新的 androidx 打包类和工件.您还可以将其用作独立工具来单独迁移库.

Jetifier 官方文档

<块引用>

独立的 Jetifier 工具将依赖于支持库的库迁移为依赖等效的 AndroidX 包.该工具可让您直接迁移单个库,而不是使用与 Android Studio 捆绑的 Android gradle 插件.

P.S. 我没有测试 Anko 是否适用于 AndroidX 依赖项,但如果即使启用了 gradle.properties 中的那些属性也不能,你别无选择,只能回退到使用 Support图书馆和现在一样.

Error when merging the dex

following are the dependencies.

ext {
    anko_version='0.10.5'
    support_lib='1.0.0-alpha1'
    room_lib = "1.1.0"
}
dependencies {

    implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk8:$kotlin_version"
    implementation "androidx.cardview:cardview:$support_lib"
    implementation "com.google.android.material:material:$support_lib"
    implementation "androidx.appcompat:appcompat:$support_lib"
    implementation "org.jetbrains.anko:anko:$anko_version"
    implementation "androidx.lifecycle:lifecycle-extensions:2.0.0-alpha1"
    implementation "android.arch.persistence.room:runtime:$room_lib"
    annotationProcessor "android.arch.persistence.room:compiler:$room_lib"
}

error

  • What went wrong: Execution failed for task ':app:transformDexArchiveWithExternalLibsDexMergerForDebug'.

    com.android.builder.dexing.DexArchiveMergerException: Error while merging dex archives: /app/build/intermediates/transforms/dexBuilder/debug/0.jar, Program type already present: android.support.v4.os.ResultReceiver$1

解决方案

It's because you messed up the dependencies. You have to either fully migrate to AndroidX dependencies or stay on Support library ones. Thus, instead of

implementation "android.arch.persistence.room:runtime:$room_lib"
annotationProcessor "android.arch.persistence.room:compiler:$room_lib"

use

implementation "androidx.room:room-runtime:2.0.0-alpha1"
annotationProcessor "androidx.room:room-compiler:2.0.0-alpha1"

Also be sure to check your gradle.properties project file to contain

android.useAndroidX=true
android.enableJetifier=true

Jetifier helps libraries, which depend on old Support packages, to use the new AndroidX ones.

What is Jetifier? It's an Android Gradle Plugin task (now can also be used as a standalone tool) which is invoked during build phase. AGP (>= 3.2.0) does automatically apply dependency translation which rewrites bytecode and resources of JAR and AAR dependencies (and transitive dependencies) to reference the new androidx-packaged classes and artifacts. You can also use it as a standalone tool to individually migrate a library.

Jetifier Official Documentation

The standalone Jetifier tool migrates support-library-dependent libraries to rely on the equivalent AndroidX packages instead. The tool lets you migrate an individual library directly, instead of using the Android gradle plugin bundled with Android Studio.

P. S. I didn't test if Anko works with AndroidX dependencies, but if it doesn't even though those properties in your gradle.properties are enabled, you have no other choices, but fallback to using Support libraries as for now.

这篇关于合并 dex 程序类型已存在时出错:android.support.v4.os.ResultReceiver$MyResultReceiver的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

本站部分内容来源互联网,如果有图片或者内容侵犯您的权益请联系我们删除!

相关文档推荐

Android release APK crash with java.lang.AssertionError: impossible in java.lang.Enum(Android 发布 APK 因 java.lang.AssertionError 崩溃:在 java.lang.Enum 中不可能)
Finished with Non Zero Exit Value 3(以非零退出值 3 结束)
On gradle:3.0.0 More than one file was found with OS independent path #39;META-INF/ASL2.0#39;(在 gradle:3.0.0 上找到多个文件,其独立于操作系统的路径为“META-INF/ASL2.0)
Android : app loading library at runtime on Lollipop but not IceCreamSandwich(Android:运行时在 Lollipop 上而不是 IceCreamSandwich 上的应用程序加载库)
buildConfigField depending on flavor + buildType(buildConfigField 取决于风味 + buildType)
How do I suppress warnings when compiling an android library with gradle?(使用 gradle 编译 android 库时如何抑制警告?)