You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

如何移除重复的Unity Ads包以解决构建失败问题?

Unity Ads重复类导致Android构建失败的解决方法

错误信息摘要

构建耗时28秒(28474毫秒),结果为Failed,核心报错:

FAILURE: Build failed with an exception.

  • What went wrong:
    Execution failed for task ':launcher:checkDebugDuplicateClasses'.

1 exception was raised by workers:
java.lang.RuntimeException: java.lang.RuntimeException:
Duplicate class com.unity3d.ads.BuildConfig found in modules UnityAds-runtime.jar (:UnityAds:) and com.unity3d.ads.unity-ads-4.4.1-runtime.jar (:com.unity3d.ads.unity-ads-4.4.1:)
Duplicate class com.unity3d.ads.IUnityAdsInitializationListener found in modules UnityAds-runtime.jar (:UnityAds:) and com.unity3d.ads.unity-ads-4.4.1-runtime.jar (:com.unity3d.ads.unity-ads-4.4.1:)

问题根源:项目中同时存在两个版本的Unity Ads包,导致类重复冲突。


解决步骤

方法1:通过Unity Package Manager移除重复包

  • 打开Unity编辑器,点击Window > Package Manager
  • 切换到In Project标签,找到所有和Unity Ads相关的包(比如Unity Ads旧版、com.unity3d.ads.unity-ads 4.4.1版)
  • 保留4.4.1版本的包,选中另一个重复包,点击右下角Remove按钮,确认移除后重新构建

方法2:手动修改Gradle配置排除重复依赖

如果Package Manager无法处理,可自定义Gradle模板解决:

  1. 开启自定义Gradle模板:Edit > Project Settings > Player > Android > Publishing Settings,勾选Custom Main Gradle Template和Custom Launcher Gradle Template
  2. 打开Assets/Plugins/Android/launcherTemplate.gradle文件
  3. 在dependencies代码块中添加排除规则,保留新版包并排除旧版重复类:
dependencies {
    // 保留其他原有依赖
    implementation('com.unity3d.ads:unity-ads:4.4.1') {
        exclude group: 'com.unity3d.ads', module: 'UnityAds'
    }
}

方法3:手动删除Plugins目录下的重复Jar包

  • 打开项目的Assets/Plugins/Android目录
  • 删除其中一个重复的Jar文件(建议删除旧版的UnityAds-runtime.jar)
  • 清理项目缓存:Edit > Clear All PlayerPrefs,再点击File > Build Settings > Clean Build,之后重新构建

内容的提问来源于stack exchange,提问作者Octopus

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.08.11 03:30:55