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

如何修复Unity Android构建错误:重复的meta-data属性值

Unity Android构建失败:Manifest合并冲突(APP_ID重复)

问题场景

构建Unity Android项目时失败,核心原因是两个不同Manifest文件重复定义了com.google.android.gms.games.APP_ID的meta-data值,导致Manifest合并失败。

报错信息

D:\GitHub\WhyNotPJ_HC\WhyNotHC\Library\Bee\Android\Prj\IL2CPP\Gradle\launcher\src\main\AndroidManifest.xml:94:13-43 Error:
    Attribute meta-data#com.google.android.gms.games.APP_ID@value value=(@string/app_id) from [:unityLibrary] AndroidManifest.xml:94:13-43
    is also present at [:unityLibrary:GooglePlayGamesManifest.androidlib] AndroidManifest.xml:20:13-46 value=(\u003576325344850).
    Suggestion: add 'tools:replace="android:value"' to <meta-data> element at AndroidManifest.xml:92:9-94:46 to override.

FAILURE: Build failed with an exception.

* What went wrong:
Execution failed for task ':launcher:processReleaseManifest'.
> Manifest merger failed : Attribute meta-data#com.google.android.gms.games.APP_ID@value value=(@string/app_id) from [:unityLibrary] AndroidManifest.xml:94:13-43
    is also present at [:unityLibrary:GooglePlayGamesManifest.androidlib] AndroidManifest.xml:20:13-46 value=(\u003576325344850).
    Suggestion: add 'tools:replace="android:value"' to <meta-data> element at AndroidManifest.xml:92:9-94:46 to override.

* Try:
Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output. Run with --scan to get full insights.

* Get more help at https://help.gradle.org

BUILD FAILED in 5s
Picked up JAVA_TOOL_OPTIONS: -Dfile.encoding=UTF-8

UnityEngine.GUIUtility:ProcessEvent (int,intptr,bool&)

解决方法

方法1:通过自定义Manifest添加覆盖规则

  • 打开Unity项目,在Assets/Plugins/Android目录下找到AndroidManifest.xml(无则新建)
  • 在根<manifest>标签中引入tools命名空间:
    <manifest xmlns:android="http://schemas.android.com/apk/res/android"
              xmlns:tools="http://schemas.android.com/tools">
    
  • 找到或添加com.google.android.gms.games.APP_ID对应的meta-data标签,加上tools:replace="android:value"属性:
    <meta-data
        android:name="com.google.android.gms.games.APP_ID"
        android:value="@string/app_id"
        tools:replace="android:value" />
    
  • 保存文件后重新构建项目

方法2:清理重复的APP_ID配置

  • 打开Unity Package Manager,找到Google Play Games插件
  • 检查插件配置面板,确认是否已手动填入APP_ID,若有,确保项目中没有其他Manifest文件重复设置该值
  • 若插件自带的Manifest硬编码了APP_ID,尝试更新插件到最新版本(新版本通常会修复此类冲突)

方法3:通过Gradle模板统一配置

  • 在Unity的Player Settings → Publishing Settings中,启用Custom Gradle Template
  • 打开生成的mainTemplate.gradle文件,在android块内添加:
    android {
        // 保留原有配置,新增以下内容
        manifestPlaceholders = [
            'app_id': '你的实际Google Play Games APP_ID'
        ]
    }
    
  • 确保所有Manifest中的APP_ID值引用这个占位符:@string/app_id

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.07.21 08:20:37