更新Android Studio 3.1后运行应用遇Program type already present错误求助
Hey there, let's tackle this duplicate class error you're facing after updating to Android Studio 3.1. This issue almost always boils down to conflicting dependencies where the same class is being pulled in multiple times—specifically, the DragAndDropPermissionsCompat class from the support-v13 library is clashing with other support libraries in your project. Here's how to resolve it step by step:
Step 1: Identify the duplicate dependency
First, you need to find out which part of your project is bringing in the duplicate support-v13 library. Run this command in your project's root directory (use gradlew.bat instead of ./gradlew if you're on Windows):
./gradlew app:dependencies
Search through the output for support-v13—you'll see either a direct dependency you added yourself, or an indirect one from a third-party library.
Step 2: Remove or exclude the duplicate
- If you directly added
support-v13to yourbuild.gradlebut don't actually need it (most apps don't require v13 unless targeting tablets specifically), just delete that dependency line. - If the duplicate comes from a third-party library, add an exclusion rule to that dependency in your app-level
build.gradle. For example, ifcom.example:some-library:1.0is pulling in support-v13, modify it like this:implementation('com.example:some-library:1.0') { exclude group: 'com.android.support', module: 'support-v13' }
Step 3: Unify your support library versions
A common root cause is having mismatched versions of support libraries. Make sure all your support dependencies use the same version. You can even define a variable in your root build.gradle to keep things consistent:
// Root build.gradle ext { supportLibVersion = '27.1.1' // A stable version compatible with AS 3.1 } // App-level build.gradle implementation "com.android.support:appcompat-v7:${supportLibVersion}" implementation "com.android.support:recyclerview-v7:${supportLibVersion}" // Add other support libraries using the same variable
Step 4: Clean and rebuild your project
Finally, clear out old build artifacts and rebuild from scratch:
- In Android Studio, go to
Build -> Clean Project, thenBuild -> Rebuild Project - Or run this command in the terminal:
./gradlew clean build
That should resolve the duplicate class error. If you're still stuck, double-check your dependency tree again—sometimes a less obvious library is hiding the duplicate.
内容的提问来源于stack exchange,提问作者Nandkishor mewara

