React Native 0.75.2执行processDebugMainManifest任务报错求助
问题:React Native 0.75.2 清单合并错误及版本稳定性疑惑
用react-native-community/cli创建了基于RN 0.75.2的项目,折腾了好几次(删除重装文件)才成功创建空白项目。之后用yarn install安装了旧项目的依赖,执行yarn android时出现清单合并错误:
Error: Attribute property#android.adservices.AD_SERVICES_CONFIG@resource value=(@xml/ga_ad_services_config) from [com.google.android.gms:play-services-measurement-api:22.0.2] AndroidManifest.xml:32:13-58 is also present at [com.google.android.gms:play-services-ads-lite:23.2.0] AndroidManifest.xml:92:13-59 value=(@xml/gma_ad_services_config). Suggestion: add 'tools:replace="android:resource"' to <property> element at AndroidManifest.xml to override. FAILURE: Build failed with an exception. * What went wrong: Execution failed for task ':app:processDebugMainManifest'. > Manifest merger failed : Attribute property#android.adservices.AD_SERVICES_CONFIG@resource value=(@xml/ga_ad_services_config) from [com.google.android.gms:play-services-measurement-api:22.0.2] AndroidManifest.xml:32:13-58 is also present at [com.google.android.gms:play-services-ads-lite:23.2.0] AndroidManifest.xml:92:13-59 value=(@xml/gma_ad_services_config). Suggestion: add 'tools:replace="android:resource"' to <property> element at AndroidManifest.xml 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.
按照错误提示修改了AndroidManifest.xml,在<application>标签添加了tools:replace="android:resource",修改后的代码片段:
<manifest xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools"> <application tools:replace="android:resource" ...
但再次执行yarn android时又出现新错误:
BUILD FAILED in 9s error Failed to install the app. Command failed with exit code 1: gradlew.bat app:installDebug -PreactNativeDevServerPort=8081 C:\Users\JOHN\Desktop\react\social\android\app\src\main\AndroidManifest.xml:9:5-30:19 Error: tools:replace specified at line:9 for attribute android:resource, but no new value specified C:\Users\JOHN\Desktop\react\social\android\app\src\main\AndroidManifest.xml Error: Validation failed, exiting FAILURE: Build failed with an exception. * What went wrong: Execution failed for task ':app:processDebugMainManifest'. > Manifest merger failed with multiple errors, see logs * 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 9s. info Run CLI with --verbose flag for more details.
请问该如何解决这个错误?同时疑惑,为何React Native每月发布新版本却难以保证无错的稳定性?
解决方法及解答
一、修复清单合并错误
你之前的修改方向错了:错误提示要求给**<property>元素**添加tools:replace,而不是<application>标签,而且必须指定你要保留的android:resource值,否则会提示“no new value specified”。
推荐两种解决方案:
方案1:手动在AndroidManifest.xml中指定冲突属性
在AndroidManifest.xml的<application>内部,添加对应冲突的<property>元素,明确指定要保留的资源值并添加替换标记:
<application ...> <!-- 解决AD_SERVICES_CONFIG冲突,选择你要保留的资源值,二选一即可 --> <property android:name="android.adservices.AD_SERVICES_CONFIG" android:resource="@xml/ga_ad_services_config" <!-- 或者用@xml/gma_ad_services_config --> tools:replace="android:resource" /> ... </application>
方案2:通过Gradle统一Google Play服务版本
冲突根源是两个Google Play服务依赖版本不一致(一个22.0.2,一个23.2.0),可以在android/build.gradle中强制所有相关依赖使用同一版本,从根源避免冲突:
allprojects { repositories { // ... 原有仓库配置 } configurations.all { resolutionStrategy { // 强制统一版本,选一个兼容你项目的版本即可 force 'com.google.android.gms:play-services-measurement-api:23.2.0' force 'com.google.android.gms:play-services-ads-lite:23.2.0' } } }
二、关于React Native版本稳定性的问题
RN每月迭代新版本主要是为了:
- 快速跟进iOS、Android的系统更新,适配新系统API和行为;
- 修复已知bug、优化性能;
- 推出新特性提升开发体验。
但稳定性问题主要来自几个方面:
- 跨平台适配复杂度:RN需要同时兼容iOS和Android两大平台,每个平台的版本迭代、API变更都会带来适配压力,新版本可能引入边缘场景的兼容性问题;
- 第三方生态差异:旧项目的依赖可能没有及时适配RN新版本,当你直接把旧依赖安装到新版本RN上时,很容易出现依赖冲突(比如这次的Google Play服务版本不一致);
- 版本迭代策略:RN的快速迭代意味着每个版本的测试覆盖可能无法覆盖所有场景,部分问题会在后续小版本中修复,所以建议优先选择稳定版(如0.75.x系列),升级前先查看官方Release Notes了解已知问题。
内容的提问来源于stack exchange,提问作者JeremyFc
相关产品推荐
相关产品推荐

