Android Studio 3中transformClassesWithMultidexlistForDebug任务执行失败求助
Hey there, I’ve run into this exact duplicate class issue with multidex before—let’s get it sorted out for you! The error is telling us that the android.support.v4.view.ViewCompat.class is showing up multiple times in your build, specifically from the support-compat-25.2.0.aar dependency. Here’s how to fix it step by step:
Step 1: Identify the Duplicate Dependency
First, we need to pinpoint which libraries are pulling in duplicate versions of the support-compat 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-compat—you’ll likely see multiple entries or mixed versions of the support libraries. The goal is to ensure all support library dependencies use the same version (in your case, 25.2.0).
Step 2: Exclude Duplicate Dependencies
Once you spot the library causing the conflict, exclude its duplicate support-compat entry in your app’s build.gradle file. For example, if a third-party library is bringing in an extra version:
implementation('com.example:problematic-library:1.0.0') { exclude group: 'com.android.support', module: 'support-compat' }
This tells Gradle to skip the duplicate support-compat from that library, using your project’s unified version instead.
Step 3: Clean Up Caches and Rebuild
Duplicate class issues often linger due to cached build files. Let’s clear them out:
- Go to
Build -> Clean Projectin Android Studio, thenBuild -> Rebuild Project. - If that doesn’t work, manually delete the
.gradlecache folder atC:\Users\karam\.gradle\caches, restart Android Studio, and try building again.
Step 4: Verify Multidex Configuration
Double-check that your multidex setup is correct, since this error occurs during multidex list generation:
- In your app’s
build.gradle, ensure multidex is enabled:android { defaultConfig { multiDexEnabled true } } - Add the multidex dependency if you haven’t already:
dependencies { implementation 'com.android.support:multidex:1.0.3' } - If you have a custom Application class, either extend
MultiDexApplicationor add this code to itsattachBaseContextmethod:@Override protected void attachBaseContext(Context base) { super.attachBaseContext(base); MultiDex.install(this); }
After following these steps, your build should no longer hit that duplicate zip entry error.
内容的提问来源于stack exchange,提问作者Youssef Karam

