迁移至新版Places SDK客户端引发依赖版本冲突错误
Hey there, let's break down this frustrating dependency conflict you've been stuck on for 2 days. The core issue here is a version mismatch between your old Google Play Services/Firebase dependencies (11.2.0) and the newer Google Places library (1.0.0).
The Places library requires modern versions of foundational Play Services components (like play-services-basement:16.2.0), but your project's older dependencies are forcing an exact version of 11.2.0 for those same components. Gradle can't resolve this conflict, hence the error.
Here's how to fix this properly (no quick hacks like disabling version checks—those just hide the problem):
Step 1: Ditch the Full Play Services Dependency
First, delete this line from your app-level build.gradle:
implementation 'com.google.android.gms:play-services:11.2.0'
This full dependency pulls in every Play Services module you don't need, and it's a major source of version conflicts. You already have specific modules like play-services-location included, so we'll keep those and update their versions.
Step 2: Use Google's BOM to Auto-Manage Versions
Google provides a Bill of Materials (BOM) that automatically syncs all Play Services and Firebase dependencies to compatible versions. This eliminates the need to manually match version numbers for every Google library.
Add this line at the TOP of your dependencies block in app-level build.gradle:
implementation platform('com.google.firebase:firebase-bom:28.4.2')
(You can use the latest BOM version if you want—this one is a stable, widely compatible release.)
Step 3: Update All Google Service Dependencies
Remove the hardcoded version numbers from all your Play Services and Firebase dependencies. The BOM will handle setting the correct, compatible version for each one:
- Change
implementation 'com.google.android.gms:play-services-location:11.2.0'toimplementation 'com.google.android.gms:play-services-location' - Change
implementation 'com.google.firebase:firebase-core:11.2.0'toimplementation 'com.google.firebase:firebase-core' - Change
implementation 'com.google.firebase:firebase-messaging:11.2.0'toimplementation 'com.google.firebase:firebase-messaging' - Keep
implementation 'com.google.android.libraries.places:places:1.0.0'(you can remove the version here too if you want the BOM to manage it, but 1.0.0 is a stable, reliable release)
Step 4: Sync Your Support Libraries (Optional but Recommended)
Your project uses Support Library version 27.1.1, which is a bit old. To avoid potential compatibility issues with the updated Play Services, consider upgrading to the final stable Support Library version (28.0.0) or migrating to AndroidX (if your project allows). For example:
implementation 'com.android.support:appcompat-v7:28.0.0' implementation 'com.android.support:recyclerview-v7:28.0.0' // Update all other support library dependencies to 28.0.0 as well
Step 5: Clean and Rebuild
Finally, clear your build cache and rebuild to make sure all changes take effect:
- Go to
File > Invalidate Caches / Restartin Android Studio - Run
./gradlew clean buildfrom the command line (or use the "Clean Project" and "Rebuild Project" options in Android Studio)
Example Adjusted app-level build.gradle Dependencies
Here's a snippet of what your updated dependencies block should look like:
dependencies { implementation fileTree(dir: 'libs', include: ['*.jar']) implementation project(path: ':calendar') implementation project(path: ':filepicker') // Google BOM to manage service versions implementation platform('com.google.firebase:firebase-bom:28.4.2') // Updated Support Libraries implementation 'com.android.support:appcompat-v7:28.0.0' implementation 'com.android.support:recyclerview-v7:28.0.0' implementation 'com.android.support:animated-vector-drawable:28.0.0' implementation 'com.android.support:mediarouter-v7:28.0.0' implementation 'com.android.support.constraint:constraint-layout:1.1.0' implementation 'com.android.support:support-v4:28.0.0' implementation 'com.android.support:design:28.0.0' implementation 'com.android.support:multidex:1.0.3' implementation 'com.android.support:cardview-v7:28.0.0' // Third-party dependencies (keep as-is unless you need updates) implementation 'com.intuit.sdp:sdp-android:1.0.5' implementation 'com.jakewharton:butterknife:8.8.1' annotationProcessor 'com.jakewharton:butterknife-compiler:8.8.1' implementation 'de.hdodenhof:circleimageview:2.2.0' // Google Services (version managed by BOM) implementation 'com.google.android.gms:play-services-location' implementation 'com.google.android.libraries.places:places:1.0.0' // Firebase Services (version managed by BOM) implementation 'com.google.firebase:firebase-core' implementation 'com.google.firebase:firebase-messaging' implementation 'com.firebase:firebase-client-android:2.5.1' // Rest of your third-party dependencies... } apply plugin: 'com.google.gms.google-services'
Important Note
Avoid using googleServices { disableVersionCheck = false }—this just suppresses the error but will lead to unpredictable crashes at runtime. The steps above fix the root cause of the conflict.
内容的提问来源于stack exchange,提问作者priyanka kataria

