这些是我在构建应用程序时在Logcat中的错误.我正在将这个应用程序从一个Firebase帐户转移到另一个帐户.但依赖关系正在抛出这样的错误. 如何清除这些错误?应用程序不是在构建,而是在应用程序构建过程中出现错误:

    Duplicate class com.google.firebase.auth.ktx.AuthKt found in modules jetified-              
    firebase-auth-22.3.0-runtime (com.google.firebase:firebase-auth:22.3.0) and 
    jetified-firebase-auth-ktx-21.1.0-runtime (com.google.firebase:firebase-auth- 
    ktx:21.1.0)
    Duplicate class com.google.firebase.database.ktx.ChildEvent found in modules 
    jetified-firebase-database-20.3.0-runtime (com.google.firebase:firebase- 
    database:20.3.0) and jetified-firebase-database-ktx-20.1.0-runtime 
    (com.google.firebase:firebase-database-ktx:20.1.0)
    Duplicate class com.google.firebase.database.ktx.ChildEvent$Added found in modules 
    jetified-firebase-database-20.3.0-runtime (com.google.firebase:firebase- 
    database:20.3.0) and jetified-firebase-database-ktx-20.1.0-runtime 
    (com.google.firebase:firebase-database-ktx:20.1.0)
    Duplicate class com.google.firebase.database.ktx.ChildEvent$Changed found in modules 
    jetified-firebase-database-20.3.0-runtime (com.google.firebase:firebase- 
    database:20.3.0) and jetified-firebase-database-ktx-20.1.0-runtime 
    (com.google.firebase:firebase-database-ktx:20.1.0)
    Duplicate class com.google.firebase.database.ktx.ChildEvent$Moved found in modules 
    jetified-firebase-database-20.3.0-runtime (com.google.firebase:firebase- 
    database:20.3.0) and jetified-firebase-database-ktx-20.1.0-runtime 
    (com.google.firebase:firebase-database-ktx:20.1.0)
    Duplicate class com.google.firebase.database.ktx.ChildEvent$Removed found in modules 
    jetified-firebase-database-20.3.0-runtime (com.google.firebase:firebase- 
    database:20.3.0) and jetified-firebase-database-ktx-20.1.0-runtime 
    (com.google.firebase:firebase-database-ktx:20.1.0)
    Duplicate class com.google.firebase.database.ktx.DatabaseKt found in modules 
    jetified-firebase-database-20.3.0-runtime (com.google.firebase:firebase- 
    database:20.3.0) and jetified-firebase-database-ktx-20.1.0-runtime 
    (com.google.firebase:firebase-database-ktx:20.1.0)
    Duplicate class com.google.firebase.database.ktx.DatabaseKt$childEvents$1 found in 
    modules jetified-firebase-database-20.3.0-runtime (com.google.firebase:firebase- 
    database:20.3.0) and jetified-firebase-database-ktx-20.1.0-runtime 
    (com.google.firebase:firebase-database-ktx:20.1.0)
    Duplicate class com.google.firebase.database.ktx.DatabaseKt$childEvents$1$1 found in 
    modules jetified-firebase-database-20.3.0-runtime (com.google.firebase:firebase- 
    database:20.3.0) and jetified-firebase-database-ktx-20.1.0-runtime 
    (com.google.firebase:firebase-database-ktx:20.1.0)
    Duplicate class com.google.firebase.database.ktx.DatabaseKt$childEvents$1$listener$1 
    found in modules jetified-firebase-database-20.3.0-runtime 
    (com.google.firebase:firebase-database:20.3.0) and jetified-firebase-database-ktx- 
    20.1.0-runtime (com.google.firebase:firebase-database-ktx:20.1.0)
    Duplicate class com.google.firebase.database.ktx.DatabaseKt$getValue$1 found in 
    modules jetified-firebase-database-20.3.0-runtime (com.google.firebase:firebase- 
    database:20.3.0) and jetified-firebase-database-ktx-20.1.0-runtime 
    (com.google.firebase:firebase-database-ktx:20.1.0)
    Duplicate class com.google.firebase.database.ktx.DatabaseKt$getValue$2 found in 
    modules jetified-firebase-database-20.3.0-runtime (com.google.firebase:firebase- 
    database:20.3.0) and jetified-firebase-database-ktx-20.1.0-runtime 
    (com.google.firebase:firebase-database-ktx:20.1.0)
    Duplicate class com.google.firebase.database.ktx.DatabaseKt$snapshots$1 found in 
    modules jetified-firebase-database-20.3.0-runtime (com.google.firebase:firebase- 
    database:20.3.0) and jetified-firebase-database-ktx-20.1.0-runtime 
    (com.google.firebase:firebase-database-ktx:20.1.0)
    Duplicate class com.google.firebase.database.ktx.DatabaseKt$snapshots$1$1 found in 
    modules jetified-firebase-database-20.3.0-runtime (com.google.firebase:firebase- 
    database:20.3.0) and jetified-firebase-database-ktx-20.1.0-runtime 
    (com.google.firebase:firebase-database-ktx:20.1.0)
    Duplicate class com.google.firebase.database.ktx.DatabaseKt$snapshots$1$listener$1 
    found in modules jetified-firebase-database-20.3.0-runtime 
    (com.google.firebase:firebase-database:20.3.0) and jetified-firebase-database-ktx- 
    20.1.0-runtime (com.google.firebase:firebase-database-ktx:20.1.0)
    Duplicate class com.google.firebase.database.ktx.FirebaseDatabaseKtxRegistrar found 
    in modules jetified-firebase-database-20.3.0-runtime (com.google.firebase:firebase- 
    database:20.3.0) and jetified-firebase-database-ktx-20.1.0-runtime 
    (com.google.firebase:firebase-database-ktx:20.1.0)

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

我的build.gradle代码是:

plugins {
id 'com.android.application'
id 'kotlin-android'
id 'com.google.gms.google-services'
}

android {
compileSdk 34

defaultConfig {
    applicationId "com.socialtap.app"
    minSdk 24
    targetSdk 33
    versionCode 3
    versionName "1.3"
    multiDexEnabled = true
    testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
    signingConfig signingConfigs.debug
}
buildTypes {
    release {
        minifyEnabled false
        proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 
        'proguard-rules.pro'
    }
}
compileOptions {
    sourceCompatibility JavaVersion.VERSION_1_8
    targetCompatibility JavaVersion.VERSION_1_8
}
kotlinOptions {
    jvmTarget = '1.8'
}
buildFeatures {
    viewBinding true
}
namespace 'com.socialtap.app'

}

dependencies {

implementation 'androidx.core:core-ktx:1.12.0'
implementation 'androidx.appcompat:appcompat:1.6.1'
implementation 'com.google.android.material:material:1.11.0'
implementation 'androidx.constraintlayout:constraintlayout:2.1.4'
implementation 'androidx.navigation:navigation-fragment-ktx:2.7.6'
implementation 'androidx.navigation:navigation-ui-ktx:2.7.6'
implementation 'androidx.legacy:legacy-support-v4:1.0.0'

// Firebase
implementation platform('com.google.firebase:firebase-bom:31.0.1')
implementation 'com.google.firebase:firebase-analytics-ktx'
implementation 'com.google.firebase:firebase-auth-ktx'
implementation 'com.google.firebase:firebase-database-ktx'
implementation 'com.google.firebase:firebase-messaging-ktx'
implementation 'com.google.firebase:firebase-storage-ktx'

//declare the dependency for the Google Play services library and specify its version
implementation 'com.google.android.gms:play-services-auth:20.7.0'

//multiDex
implementation 'androidx.multidex:multidex:2.0.1'

// image
implementation "com.github.bumptech.glide:glide:4.13.2"

//MaterialSpinner
implementation 'com.jaredrummler:material-spinner:1.3.1'

//sdp
implementation 'com.intuit.sdp:sdp-android:1.1.0'

//TedImagePicker
implementation 'com.github.dhaval2404:imagepicker:2.1'

//Coroutines
implementation 'org.jetbrains.kotlinx:kotlinx-coroutines-core:1.6.4'
implementation 'org.jetbrains.kotlinx:kotlinx-coroutines-android:1.6.4'
implementation 'org.jetbrains.kotlinx:kotlinx-coroutines-play-services:1.6.4'

//CircleImageView
implementation 'de.hdodenhof:circleimageview:3.1.0'

//Loader
implementation 'com.github.ybq:Android-SpinKit:1.4.0'

//Retrofit and GSON
implementation 'com.squareup.retrofit2:retrofit:2.9.0'
implementation 'com.squareup.retrofit2:converter-gson:2.9.0'
implementation 'com.squareup.okhttp3:logging-interceptor:5.0.0-alpha.3'
implementation 'com.squareup.okhttp3:okhttp:5.0.0-alpha.3'

//ImageCompressor
implementation 'id.zelory:compressor:3.0.1'

//NFC
implementation 'com.google.guava:guava:31.0.1-jre'

//QRCode
implementation 'com.google.zxing:core:3.5.1'

//Facebook Login
implementation 'com.facebook.android:facebook-login:14.1.1'

//Zoomable Image
implementation 'com.jsibbold:zoomage:1.3.1'
implementation 'androidx.test.ext:junit-ktx:1.1.5'
implementation 'androidx.test:monitor:1.6.1'
implementation 'com.google.firebase:firebase-auth:22.3.0'
implementation 'com.google.firebase:firebase-database:20.3.0'
testImplementation 'junit:junit:4.13.2'

//QRCodeScanner
implementation 'com.github.yuriy-budiyev:code-scanner:2.3.2'
implementation 'com.github.kenglxn.QRGen:android:3.0.1'

//Permissions
implementation 'com.karumi:dexter:6.2.3'

}

另一个gradle文件:

// Top-level build file where you can add configuration options common to all sub- 
projects/modules.
buildscript {
  repositories {
    google()
    mavenCentral()
}
dependencies {
    classpath 'com.android.tools.build:gradle:8.2.1'
    classpath 'org.jetbrains.kotlin:kotlin-gradle-plugin:1.8.0'
    classpath 'com.google.gms:google-services:4.4.0'
  }
}

allprojects {
  repositories {
    google()
    mavenCentral()
    maven { url "https://jitpack.io" }
   }
}


task clean(type: Delete) {
  delete rootProject.buildDir
}

推荐答案

代码中与重复类相关的问题是因为您有重复的依赖项:

// Firebase
implementation platform('com.google.firebase:firebase-bom:31.0.1')
implementation 'com.google.firebase:firebase-analytics-ktx'
implementation 'com.google.firebase:firebase-auth-ktx'
implementation 'com.google.firebase:firebase-database-ktx'
implementation 'com.google.firebase:firebase-messaging-ktx'
implementation 'com.google.firebase:firebase-storage-ktx'

implementation 'com.google.firebase:firebase-auth:22.3.0'
implementation 'com.google.firebase:firebase-database:20.3.0'

当你使用BOM表时,不需要为你的依赖项指定版本.因此,您将BOM提供的版本与手动添加的版本混合在一起,因此出现了错误.要解决这个问题,只需删除以下代码行并再次同步项目.

//implementation 'com.google.firebase:firebase-auth:22.3.0' //👈
//implementation 'com.google.firebase:firebase-database:20.3.0' //👈

Android相关问答推荐

listOf(listOf(字符串))在lazyArchitect(lazyStream)中合成

Jetpack编写:通过viewModels()vs viewModel View ModernName()'

Jetpack Compose中的导航找不到NavHost类的名称为:startDestination";的参数

这款应用与最新版本的Android不兼容.在Android 14中

try 用Jetpack Compose理解视图模型和导航

MAP函数返回单位列表而不是字符列表

在一列中垂直对齐两个框

Android 中 recyclerview 的自定义分隔线 colored颜色 不起作用

我的自定义小吃店不适合我的全宽屏幕尺寸

未找到 com.android.tools.build:gradle:7.4.0 的匹配变体

如何使用 Jetpack Compose 制作两个圆圈

在 Jetpack Compose 中清除列表时可组合不重组

验证硬编码密码

Jetpack compose 未解决的参考错误

如何使用 ConstraintLayout 链接两个文本

无法使用 Gradle 托管设备对基线配置文件运行测试

react-native-config 在发布版本中不起作用

基线配置文件 x R8/Proguard

Google Play 服务登录在 Unity Android 上无法正常运行

无法再查看 Jetpack Compose 预览.无法实例化一个或多个类 (ComposeViewAdapter)