問題描述
合并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的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!