Android Studio集成Firestore与BigQuery时的依赖冲突问题
问题描述
我用Kotlin在Android Studio开发Android应用,后端采用Firestore,已部署“Stream Firestore to BigQuery”扩展,实现数据上传至Firestore时自动同步至BigQuery以支持SQL复杂查询。但添加BigQuery客户端API到build.gradle后,出现重复类的依赖冲突错误,相关配置及错误日志如下,恳请指导解决冲突完成集成。
build.gradle(Project)
buildscript { repositories { mavenCentral() google() } dependencies { classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:1.8.21" classpath 'com.android.tools.build:gradle:8.1.1' classpath 'com.google.gms:google-services:4.3.15' classpath "androidx.navigation:navigation-safe-args-gradle-plugin:2.7.1" } } plugins { id 'com.android.application' version '8.1.1' apply false id 'com.android.library' version '8.1.1' apply false id 'org.jetbrains.kotlin.android' version '1.8.21' apply false id 'com.google.devtools.ksp' version "1.9.0-1.0.11" apply false } tasks.register('clean', Delete) { delete rootProject.buildDir }
build.gradle(Module:app)
plugins { id 'com.android.application' id 'org.jetbrains.kotlin.android' id 'com.google.gms.google-services' id 'androidx.navigation.safeargs.kotlin' id 'kotlin-kapt' id 'com.google.devtools.ksp' id 'kotlin-parcelize' } android { compileSdk 34 defaultConfig { applicationId "jp.ac.shinshu.babatomohiro.sharingtravel" minSdk 27 targetSdk 34 versionCode 1 versionName "1.0" testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner" } buildTypes { release { minifyEnabled false proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro' } } compileOptions { sourceCompatibility JavaVersion.VERSION_18 targetCompatibility JavaVersion.VERSION_18 } kotlinOptions { jvmTarget = '18' } dataBinding { enabled true } namespace 'jp.ac.shinshu.babatomohiro.sharingtravel' } dependencies { implementation 'androidx.core:core-ktx:1.10.1' implementation 'androidx.appcompat:appcompat:1.6.1' implementation 'com.google.android.material:material:1.9.0' implementation 'androidx.constraintlayout:constraintlayout:2.1.4' implementation "androidx.swiperefreshlayout:swiperefreshlayout:1.1.0" //LiveData and ViewModel dependency implementation 'androidx.lifecycle:lifecycle-livedata-ktx:2.6.1' implementation 'androidx.lifecycle:lifecycle-viewmodel-ktx:2.6.1' //Navigation dependency implementation 'androidx.navigation:navigation-fragment-ktx:2.7.1' implementation 'androidx.navigation:navigation-ui-ktx:2.7.1' //Firebase dependency implementation platform('com.google.firebase:firebase-bom:32.2.2') implementation 'com.google.firebase:firebase-analytics-ktx:21.3.0' implementation 'com.google.firebase:firebase-auth-ktx:22.1.1' implementation 'com.google.firebase:firebase-firestore-ktx:24.7.1' implementation 'com.google.firebase:firebase-storage-ktx:20.2.1' implementation 'com.google.firebase:firebase-messaging-ktx:23.2.1' implementation 'com.google.firebase:firebase-analytics-ktx:21.3.0' implementation 'com.github.CanHub:Android-Image-Cropper:4.3.0' //Glide dependency implementation 'com.github.bumptech.glide:glide:4.16.0' implementation 'com.google.code.gson:gson:2.10.1' implementation 'com.github.krokyze:ucropnedit:2.2.8' implementation 'id.zelory:compressor:3.0.1' implementation 'com.googlecode.mp4parser:isoparser:1.1.22' implementation 'com.iceteck.silicompressorr:silicompressor:2.2.4' implementation "org.jetbrains.kotlinx:kotlinx-coroutines-core:1.7.3" implementation "org.jetbrains.kotlinx:kotlinx-coroutines-android:1.7.3" implementation 'androidx.camera:camera-core:1.2.3' implementation 'androidx.camera:camera-camera2:1.2.3' implementation 'androidx.camera:camera-lifecycle:1.2.3' implementation 'androidx.camera:camera-video:1.2.3' implementation 'androidx.camera:camera-view:1.2.3' implementation 'androidx.camera:camera-extensions:1.2.3' implementation 'com.google.android.exoplayer:exoplayer:2.19.1' implementation 'com.google.android.exoplayer:exoplayer-core:2.19.1' implementation 'com.google.android.exoplayer:exoplayer-dash:2.19.1' implementation 'com.google.android.exoplayer:exoplayer-ui:2.19.1' implementation 'com.google.guava:guava:32.1.2-jre' implementation "androidx.room:room-runtime:2.5.2" ksp "androidx.room:room-compiler:2.5.2" implementation "androidx.room:room-ktx:2.5.2" implementation 'com.google.android.gms:play-services-maps:18.1.0' implementation 'com.google.android.gms:play-services-location:21.0.1' implementation 'com.google.android.libraries.places:places:3.2.0' implementation 'com.github.MikeOrtiz:TouchImageView:3.2.1' implementation 'io.github.nikartm:image-support:2.0.0' implementation 'com.googlecode.libphonenumber:libphonenumber:8.13.19' implementation 'com.github.shuhart:stepview:1.5.1' implementation 'me.relex:circleindicator:2.1.6' implementation 'com.stripe:stripe-android:20.28.3' //Bigquery API implementation platform('com.google.cloud:libraries-bom:26.22.0') implementation 'com.google.cloud:google-cloud-bigquery' testImplementation 'junit:junit:4.13.2' androidTestImplementation 'androidx.test.ext:junit:1.1.5' androidTestImplementation 'androidx.test.espresso:espresso-core:3.5.1' }
Build Output
FAILURE: Build completed with 2 failures. 1: Task failed with an exception. ----------- * What went wrong: Execution failed for task ':app:checkDebugDuplicateClasses'. > A failure occurred while executing com.android.build.gradle.internal.tasks.CheckDuplicatesRunnable > Duplicate class com.google.api.Advice found in modules proto-google-common-protos-2.23.0 (com.google.api.grpc:proto-google-common-protos:2.23.0) and protolite-well-known-types-18.0.0-runtime (com.google.firebase:protolite-well-known-types:18.0.0) Duplicate class com.google.api.MonitoredResourceProto found in modules proto-google-common-protos-2.23.0 (com.google.api.grpc:proto-google-common-protos:2.23.0) and protolite-well-known-types-18.0.0-runtime (com.google.firebase:protolite-well-known-types:18.0.0) Duplicate class com.google.api.Monitoring found in modules proto-google-common-protos-2.23.0 (com.google.api.grpc:proto-google-common-protos:2.23.0) and protolite-well-known-types-18.0.0-runtime (com.google.firebase:protolite-well-known-types:18.0.0) Duplicate class com.google.api.Monitoring$1 found in modules proto-google-common-protos-2.23.0 (com.google.api.grpc:proto-google-common-protos:2.23.0) and protolite-well-known-types-18.0.0-runtime (com.google.firebase:protolite-well-known-types:18.0.0) Duplicate class com.google.api.Monitoring$Builder found in modules proto-google-common-protos-2.23.0 (com.google.api.grpc:proto-google-common-protos:2.23.0) and protolite-well-known-types-18.0.0-runtime (com.google.firebase:protolite-well-known-types:18.0.0) Duplicate class com.google.protobuf.DescriptorProtos$ExtensionRangeOptionsOrBuilder found in modules protobuf-java-3.23.2 (com.google.protobuf:protobuf-java:3.23.2) and protolite-well-known-types-18.0.0-runtime (com.google.firebase:protolite-well-known-types:18.0.0) Duplicate class com.google.protobuf.DescriptorProtos$FieldDescriptorProto found in modules protobuf-java-3.23.2 (com.google.protobuf:protobuf-java:3.23.2) and protolite-well-known-types-18.0.0-runtime (com.google.firebase:protolite-well-known-types:18.0.0) Duplicate class com.google.protobuf.DescriptorProtos$FieldDescriptorProto$Builder found in modules protobuf-java-3.23.2 (com.google.protobuf:protobuf-java:3.23.2) and protolite-well-known-types-18.0.0-runtime (com.google.firebase:protolite-well-known-types:18.0.0) Duplicate class com.google.protobuf.DescriptorProtos$FieldDescriptorProto$Label found in modules protobuf-java-3.23.2 (com.google.protobuf:protobuf-java:3.23.2) and protolite-well-known-types-18.0.0-runtime (com.google.firebase:protolite-well-known-types:18.0.0) ................ omitted..................... Duplicate class com.google.type.TimeZone$1 found in modules proto-google-common-protos-2.23.0 (com.google.api.grpc:proto-google-common-protos:2.23.0) and protolite-well-known-types-18.0.0-runtime (com.google.firebase:protolite-well-known-types:18.0.0) Duplicate class com.google.type.TimeZone$Builder found in modules proto-google-common-protos-2.23.0 (com.google.api.grpc:proto-google-common-protos:2.23.0) and protolite-well-known-types-18.0.0-runtime (com.google.firebase:protolite-well-known-types:18.0.0) Duplicate class com.google.type.TimeZoneOrBuilder found in modules proto-google-common-protos-2.23.0 (com.google.api.grpc:proto-google-common-protos:2.23.0) and protolite-well-known-types-18.0.0-runtime (com.google.firebase:protolite-well-known-types:18.0.0) Go to the documentation to learn how to Fix dependency resolution errors.
解决方案
冲突根源是BigQuery客户端依赖自带的proto-google-common-protos和protobuf-java模块,与Firebase的protolite-well-known-types库存在重复的Protobuf相关类。只需修改Module:app中的BigQuery依赖,排除冲突模块即可:
替换原BigQuery依赖为以下代码:
//Bigquery API implementation platform('com.google.cloud:libraries-bom:26.22.0') implementation('com.google.cloud:google-cloud-bigquery') { exclude group: 'com.google.api.grpc', module: 'proto-google-common-protos' exclude group: 'com.google.protobuf', module: 'protobuf-java' }
这样配置后,Gradle会复用Firebase提供的Protolite版本类,同时保留BigQuery客户端的核心功能,解决重复类冲突。
内容的提问来源于stack exchange,提问作者Tomotomo
相关产品推荐
相关产品推荐

