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:

Your project (or one of its sub-projects, or a dependency) is no longer using android.support libraries and instead is using androidx libraries, which causes conflicts if mixed with android.support libraries.

If you want to use androidx-namespaced libraries in an old project, you need to set the compile SDK to Android 9.0 (API level 28) or higher but below "API level 31", 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.

  • 3
    Can you add a little more information about what exactly this is doing?  May 27, 2019 at 23:52
  • 3
    @NathanF. this is because of mixing support libraries. by adding these lines androidX selected as your support library  May 28, 2019 at 11:40 
  • 3
    This will just forcibly replace any dependency on android.support.* with androidx.* dependencies (but for me, it just resulted in a compile error because android.support was used in the codes), in case anyone is seeking a fix instead of a workaround check the answer for Execution failed for task ':app:checkDebugDuplicateClasses' (although that question is about Ionic the answer should work).  Jun 29, 2019 at 4:46 
  • 2
    @nicej I was able to solve the issue by selecting Refactor > "Migrate to AndroidX" from the menu bar. Thanks.  Oct 1, 2019 at 11:52
  • 2
    Perhaps this resolution shouldn't be your first choice guys, it tends to slow down project builds, as stated in the docs: "Caution: As of late 2021, most of the library ecosystem already supports AndroidX natively. This means that your project is most likely already using AndroidX libraries directly and there is no need to follow the steps in this migration guide. Additionally, the enableJetifier flag mentioned in this guide can lead to slower build times and should not be used unless it’s necessary."  Jun 25, 2022 at 18:49 
35

Adding these lines to gradle.properties file solves "Duplicate Class" errors:

android.useAndroidX=true

android.enableJetifier=true

留言