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

EAS构建Android失败:react-native-google-mobile-ads引发Manifest冲突

解决react-native-google-mobile-ads导致Expo Android构建的AndroidManifest冲突问题

问题根源

react-native-google-mobile-ads库会默认向AndroidManifest.xml注入自身的com.google.android.gms.ads.APPLICATION_ID和com.google.android.gms.ads.DELAY_APP_MEASUREMENT_INIT配置,与你在app.json中配置的Admob信息发生冲突,导致Gradle合并Manifest时失败。

解决方案

针对Bare Workflow项目

  1. 打开项目中的android/app/src/main/AndroidManifest.xml
  2. 在<manifest>标签中添加tools命名空间:
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
          xmlns:tools="http://schemas.android.com/tools"
          package="你的应用包名">
  1. 在<application>标签内添加带tools:replace的meta-data配置,强制覆盖冲突值:
<application ...>
    <!-- 替换为你实际的Admob Android应用ID -->
    <meta-data
        android:name="com.google.android.gms.ads.APPLICATION_ID"
        android:value="ca-app-pub-xxxxxxxxxxxxxxxx~yyyyyyyyyy"
        tools:replace="android:value" />
    
    <!-- 根据需求设置true或false,覆盖冲突的延迟初始化配置 -->
    <meta-data
        android:name="com.google.android.gms.ads.DELAY_APP_MEASUREMENT_INIT"
        android:value="true"
        tools:replace="android:value" />
    
    <!-- 其他原有配置 -->
</application>

针对Managed Workflow项目

  1. 安装expo-build-properties插件:
npx expo install expo-build-properties
  1. 在app.json的plugins数组中添加配置,通过插件修改Manifest:
{
  "expo": {
    "plugins": [
      [
        "expo-build-properties",
        {
          "android": {
            "manifest": {
              "xmlns:tools": "http://schemas.android.com/tools",
              "application": {
                "meta-data": [
                  {
                    "android:name": "com.google.android.gms.ads.APPLICATION_ID",
                    "android:value": "ca-app-pub-xxxxxxxxxxxxxxxx~yyyyyyyyyy",
                    "tools:replace": "android:value"
                  },
                  {
                    "android:name": "com.google.android.gms.ads.DELAY_APP_MEASUREMENT_INIT",
                    "android:value": "true",
                    "tools:replace": "android:value"
                  }
                ]
              }
            }
          }
        }
      ]
    ],
    // 其他原有配置
  }
}

验证修复

重新执行构建命令:

npx eas-cli build --profile development

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.07.21 14:45:08