Android Studio 3.1.1报错:Program type already present: com.google.android.gms.common.internal.zze
Hey there, I’ve dealt with this exact error a few times when working with Google Play Services and Firebase dependencies, so let me break down what’s going on and how to fix it.
What’s causing this error?
This error boils down to a dependency conflict. Your project has multiple versions of Google Play Services (or Firebase) libraries that all include the com.google.android.gms.common.internal.zze class. The D8 compiler throws this error when it encounters duplicate class definitions across your dependencies.
Step-by-step fixes
统一所有Google Play Services/Firebase依赖版本
The most common fix is making sure all your Google Play Services and Firebase dependencies use the same version. Here’s how:- Open your project-level
build.gradlefile, and add a version variable in thebuildscriptblock:buildscript { ext { googleServicesVersion = "12.0.1" // Use a stable version compatible with your project } // ... other existing configuration } - In your module-level
build.gradlefile, replace hardcoded versions with this variable for all GMS/Firebase dependencies:implementation "com.google.android.gms:play-services-location:$googleServicesVersion" implementation "com.google.firebase:firebase-database:$googleServicesVersion"
This ensures no mismatched versions are pulling in duplicate classes.
- Open your project-level
Identify and exclude duplicate dependencies
If you’re not sure which library is causing the conflict, run this Gradle command in your terminal to analyze dependencies:./gradlew app:dependenciesLook for entries under
com.google.android.gmswith different versions. Once you find the culprit, exclude the conflicting group from that dependency:implementation('third-party-library:some-lib:1.0.0') { exclude group: 'com.google.android.gms' }Update the Google Services plugin
Make sure the Google Services plugin version in your project-levelbuild.gradlematches your GMS dependency version. For example:buildscript { dependencies { classpath "com.google.gms:google-services:4.0.1" // Match this to your GMS version } }Outdated plugins often cause version mismatch issues that lead to duplicate class errors.
Clean and rebuild your project
After making these changes, clear your project’s build cache and rebuild:- Go to
Build > Clean Projectin the Android Studio menu - Then run
Build > Rebuild Project
This ensures no cached old dependencies are causing lingering issues.
- Go to
A quick note
Android Studio 3.1.1 is a bit outdated, so if you can, consider upgrading to a more recent stable version—it’ll have better dependency resolution and fewer bugs. But if you’re stuck on 3.1.1, the steps above should still resolve the error.
内容的提问来源于stack exchange,提问作者Jaymin Bhadani

