Duplicate classes from androidx and com.android.support

て烟熏妆下的殇ゞ 提交于 2019-12-09 07:23:44

问题


I recently updated my Android Studio (and I'm pretty sure the Gradle version), and now I've been getting a bunch of errors when trying to compile my project. Here's the one that is plaguing me at the moment:

Duplicate class android.support.v4.app.INotificationSideChannel found in modules classes.jar (androidx.core:core:1.0.1) and classes.jar (com.android.support:support-compat:26.1.0)

This is followed by lots of similar ones.

I tried removing all uses of com.android.support in favor of androidx (see here for what I was using the replace things), but com.android.support libraries are still being used, even when I delete the libraries (they're just remade once I try to compile again).

Here's a link to the full error I get.


回答1:


I hope you have in your gradle.properties these two lines:

(If you don't have a gradle.properties, then simply create it in the root directory of your project)

android.useAndroidX=true
android.enableJetifier=true

It looks like you have some support relics any where in your dependencies, maybe form a lib ? To investigate and see the dependencies tree, please run

./gradlew :yourApp:dependencies

and then you see from where it comes.




回答2:


In your app build.gradle you are using a mix of old support library and new support library artifacts. Remove one of them from your build.gradle to resolve this issue.

Old artifact: com.android.support:support-compat

Corresponding new artifact: androidx.core:core:1.0.0

See this page for more information on migrating to AndroidX.




回答3:


This solution from here worked the best for me. Migrating to androidX

https://developer.android.com/jetpack/androidx/migrate

With Android Studio 3.2 and higher, you can migrate an existing project to AndroidX by selecting Refactor > Migrate to AndroidX from the menu bar.

The refactor command makes use of two flags. By default, both of them are set to true in your gradle.properties file:

android.useAndroidX=true The Android plugin uses the appropriate AndroidX library instead of a Support Library. android.enableJetifier=true The Android plugin automatically migrates existing third-party libraries to use AndroidX by rewriting their binaries.




回答4:


Like others says, the solution is to migrating to AndroidX, it works for me. However, it isn´t an easy way and it requires a bit of pacience... These are the steps that I did:

  • First, is very important that you do all this changes in a different branch or you make a backup of your project.

  • You need to have the Android Gradle Plugin Version 3.5.1. So, in build.gradle set: dependencies { classpath 'com.android.tools.build:gradle:3.5.1' ...

  • Migrate to AndroidX using Android Studio Tool : Refactor --> Migrate to AndroidX...
  • When it finishes, it has done all pertinents modification, but posibly you can´t deploy the project correctly because you find any errors. These are the problems that I found and the solutions:

  • If you use Kotlin, in build.gradle set: buildscript { ext.kotlin_version = '1.3.10' ... and compile "org.jetbrains.kotlin:kotlin-stdlib-jdk8:$kotlin_version"

  • If you use destination method, add "file" parameter: destination file("$reportsDir/checkstyle/checkstyle.xml")
  • If you use Butterknife, use 10.0.0 version
  • Finally, Build --> Clean Project and Build --> Rebuild Project



回答5:


go to the Gradle Scrpits->gradle.properties and then paste this code :

- android.useAndroidX=true
- android.enableJetifier=true

and rebulid your project. good luck :)



来源:https://stackoverflow.com/questions/55756647/duplicate-classes-from-androidx-and-com-android-support

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