Android Google Services插件版本冲突求助:AS3.1升级后配置异常
Hey there, let's work through this frustrating problem step by step—version conflicts and auto-reverting configs are the worst, but we'll get it sorted.
1. Understand the Core Compatibility Rule First
That Version Conflict message you're seeing is rooted in a mismatch between your Android Gradle Plugin and google-services plugin. Here's the key rule to follow:
- Android Gradle Plugin 3.1.x (like the 3.1.1 you're trying to use) requires a google-services plugin version of 3.2.x or higher (e.g., 3.2.1, 3.3.0). If your google-services version is too old, it not only triggers the conflict but can even force your Android plugin version to revert automatically—super annoying, right?
2. Update Your Root build.gradle Config
This is the most critical fix—most auto-revert issues happen because this file isn't properly updated:
Open your project's root build.gradle file and adjust the dependencies block:
buildscript { repositories { google() // Make sure this is included (replaces the old maven.google.com URL) jcenter() } dependencies { // Set Android Gradle Plugin to 3.1.1 classpath 'com.android.tools.build:gradle:3.1.1' // Upgrade google-services to a compatible version (3.2.1 works perfectly here) classpath 'com.google.gms:google-services:3.2.1' } }
Also, double-check your gradle/wrapper/gradle-wrapper.properties to confirm Gradle version 4.4 is set (it's fully compatible with plugin 3.1.1):
distributionUrl=https\://services.gradle.org/distributions/gradle-4.4-all.zip
3. Stop the Auto-Revert Behavior
If changing the plugin version still gets reverted, try these quick fixes:
- Clear Android Studio Cache: Go to
File > Invalidate Caches / Restartand selectInvalidate and Restart. Caches often hold onto old configs and cause weird behavior like this. - Check Submodule Configs: If your project has multiple modules, make sure none of the submodule
build.gradlefiles are hardcoding the old plugin version, or overriding the root config via shared variables. - Turn Off Offline Mode: If you have Gradle offline mode enabled (
File > Settings > Build, Execution, Deployment > Gradle > Offline work), disable it. Offline mode can prevent Gradle from downloading the new plugin versions, leading to auto-reverts.
4. Sync and Verify
After making all these changes, click the Sync Project with Gradle Files button (the refresh icon in the top-right corner of Android Studio). Wait for the sync to finish—if you still see errors, check the full Build log for specific hints (it usually tells you exactly which google-services version you need to use).
内容的提问来源于stack exchange,提问作者jobin

