Search code examples
androidandroid-studioandroid-gradle-pluginlibrariesandroidx

Duplicate classes from androidx and com.android.support


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.


Solution

  • Add these lines to your 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
    

    then you'll see from where it comes.