Android项目依赖报错:无法匹配com.google.firebase:firebase-sessions指定版本
Firebase Crashlytics依赖冲突:找不到firebase-sessions匹配版本
今日在Android项目中使用Firebase和OneSignal实现通知功能时突然出现如下错误:
Could not find any version that matches com.google.firebase:firebase-sessions:[15.0.0, 16.0.0). Versions that do not match: - 1.2.4 - 1.2.3 - 1.2.2 - 1.2.1 - 1.2.0 - + 4 more Required by: project :app > com.google.firebase:firebase-crashlytics:18.6.4
已尝试更换Firebase BOM至最新版本,但问题仍未解决,以下是项目的app/build.gradle依赖配置:
dependencies { constraints { implementation("org.jetbrains.kotlin:kotlin-stdlib-jdk7:1.8.0") { because("kotlin-stdlib-jdk7 is now a part of kotlin-stdlib") } implementation("org.jetbrains.kotlin:kotlin-stdlib-jdk8:1.8.0") { because("kotlin-stdlib-jdk8 is now a part of kotlin-stdlib") } } implementation fileTree(dir: "libs", include: ["*.jar"]) implementation 'androidx.appcompat:appcompat:1.2.0' implementation 'androidx.constraintlayout:constraintlayout:2.0.4' implementation 'androidx.legacy:legacy-support-v4:1.0.0' implementation 'androidx.navigation:navigation-fragment:2.3.2' implementation 'androidx.navigation:navigation-ui:2.3.2' implementation 'androidx.lifecycle:lifecycle-livedata-ktx:2.5.1' implementation 'androidx.lifecycle:lifecycle-viewmodel-ktx:2.5.1' implementation 'com.android.support:appcompat-v7:28.0.0' implementation 'com.android.support.constraint:constraint-layout:2.0.4' testImplementation 'junit:junit:4.13.2' androidTestImplementation 'androidx.test.ext:junit:1.1.3' androidTestImplementation 'androidx.test.espresso:espresso-core:3.3.0' implementation 'androidx.cardview:cardview:1.0.0' implementation "com.airbnb.android:lottie:3.5.0" implementation 'me.zhanghai.android.materialratingbar:library:1.4.0' // material //noinspection GradleDependency implementation 'com.google.android.material:material:1.0.0' // location 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.1.0' /*circular imageView */ implementation 'de.hdodenhof:circleimageview:3.0.1' /*country code lib*/ implementation 'com.hbb20:ccp:2.4.2' /*circular viewpager indicator*/ implementation 'com.romandanylyk:pageindicatorview:1.0.0' implementation 'com.makeramen:roundedimageview:2.3.0' /*expandable recyclerview*/ implementation 'com.thoughtbot:expandablerecyclerview:1.3' /*permissions handling lib*/ implementation 'gun0912.ted:tedpermission:2.2.0' /* image loading lib*/ implementation 'com.github.bumptech.glide:glide:4.11.0' /*for network call*/ implementation 'com.squareup.retrofit2:retrofit:2.9.0' implementation 'com.squareup.retrofit2:converter-gson:2.9.0' implementation 'com.squareup.retrofit2:adapter-rxjava:2.5.0' implementation 'com.github.Quendel:Multiutils:2.0' implementation 'com.jaredrummler:material-spinner:1.3.1' // Firebase implementation platform('com.google.firebase:firebase-bom:32.8.1') implementation 'com.google.firebase:firebase-analytics' implementation 'com.google.firebase:firebase-crashlytics' implementation 'com.google.firebase:firebase-messaging' implementation 'com.google.firebase:firebase-database' implementation 'com.google.android.gms:play-services-basement:18.1.0' //lifecycle implementation "android.arch.lifecycle:extensions:1.1.1" implementation "androidx.lifecycle:lifecycle-common-java8:2.6.1" // Room Database def room_version = "2.5.1" implementation "androidx.room:room-runtime:$room_version" annotationProcessor "androidx.room:room-compiler:$room_version" testImplementation "androidx.room:room-testing:$room_version" // OneSignal implementation 'com.onesignal:OneSignal:[5.0.0, 5.99.99]' // spin kit (dialog) implementation 'com.github.ybq:Android-SpinKit:1.4.0' // crop picture implementation 'com.github.yalantis:ucrop:2.2.6' implementation 'androidx.work:work-runtime:2.8.1' implementation "androidx.browser:browser:1.5.0" }
解决方案
1. 强制指定firebase-sessions版本
在dependencies的constraints块中添加强制约束,使用错误提示中显示的可用版本(比如最新的1.2.4):
constraints { // 保留原有约束... implementation("com.google.firebase:firebase-sessions:1.2.4") { because("Resolve version conflict with Crashlytics") } }
2. 锁定OneSignal具体版本
避免使用版本范围,指定OneSignal的稳定版本(比如5.1.5),减少依赖冲突概率:
implementation 'com.onesignal:OneSignal:5.1.5'
3. 移除重复的Support/AndroidX库
项目中同时存在androidx.appcompat:appcompat和com.android.support:appcompat-v7,这会引发兼容性问题,建议移除com.android.support:appcompat-v7:28.0.0,统一使用AndroidX库。
4. 清理Gradle缓存并同步
- 在Android Studio中执行:
File > Invalidate Caches... > Invalidate and Restart - 或终端运行命令:
./gradlew clean build --refresh-dependencies
内容的提问来源于stack exchange,提问作者Saad
相关产品推荐
相关产品推荐

