任务 ':app:transformClassesWithJarMergingForDebug' 执行失败。> com.android.build.api.transform.TransformException: java.util.zip.ZipException: 重复条目:com/google/common/collect/ImmutableList.class
Execution failed for task ':app:transformClassesWithJarMergingForDebug'. > com.android.build.api.transform.TransformException: java.util.zip.ZipException: duplicate entry: com/google/common/collect/ImmutableList.class
ID: android/gradle-task-assemble-debug-failed-jetifier
版本兼容性
| 版本 | 状态 | 引入 | 弃用 | 备注 |
|---|---|---|---|---|
| Android Gradle Plugin 8.1 | active | — | — | — |
| Gradle 8.2 | active | — | — | — |
| Jetifier 1.0.0-beta10 | active | — | — | — |
| Android Studio Hedgehog 2023.1.1 | active | — | — | — |
根因分析
多个依赖中发现重复类,通常是由于 Jetifier 同时转换了支持库和 AndroidX,或者两个库提供了相同的类。
English
Duplicate class found in multiple dependencies, often due to Jetifier converting both support libraries and AndroidX, or two libraries shipping the same class.
官方文档
https://developer.android.com/studio/build/jetifier解决方案
-
Run `./gradlew :app:dependencies --configuration debugCompileClasspath` to identify which libraries bring the duplicate class. Then exclude the transitive dependency in build.gradle: implementation('com.example:library:1.0') { exclude group: 'com.google.guava', module: 'guava' } -
Upgrade all dependencies to their AndroidX versions and disable Jetifier in gradle.properties: android.jetifier.enabled=false
-
Use the `com.google.guava:guava:30.1.1-android` variant which avoids conflicts with other Android libraries.
无效尝试
常见但无效的做法:
-
70% 失败
Disabling Jetifier entirely may cause other libraries to break if they still depend on support libraries.
-
65% 失败
Adding an exclude statement in packagingOptions for the duplicate class often masks the root cause and may remove needed functionality.
-
60% 失败
Using a newer version of the dependency without checking its transitive dependencies may introduce more duplicates.