Duplicate classes from androidx and com.android.support

TheKingElessar picture TheKingElessar · Apr 19, 2019 · Viewed 61.8k times · Source

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.

Answer

hannes ach picture hannes ach · Apr 19, 2019

Add these lines to gradle.properties:

android.useAndroidX=true
android.enableJetifier=true

If gradle.properties is absent, create the file in the root directory of your project.

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

./gradlew :yourApp:dependencies

and then you see from where it comes.