升级Android Studio后编译报错:Program type already present: android.support.v4.app.BackStackRecord$Op
Hey there, I’ve dealt with this exact error countless times after AS updates—total headache, right? Let’s break down the fixes step by step, since this is almost always caused by conflicting or duplicate support library dependencies.
1. Check for AndroidX vs. Support Library Mixup
First off, Android Studio updates often push toward AndroidX, and mixing old com.android.support libraries with AndroidX will trigger this error immediately.
- Open your project’s
gradle.propertiesfile and look for these lines:
If they exist, make sure none of your dependencies start withandroid.useAndroidX=true android.enableJetifier=truecom.android.support:. If you’re still using old support libraries, use Android Studio’s built-in migration tool: go toRefactor > Migrate to AndroidXand follow the prompts—it’ll handle most of the heavy lifting.
2. Hunt Down Duplicate Support Library Dependencies
Third-party libraries often sneak in their own versions of support libraries, leading to duplicates.
- Run this command in your project root terminal (Windows uses
gradlewinstead of./gradlew):./gradlew app:dependencies - Search the output for
android.support.v4—you’ll see which dependencies are pulling in duplicate v4 library versions. - Exclude the duplicate from the problematic dependency like this:
implementation('com.example.somelibrary:1.2.3') { exclude group: 'com.android.support', module: 'support-v4' }
3. Standardize Your Support Library Versions
Mismatched versions of support libraries are another common culprit.
- In your project-level
build.gradle, define a global version variable:ext { supportLibVersion = '28.0.0' // Use the latest stable support version here } - Update all your support library dependencies to use this variable, e.g.:
This ensures every support library uses the exact same version, eliminating version conflicts.implementation "com.android.support:appcompat-v7:$supportLibVersion" implementation "com.android.support:recyclerview-v7:$supportLibVersion"
4. Clean & Rebuild Your Project
Sometimes cached build files are the issue, so let’s wipe them clean:
- Click
Build > Clean Projectin Android Studio - Then click
Build > Rebuild Project - For good measure, delete the
.gradlefolder in your project root and thebuildfolders in both your app module and project root, then re-sync your Gradle files.
If none of these work, check if any of your third-party libraries are outdated—many older libraries haven’t been updated to use AndroidX or latest support versions, so updating them to their latest releases might resolve the conflict.
内容的提问来源于stack exchange,提问作者Kurniawan Alcantara

