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项目
- 打开项目中的
android/app/src/main/AndroidManifest.xml - 在
<manifest>标签中添加tools命名空间:
<manifest xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools" package="你的应用包名">
- 在
<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项目
- 安装expo-build-properties插件:
npx expo install expo-build-properties
- 在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
相关产品推荐
相关产品推荐

