集成Firebase后出现variant.getMergeResources()废弃API警告求助
Hey, let's figure out how to fix that annoying Gradle warning you're seeing! That "variant.getMergeResources() is obsolete" message is almost always coming from an outdated third-party plugin, not your own code. Let's break down the solutions step by step:
First, let's recap your setup to make sure we're on the same page:
- You're using Android Gradle Plugin (AGP) 3.4.1
- Your
google-servicesplugin version is 4.3.0 - You've added Firebase Core (17.0.0) and Auth (18.0.0) dependencies
1. Upgrade the google-services Plugin First
The most likely culprit here is your old google-services version (4.3.0 is from 2019). This version still uses the deprecated variant.getMergeResources() API under the hood. Let's upgrade it to a version compatible with AGP 3.4.1:
Update your root build.gradle file's classpath section:
buildscript { ext { firebaseCoreVersion='17.0.0' firebaseAuthVersion='18.0.0' } dependencies { classpath 'com.android.tools.build:gradle:3.4.1' // Upgrade to a newer compatible version, e.g., 4.3.10 classpath 'com.google.gms:google-services:4.3.10' } }
After updating, sync your project—this should resolve the warning in most cases.
2. Check Other Third-Party Plugins (If the Warning Persists)
If the warning doesn't go away, take a look at any other plugins you're using (like resource compressors, flavor managers, or analytics tools). Older plugins often rely on deprecated Gradle APIs. Try disabling them one by one to pinpoint which one is causing the issue, then upgrade that plugin to its latest stable version.
3. Consider Upgrading Android Gradle Plugin (Optional)
If your project allows for it, upgrading AGP to a newer stable version (like 3.5.4, the final release of the 3.5 series) will also fix this problem. Newer AGP versions replace the deprecated APIs entirely, and they play nicer with modern Firebase plugins. Just remember to update your Gradle wrapper version too:
- Update AGP in root
build.gradle:
classpath 'com.android.tools.build:gradle:3.5.4'
- Update Gradle wrapper in
gradle/wrapper/gradle-wrapper.properties:
distributionUrl=https\://services.gradle.org/distributions/gradle-5.4.1-all.zip
A Quick Note on android.debug.obsoleteApi=true
That flag does print detailed stack traces, but since the warning comes from a plugin (not your code), the stack will point to the plugin's internal classes. For example, if you see references to com.google.gms.googleservices in the trace, that confirms the google-services plugin is the issue—so upgrading it is the fix.
内容的提问来源于stack exchange,提问作者G. Ciardini

