升级安卓版本后得到“重复类安卓.support.v4.app.INotificationSideChannel”

在Android更新3.4之前,我的应用程序运行完美,但在升级Android后,我的应用程序出现合并错误:

"Duplicate class android.support.v4.app.INotificationSideChannel"

android update 3.4
upgrade gradle 5.1.1 
upgrade sdk

Error:
    Duplicate class android.support.v4.app.INotificationSideChannel found in modules classes.jar (androidx.core:core:1.0.0) and classes.jar (com.android.support:support-compat:28.0.0)
    Duplicate class android.support.v4.app.INotificationSideChannel$Stub found in modules classes.jar (androidx.core:core:1.0.0) and classes.jar (com.android.support:support-compat:28.0.0)
    Duplicate class android.support.v4.app.INotificationSideChannel$Stub$Proxy found in modules classes.jar (androidx.core:core:1.0.0) and classes.jar (com.android.support:support-compat:28.0.0)
    Duplicate class android.support.v4.graphics.drawable.IconCompatParcelizer found in modules classes.jar (androidx.core:core:1.0.0) and classes.jar (com.android.support:support-compat:28.0.0)
    Duplicate class android.support.v4.os.IResultReceiver found in modules classes.jar (androidx.core:core:1.0.0) and classes.jar (com.android.support:support-compat:28.0.0)
    Duplicate class android.support.v4.os.IResultReceiver$Stub found in modules classes.jar (androidx.core:core:1.0.0) and classes.jar (com.android.support:support-compat:28.0.0)
    Duplicate class android.support.v4.os.IResultReceiver$Stub$Proxy found in modules classes.jar (androidx.core:core:1.0.0) and classes.jar (com.android.support:support-compat:28.0.0)
    Duplicate class android.support.v4.os.ResultReceiver found in modules classes.jar (androidx.core:core:1.0.0) and classes.jar (com.android.support:support-compat:28.0.0)
    Duplicate class android.support.v4.os.ResultReceiver$1 found in modules classes.jar (androidx.core:core:1.0.0) and classes.jar (com.android.support:support-compat:28.0.0)
    Duplicate class android.support.v4.os.ResultReceiver$MyResultReceiver found in modules classes.jar (androidx.core:core:1.0.0) and classes.jar (com.android.support:support-compat:28.0.0)
    Duplicate class android.support.v4.os.ResultReceiver$MyRunnable found in modules classes.jar (androidx.core:core:1.0.0) and classes.jar (com.android.support:support-compat:28.0.0)
    Duplicate class androidx.core.graphics.drawable.IconCompatParcelizer found in modules classes.jar (androidx.core:core:1.0.0) and classes.jar (com.android.support:support-compat:28.0.0)
    Duplicate class androidx.core.internal.package-info found in modules classes.jar (androidx.core:core:1.0.0) and classes.jar (com.android.support:support-compat:28.0.0)
    Duplicate class androidx.versionedparcelable.CustomVersionedParcelable found in modules classes.jar (androidx.versionedparcelable:versionedparcelable:1.0.0) and classes.jar (com.android.support:versionedparcelable:28.0.0)
    Duplicate class androidx.versionedparcelable.NonParcelField found in modules classes.jar (androidx.versionedparcelable:versionedparcelable:1.0.0) and classes.jar (com.android.support:versionedparcelable:28.0.0)
    Duplicate class androidx.versionedparcelable.ParcelField found in modules classes.jar (androidx.versionedparcelable:versionedparcelable:1.0.0) and classes.jar (com.android.support:versionedparcelable:28.0.0)
    Duplicate class androidx.versionedparcelable.ParcelImpl found in modules classes.jar (androidx.versionedparcelable:versionedparcelable:1.0.0) and classes.jar (com.android.support:versionedparcelable:28.0.0)
    Duplicate class androidx.versionedparcelable.ParcelImpl$1 found in modules classes.jar (androidx.versionedparcelable:versionedparcelable:1.0.0) and classes.jar (com.android.support:versionedparcelable:28.0.0)
    Duplicate class androidx.versionedparcelable.ParcelUtils found in modules classes.jar (androidx.versionedparcelable:versionedparcelable:1.0.0) and classes.jar (com.android.support:versionedparcelable:28.0.0)
    Duplicate class androidx.versionedparcelable.VersionedParcel found in modules classes.jar (androidx.versionedparcelable:versionedparcelable:1.0.0) and classes.jar (com.android.support:versionedparcelable:28.0.0)
    Duplicate class androidx.versionedparcelable.VersionedParcel$1 found in modules classes.jar (androidx.versionedparcelable:versionedparcelable:1.0.0) and classes.jar (com.android.support:versionedparcelable:28.0.0)
    Duplicate class androidx.versionedparcelable.VersionedParcel$ParcelException found in modules classes.jar (androidx.versionedparcelable:versionedparcelable:1.0.0) and classes.jar (com.android.support:versionedparcelable:28.0.0)
    Duplicate class androidx.versionedparcelable.VersionedParcelParcel found in modules classes.jar (androidx.versionedparcelable:versionedparcelable:1.0.0) and classes.jar (com.android.support:versionedparcelable:28.0.0)
    Duplicate class androidx.versionedparcelable.VersionedParcelStream found in modules classes.jar (androidx.versionedparcelable:versionedparcelable:1.0.0) and classes.jar (com.android.support:versionedparcelable:28.0.0)
    Duplicate class androidx.versionedparcelable.VersionedParcelStream$FieldBuffer found in modules classes.jar (androidx.versionedparcelable:versionedparcelable:1.0.0) and classes.jar (com.android.support:versionedparcelable:28.0.0)
    Duplicate class androidx.versionedparcelable.VersionedParcelStream$InputBuffer found in modules classes.jar (androidx.versionedparcelable:versionedparcelable:1.0.0) and classes.jar (com.android.support:versionedparcelable:28.0.0)
    Duplicate class androidx.versionedparcelable.VersionedParcelable found in modules classes.jar (androidx.versionedparcelable:versionedparcelable:1.0.0) and classes.jar (com.android.support:versionedparcelable:28.0.0)
    Duplicate class androidx.versionedparcelable.VersionedParcelize found in modules classes.jar (androidx.versionedparcelable:versionedparcelable:1.0.0) and classes.jar (com.android.support:versionedparcelable:28.0.0)

Go to the documentation to learn how to Fix dependency resolution errors.

------------------依赖性------------

dependencies {
    implementation fileTree(include: ['*.jar'], dir: 'libs')
    //noinspection GradleCompatible
    implementation 'com.android.support:appcompat-v7:28.0.0'
    implementation 'com.android.support:design:28.0.0'
    //noinspection GradleCompatible
//    implementation 'com.android.support:appcompat-v7:28.0.0'
    implementation 'com.android.support:support-compat:28.0.0'
    implementation 'com.android.support.constraint:constraint-layout:2.0.0-alpha4'
//    implementation 'com.android.support:design:28.0.0'
    testImplementation 'junit:junit:4.13-beta-2'
    androidTestImplementation 'com.android.support.test:runner:1.0.2'
    androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.2'
    //volley
    implementation 'com.android.volley:volley:1.1.0'
    //crop image library...
    implementation 'com.theartofdev.edmodo:android-image-cropper:2.8.0'
    //ButterKnife
    implementation 'com.jakewharton:butterknife:8.8.1'
    annotationProcessor 'com.jakewharton:butterknife-compiler:8.8.1'
    //retrofit
    implementation 'com.squareup.retrofit2:retrofit:2.5.0'
    implementation 'com.squareup.retrofit2:converter-gson:2.5.0'
    implementation 'com.squareup.retrofit2:adapter-rxjava:2.5.0'
    implementation 'io.reactivex:rxandroid:1.2.1'
    implementation 'com.github.traex.rippleeffect:library:1.3'
    //Google play services
    implementation 'com.google.android.gms:play-services-location:16.0.0'
    implementation 'com.google.android.gms:play-services-maps:16.1.0'
    //gson
    implementation 'com.google.code.gson:gson:2.8.5'
    // Room
    implementation 'android.arch.persistence.room:runtime:1.1.1'
    implementation 'com.android.support:support-v4:28.0.0'
    annotationProcessor "android.arch.persistence.room:compiler:1.1.1"
    implementation 'org.jsoup:jsoup:1.11.3'
    //cardview & recyclerview
    implementation 'com.android.support:cardview-v7:28.0.0'
    implementation 'com.android.support:recyclerview-v7:28.0.0'
    //picasoo
    implementation 'com.squareup.picasso:picasso:2.71828'
    implementation 'com.android.support:support-annotations:28.0.0'
    implementation 'de.hdodenhof:circleimageview:3.0.0'
    implementation 'com.karumi:dexter:5.0.0'
    implementation 'com.journeyapps:zxing-android-embedded:3.4.0'
    //firebase
    implementation 'com.google.firebase:firebase-core:16.0.8'
    implementation 'com.google.firebase:firebase-ml-vision:19.0.3'
    //firebase-cloud massaging..
    implementation 'com.google.firebase:firebase-messaging:17.6.0'
    implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"
}

答案 1

为什么会发生这种情况?

因为升级后,在某个地方访问,当你的项目仍然没有使用androidx时。因此,像和许多其他类现在在两个地方找到 - 和.这就是发生此错误的原因。androidx.core:coreINotificationSideChannelandroidx.core:corecom.android.support:support-compat

溶液?

您需要迁移到AndroidX,这应该已经完成。如果您不了解AndroidX。请阅读什么是AndroidX

如何迁移当前项目

在 Android Studio 3.2(2018 年 9 月)中,可以选择将现有项目迁移到 。这会自动折射所有包装。AndroidX

在迁移之前,强烈建议备份项目。

现有项目

  • Android Studio > 重构菜单 > 迁移到 AndroidX...
  • 它将进行分析,并将在底部打开折射率窗口。接受要完成的更改。

image

新建项目

将这些标志放在您的gradle.properties

android.enableJetifier=true
android.useAndroidX=true

检查 @Library 映射是否具有相同的 AndroidX 软件包。

查看@迁移到AndroidX的官方页面


答案 2

您的库(可能在其中一个使用的库中)与库冲突。androidxsupport

将这些行添加到文件中:(它位于项目的根目录中)gradle.properties

android.useAndroidX=true
android.enableJetifier=true

Jetifier 工具将依赖于支持库的库迁移到等效的 AndroidX 包。


推荐