Gradle版本冲突求助:Program type already present错误解决咨询
Hey George, this error is a classic case of dependency conflict — your project has multiple versions of the Android Support Library floating around, and the D8 compiler is choking on duplicate class definitions. Let's break down the issues in your setup and fix them step by step:
1. Your explicit Support Library versions don't match
Looking at your app-level build.gradle, you've got:
com.android.support:appcompat-v7:27.1.1com.android.support:design:27.0.2
The Design library includes CoordinatorLayout under the hood, and since it's on an older version than AppCompat, you're ending up with two copies of the CoordinatorLayout$Behavior class — hence the error. All Support Library artifacts must use the exact same version.
2. Firebase dependencies are probably pulling in outdated Support libraries
Most Firebase libraries automatically include Support Library dependencies, and if those versions don't align with your manually declared ones, that's another source of conflict.
Step-by-Step Fixes:
First: Align your explicit Support Library versions
Update your app-level build.gradle dependencies to use the same version for all Support Library entries:
implementation 'com.android.support:appcompat-v7:27.1.1' implementation 'com.android.support:design:27.1.1' // Match AppCompat's version here
Second: Force all dependencies to use your chosen Support Library version
Add this block to your app-level build.gradle right after the android block to override any conflicting versions pulled in by Firebase or other libraries:
configurations.all { resolutionStrategy { force 'com.android.support:support-v4:27.1.1' force 'com.android.support:appcompat-v7:27.1.1' force 'com.android.support:design:27.1.1' } }
Third: Clean and rebuild your project
Head to the Android Studio toolbar and run:
Build > Clean Project- Then
Build > Rebuild Project
This clears out any cached build artifacts that might still hold the old conflicting classes.
Pro Tip to Avoid This in the Future
Define version variables in your project-level build.gradle so you only have to update versions in one place:
buildscript { ext { support_version = '27.1.1' firebase_version = '15.0.2' // Align Firebase versions too for consistency } // Your existing repositories and classpath entries... }
Then reference these variables in your app-level build.gradle:
implementation "com.android.support:appcompat-v7:$support_version" implementation "com.android.support:design:$support_version" implementation "com.google.firebase:firebase-core:$firebase_version" implementation "com.google.firebase:firebase-database:$firebase_version" implementation "com.google.firebase:firebase-messaging:$firebase_version" implementation "com.google.firebase:firebase-auth:$firebase_version"
This keeps everything consistent and makes version updates way easier.
内容的提问来源于stack exchange,提问作者George

