Error while merging dex Program type already present: android.support.v4.os.ResultReceiver$MyResultReceiver

◇◆丶佛笑我妖孽 提交于 2019-11-27 11:46:37

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.

add following lines on gradle.properties

android.useAndroidX=true
android.enableJetifier=true

and change your room dependencies on build.gradle(moudel:app)

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

Migrate the dependencies to androidx dependencies. And in gradle.properties add the below lines (If not created already, create the file in root folder).

android.useAndroidX=true
android.enableJetifier=true

Hope this helps.

This is what worked for me was Refactor -> Migrate to AndroidX option in Android Studio. This seemed to resolve any things I may have missed when trying to do the AndroidX migration one dependency at a time. https://developer.android.com/jetpack/androidx/migrate

I had the same problem.

Do not mix dependencies styles(androidx and com.android.support) in your project.

In your code try to replace

implementation "androidx.appcompat:appcompat:$support_lib"

with

implementation "com.android.support:appcompat-v7:$version_of_support_library"

A full list of dependencies migration you can find here .

I should use old style dependency because I needed WorkManager and according to official documentation WorkManager currently without AndroidX dependencies.

WorkManager classes are already in the androidx.work package, but currently depend on Support Library 27.1, and associated Arch component versions. Version of WorkManager with AndroidX dependencies will be released in the future.

What worked for me was Refactor -> Migrate to AndroidX option in Android Studio. This seemed to resolve any things I may have missed when trying to do the AndroidX migration one dependency at a time. https://developer.android.com/jetpack/androidx/migrate

Anil

Check the package which clashes with the com.android.support and exclude it from that package. For me, I was using androidx packages and also FCM, where there was a clash. So, this fixed for me:

implementation ('com.google.firebase:firebase-core:16.0.4') {
    exclude group: 'com.android.support'
}

for my instance i had upgraded from implementation 'com.github.bumptech.glide:glide:4.0.0 to implementation 'com.github.bumptech.glide:glide:4.7.1'

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