Duplicate class android.support.v4.app.INotificationSideChannel found in modules classes?

前端 未结 6 1347
刺人心
刺人心 2020-11-29 05:54

I am developing a news app but I am getting following errors in from gradle console

(androidx.core:core:1.0.1) and classes.jar (com.android.support:support-c         


        
相关标签:
6条回答
  • 2020-11-29 06:07

    Taken from here. AndroidX is the open-source project that the Android team uses to develop, test, package, version and release libraries within Jetpack.

    0 讨论(0)
  • 2020-11-29 06:09

    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.).

    0 讨论(0)
  • 2020-11-29 06:16

    Top-Master's answer only work if you can downgrade to a specific version. In my case, I have a React Native app and one of the libraries I was using had migrated to AndroidX. The previous version had issues with iOS, so I had to use the most recent version. What I had to do was:

    1. Migrate the Android project to AndroidX (Refactor > Migrate to AndroidX).
    2. Use jetify to convert node_module dependencies to AndroidX. For React Native 0.60 and above, jetify is run automatically, so you don't have to install this library.
    0 讨论(0)
  • 2020-11-29 06:20

    You can add below lines into your gradle.properties file:

    android.useAndroidX=true
    android.enableJetifier=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.

    0 讨论(0)
  • I run into something like this, and below is based on my other answer:

    Your project (or one of its sub-projects) is referring to a dependency using the + plus-sign at its end, like com.google.firebase:firebase-auth:+, which means, use any higher version when possible, and that newer version is no longer using android.support libraries and instead is using androidx; to fix this issue follow the below steps.

    Steps:

    1. Ensure the ANDROID_HOME environment-variable is set, and then, open a console window (like git-bash, because it keeps the whole command output), and cd into your project's android directory (for Ionic projects it should be platforms/android).
    2. First, List all dependencies by running below (in git-bash):
      ./gradlew :app:dependencies
      
    3. Copy the result into your preferred text-editor, and search for androidx.
    4. If you found something follow below steps, else you are done! (and you do not need to repeat these steps).
    5. Scroll up until you see -> at the end of any line, like for example 16.0.8 -> 19.0.0 or + -> 19.0.0, which both mean that the version was auto-resolved (to something higher than specified by you because of +).
    6. So, set the version down manually:
      • When possible, in your project (or sub-project) find and replace the + sign with a specific version.
      • Or, force a specific version of the dependencies like mentioned below.
    7. At last, repeat above steps (but instead of step one just clear the console).

    To Force specific version of the dependencies add to your root build.gradle file something like below (which is what worked for me) but of course edit below and add your own rules (because these might not work for your case):

    allprojects {
      // ...
      configurations.all {
        resolutionStrategy {
          force 'com.google.firebase:firebase-common:17.0.0'
          force 'com.google.android.gms:play-services-basement:16.2.0'
          force 'com.google.firebase:firebase-iid:16.0.0'
          force 'com.google.firebase:firebase-auth:17.0.0'
        }
      }
    }
    
    0 讨论(0)
  • 2020-11-29 06:28

    Like @Ahmed says, the solution is to implement 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
    0 讨论(0)
提交回复
热议问题