android build_error ai_generated true

任务 ':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

其他格式: JSON · Markdown 中文 · English
80%修复率
82%置信度
1证据数
2023-08-05首次发现

版本兼容性

版本状态引入弃用备注
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.

generic

官方文档

https://developer.android.com/studio/build/jetifier

解决方案

  1. 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' }
  2. Upgrade all dependencies to their AndroidX versions and disable Jetifier in gradle.properties: android.jetifier.enabled=false
  3. Use the `com.google.guava:guava:30.1.1-android` variant which avoids conflicts with other Android libraries.

无效尝试

常见但无效的做法:

  1. 70% 失败

    Disabling Jetifier entirely may cause other libraries to break if they still depend on support libraries.

  2. 65% 失败

    Adding an exclude statement in packagingOptions for the duplicate class often masks the root cause and may remove needed functionality.

  3. 60% 失败

    Using a newer version of the dependency without checking its transitive dependencies may introduce more duplicates.