Duplicate class android.support.v4.app.INotificationSideChannel found in modules classes?
You can add below 2 lines into your gradle.properties
file:
android.useAndroidX=true
android.enableJetifier=true
Note to check, to not repeat any line that already exists (and ensure existing are
true
).
Details:
If you want to use androidx
-namespaced libraries in a new project, you need to set the compile SDK to Android 9.0 (API level 28) or higher and set both of the mentioned Android Gradle plugin flags to true
.
android.useAndroidX
: When this flag is set to true
, the Android plugin uses the appropriate AndroidX library instead of a Support Library. The flag is false
by default if it is not specified.
android.enableJetifier
: When this flag is set to true
, the Android plugin automatically migrates existing third-party libraries to use AndroidX dependencies by rewriting their binaries. The flag is false
by default if it is not specified.
Adding these lines to gradle.properties file solves "Duplicate Class" errors:
android.useAndroidX=true
android.enableJetifier=true
However, this generated new errors in my project:
"package android.support.annotation does not exist"
"cannot find symbol class Fragment"
"package android.support.v4.content does not exist"
"Program type already present"
etc.
However, the refactoring worked for me:
Migrate your project to AndroidX by selecting Refactor >
"Migrate to AndroidX" from the menu bar.
Select Build > Clean project
Restore Android Studio
Now, my project (Match4app) works with AndroidX and I was able to publish it in the PlayStore without any issues.
Comment: This task also allowed me to upgrade all other libraries that depend on AndroidX (i.e. com.firebaseui:firebase-ui-auth:6.0.2, com.google.android.gms:play-services-games:18.0.1, com.google.android.gms:play-services-auth:17.0.0, com.google.android.gms:play-services-ads:18.2.0, etc.).
I was having this same issue and this is how i resolved it
Expand Graddle Scripts and then Go to graddle.properties and add these 2 lines
Note: Maybe the first line android.useAndroidX=true is already there so do not repeat it.
android.useAndroidX=true android.enableJetifier=true