Gradle 在模块类中找到重复的类android.support.v4.app.INotificationSideChannel?

Gradle 在模块类中找到重复的类android.support.v4.app.INotificationSideChannel?,gradle,chat,androidx,Gradle,Chat,Androidx,我正在开发一个新闻应用程序,但我从gradle控制台收到以下错误 (androidx.core:core:1.0.1) 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.1) and c

我正在开发一个新闻应用程序,但我从gradle控制台收到以下错误

(androidx.core:core:1.0.1) 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.1) 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.1) 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.1) 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.1) 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.1) 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.1) 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.1) 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.1) 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.1) 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.1) 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.1) 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.1) 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 class
在我的应用程序下面

apply plugin: 'com.android.application'

android {
    compileSdkVersion 28
    defaultConfig {
        applicationId "com.example.myapplication"
        minSdkVersion 15
        targetSdkVersion 28
        versionCode 1
        versionName "1.0"
        testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
    }
    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
        }
    }
}

dependencies {
    implementation fileTree(dir: 'libs', include: ['*.jar'])
    implementation 'com.android.support:appcompat-v7:28.0.0'
    implementation 'com.android.support.constraint:constraint-layout:1.1.3'
    testImplementation 'junit:junit:4.12'
    androidTestImplementation 'com.android.support.test:runner:1.0.2'
    implementation 'com.github.bassaer:chatmessageview:2.0.1'
    implementation 'com.google.code.gson:gson:2.8.5'
    androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.2'
}

您可以将以下行添加到
gradle.properties
文件中:

android.useAndroidX=true
android.enableJetifier=true

细节: 如果您想在新项目中使用
androidx
-命名空间库,则需要将编译SDK设置为Android 9.0(API级别28)或更高版本,并将上述两个Android Gradle插件标志设置为
true

android.useAndroidX
:当此标志设置为
true
时,android插件使用适当的AndroidX库而不是支持库。如果未指定该标志,则默认情况下该标志为
false


android.enableJetifier
:当此标志设置为
true
时,android插件会通过重写现有的第三方库的二进制文件,自动迁移现有的第三方库以使用AndroidX依赖项。如果未指定该标志,则默认情况下该标志为
false

我遇到了类似的情况,下面是基于我的:

您的项目(或其子项目之一)引用的依赖项末尾使用了加号+,如
com.google.firebase:firebase auth:+
,这意味着尽可能使用更高版本,新版本不再使用android.support库,而是使用androidx;要解决此问题,请执行以下步骤

步骤:
  • 确保设置了
    ANDROID\u HOME
    环境变量,然后打开一个控制台窗口(比如git bash,因为它保存整个命令输出),并将
    cd
    放入项目的
    ANDROID
    目录(对于爱奥尼亚项目,它应该是
    platforms/ANDROID
  • 首先,通过运行以下命令(在git bash中)列出所有依赖项:
  • 将结果复制到您首选的文本编辑器中,然后搜索
    androidx
  • 如果您发现了一些问题,请按照以下步骤操作,否则您就完成了!(无需重复这些步骤)
  • 向上滚动,直到在任何一行的末尾看到->,例如
    16.0.8->19.0.0
    +->19.0.0
    ,这都意味着该版本已自动解析(由于+,因此比您指定的版本更高)
  • 因此,请手动设置版本:
    • 如果可能,请在项目(或子项目)中查找+符号,并将其替换为特定版本
    • 或者,强制使用下面提到的依赖项的特定版本
  • 最后,重复上述步骤(但只需清除控制台上的
    而不是第一步)

  • 强制特定版本的依赖项添加到您的根
    build.gradle
    文件中,请执行以下操作(这对我很有用),但当然要编辑以下内容并添加您自己的规则(因为这些规则可能不适用于您的情况):


    摘自。AndroidX是Android团队用于开发、测试、打包、版本和发布Jetpack中的库的开源项目。

    将这些行添加到gradle.properties文件可解决“重复类”错误:

    但是,这在我的项目中产生了新的错误:

    “程序包android.support.annotation不存在”

    “找不到符号类片段”

    “程序包android.support.v4.content不存在”

    “程序类型已存在”

    等等

    然而,重构对我来说很有效:

    Migrate your project to AndroidX by selecting Refactor > 
    "Migrate to AndroidX" from the menu bar.
    
    Select Build > Clean project
    
    Restore Android Studio
    
    现在,我的项目(Match4app)与AndroidX一起工作,我能够在PlayStore中发布它,没有任何问题


    评论:这项任务还允许我升级依赖AndroidX的所有其他库(即com.firebaseui:firebaseui 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等)。

    如@Ahmed所说,解决方案是实现AndroidX,它适合我。然而,这不是一个简单的方法,它需要一点平静。。。以下是我所做的步骤:

    • 首先,在不同的分支中进行所有这些更改或备份项目是非常重要的

    • 你需要有Android Gradle插件版本3.5.1。因此,在build.gradle集合中:
      依赖项{
      classpath'com.android.tools.build:gradle:3.5.1'
      …

    • 使用Android Studio工具迁移到AndroidX:重构-->迁移到AndroidX
    • 当它完成时,它已经完成了所有有针对性的修改,但可能您无法正确部署项目,因为您发现了任何错误。以下是我发现的问题和解决方案:

    • 如果使用Kotlin,则在build.gradle集中:
      buildscript{
      ext.kotlin_version='1.3.10'
      …
      编译“org.jetbrains.kotlin:kotlin-stdlib-jdk8:$kotlin_version”

    • 如果使用destination方法,请添加“file”参数:
      目标文件(“$reportsDir/checkstyle/checkstyle.xml”)
    • 如果您使用Butterknife,请使用10.0.0版本

    只有当您可以降级到特定版本时,Top Master的答案才有效。在我的情况下,我有一个React本机应用程序,并且我使用的一个库已迁移到AndroidX。以前的版本与iOS有问题,因此我必须使用最新版本。我必须做的是:

  • 将Android项目迁移到AndroidX(重构>迁移到AndroidX)
  • 用于将
    node_模块
    依赖项转换为AndroidX。对于React Native 0.60及以上版本,jetify将自动运行,因此您无需安装此库

  • 我遇到了同样的问题,我就是这样解决的

    展开Graddle脚本,然后转到Graddle.prop
    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'
        }
      }
    }
    
    android.useAndroidX=true
    
    android.enableJetifier=true
    
    Migrate your project to AndroidX by selecting Refactor > 
    "Migrate to AndroidX" from the menu bar.
    
    Select Build > Clean project
    
    Restore Android Studio