Unity Android构建报错:存在重复的META-INF/annotation-experimental_release.kotlin_module文件
解决方案:重复
META-INF/annotation-experimental_release.kotlin_module文件构建报错 针对你遇到的依赖冲突导致的Unity Android构建报错,以下是经过验证的可行解决方案:
1. 修改Unity Gradle模板,添加打包规则
- 打开Unity,依次进入
Edit > Project Settings > Player > Android > Publishing Settings,勾选Custom Main Gradle Template和Custom Base Gradle Template - 打开生成的
mainTemplate.gradle文件,在android代码块中添加打包排除规则:
android { // 保留原有配置... packagingOptions { // 直接排除冲突文件 exclude 'META-INF/annotation-experimental_release.kotlin_module' // 若单个排除无效,改用通配符优先选择第一个匹配文件 // pickFirst 'META-INF/*.kotlin_module' } }
2. 针对性排除依赖中的冲突模块
既然明确冲突来自Google Mobile Ads和TheoPlayer的依赖嵌套,可以在Gradle中排除其中一方的annotation-experimental依赖:
- 在
mainTemplate.gradle的dependencies块中,找到对应依赖并添加排除规则:
dependencies { // 排除Google Mobile Ads中的冲突依赖(根据实际依赖版本调整) implementation 'com.google.android.gms:play-services-ads:xx.x.x' { exclude group: 'androidx.annotation', module: 'annotation-experimental' } // 或者排除TheoPlayer中的冲突依赖 implementation 'com.google.ads.interactivemedia.v3:interactivemedia:3.22.2' { exclude group: 'androidx.annotation', module: 'annotation-experimental' } }
注:排除前需确认其中一方的该依赖为非必需,不会影响插件功能
3. 强制统一依赖版本
在baseProjectTemplate.gradle中添加版本强制规则,确保所有依赖使用同一版本的annotation-experimental:
allprojects { repositories { // 保留原有仓库配置... } configurations.all { resolutionStrategy { force 'androidx.annotation:annotation-experimental:1.1.0' } } }
4. 彻底清理缓存
- Unity侧:执行
File > Build Settings > Android > Clean Build,手动删除项目根目录下的Library、Temp、obj文件夹 - Android Studio侧:导出项目后,点击
File > Invalidate Caches... > Invalidate and Restart,再依次执行Build > Clean Project和Build > Rebuild Project
若以上方案仍无效,可尝试更换TheoPlayer至不包含该冲突依赖的版本,或联系插件开发者更新依赖配置。
内容的提问来源于stack exchange,提问作者Tijs Van de Velde
相关产品推荐
相关产品推荐

