React Native集成react-native-crisp-chat-sdk后Android Manifest合并失败求助
解决React Native中react-native-crisp-chat-sdk导致的Android Manifest合并失败问题
问题场景
安装react-native-crisp-chat-sdk后iOS端运行正常,但Android端构建时出现Manifest合并失败错误,具体报错如下:
Task :app:processDebugMainManifest FAILED See https://developer.android.com/r/studio-ui/build/manifest-merger for more information about the manifest merger. Deprecated Gradle features were used in this build, making it incompatible with Gradle 9.0. You can use '--warning-mode all' to show the individual deprecation warnings and determine if they come from your own scripts or plugins. See https://docs.gradle.org/8.0.1/userguide/command_line_interface.html#sec:command_line_warnings 112 actionable tasks: 2 executed, 110 up-to-date info 💡 Tip: Make sure that you have set up your development environment correctly, by running react-native doctor. To read more about doctor command visit: https://github.com/react-native-community/cli/blob/main/packages/cli-doctor/README.md#doctor /Users/username/appname/android/app/src/debug/AndroidManifest.xml:43:9-51 Error: Attribute meta-data#com.google.firebase.messaging.default_notification_icon@resource value=(@drawable/ic_small_icon) from AndroidManifest.xml:43:9-51 is also present at [im.crisp:crisp-sdk:2.0.9] AndroidManifest.xml:77:13-69 value=(@drawable/crisp_sdk_notification_icon). Suggestion: add 'tools:replace="android:resource"' to element at AndroidManifest.xml:41:7-43:54 to override. /Users/username/appname/android/app/src/debug/AndroidManifest.xml:40:13-44 Error: Attribute meta-data#com.google.firebase.messaging.default_notification_color@resource value=(@color/white) from [:react-native-firebase_messaging] AndroidManifest.xml:40:13-44 is also present at [im.crisp:crisp-sdk:2.0.9] AndroidManifest.xml:80:13-67 value=(@color/crisp_sdk_theme_blue_regular). Suggestion: add 'tools:replace="android:resource"' to element at AndroidManifest.xml:38:9-40:47 to override. /Users/username/appname/android/app/src/debug/AndroidManifest.xml:34:13-33 Error: Attribute meta-data#firebase_messaging_auto_init_enabled@value value=(true) from [:react-native-firebase_messaging] AndroidManifest.xml:34:13-33 is also present at [im.crisp:crisp-sdk:2.0.9] AndroidManifest.xml:83:13-34 value=(false). Suggestion: add 'tools:replace="android:value"' to element at AndroidManifest.xml:32:9-34:36 to override. FAILURE: Build failed with an exception. * What went wrong: Execution failed for task ':app:processDebugMainManifest'. > Manifest merger failed with multiple errors, see logs
项目依赖信息
项目的package.json内容如下:
{ "name": "appslug", "version": "1.0.0", "private": true, "scripts": { "android": "react-native run-android", "ios": "react-native run-ios", "lint": "eslint .", "start": "react-native start", "test": "jest" }, "dependencies": { "@flyerhq/react-native-chat-ui": "^1.4.3", "@notifee/react-native": "^7.8.2", "@react-native-async-storage/async-storage": "^1.19.6", "@react-native-clipboard/clipboard": "^1.14.0", "@react-native-community/push-notification-ios": "^1.11.0", "@react-native-firebase/app": "^20.3.0", "@react-native-firebase/messaging": "^20.3.0", "@react-native-masked-view/masked-view": "^0.3.1", "@react-navigation/bottom-tabs": "^6.5.9", "@react-navigation/native": "^6.1.7", "@react-navigation/native-stack": "^6.9.13", "@rneui/base": "^4.0.0-rc.8", "@rneui/themed": "^4.0.0-rc.8", "apisauce": "^3.0.1", "formik": "^2.4.3", "moment": "^2.30.1", "moment-timezone": "^0.5.45", "react": "18.2.0", "react-native": "0.72.4", "react-native-crisp-chat-sdk": "^0.16.0", "react-native-gesture-handler": "^2.16.1", "react-native-image-picker": "^7.1.2", "react-native-keyboard-aware-scroll-view": "^0.9.5", "react-native-linear-gradient": "^2.8.3", "react-native-permissions": "^4.1.5", "react-native-push-notification": "^8.1.1", "react-native-reanimated": "^3.15.0", "react-native-render-html": "^6.3.4", "react-native-safe-area-context": "^4.7.2", "react-native-screens": "^3.25.0", "react-native-skeleton-placeholder": "^5.2.4", "react-native-splash-screen": "^3.3.0", "react-native-svg": "^14.1.0", "react-native-toast-message": "^2.2.1", "react-native-vector-icons": "^10.0.0", "react-native-webview": "^13.8.1", "socket.io-client": "^4.8.1", "yup": "^1.2.0" }, "devDependencies": { "@babel/core": "^7.20.0", "@babel/preset-env": "^7.20.0", "@babel/runtime": "^7.20.0", "@react-native/eslint-config": "^0.72.2", "@react-native/metro-config": "^0.72.11", "@tsconfig/react-native": "^3.0.0", "@types/react": "^18.0.24", "@types/react-test-renderer": "^18.0.0", "babel-jest": "^29.2.1", "eslint": "^8.19.0", "jest": "^29.2.1", "metro-react-native-babel-preset": "0.76.8", "prettier": "^2.4.1", "react-test-renderer": "18.2.0", "typescript": "4.8.4" }, "engines": { "node": ">=16" } }
解决方案
如果直接按错误提示添加tools:replace无效,可依次尝试以下步骤:
添加tools命名空间
确保在AndroidManifest.xml的根<manifest>标签中引入tools命名空间:<manifest xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools" package="com.yourpackage">批量替换冲突属性
对每个冲突的meta-data标签,明确添加tools:replace属性覆盖Crisp SDK的配置:<!-- 替换通知图标 --> <meta-data android:name="com.google.firebase.messaging.default_notification_icon" android:resource="@drawable/ic_small_icon" tools:replace="android:resource" /> <!-- 替换通知颜色 --> <meta-data android:name="com.google.firebase.messaging.default_notification_color" android:resource="@color/white" tools:replace="android:resource" /> <!-- 替换自动初始化配置 --> <meta-data android:name="firebase_messaging_auto_init_enabled" android:value="true" tools:replace="android:value" />排除Crisp SDK的Manifest
在android/app/build.gradle的依赖中,排除Crisp SDK自带的Manifest文件:implementation(project(':react-native-crisp-chat-sdk')) { exclude group: 'im.crisp', module: 'crisp-sdk' }清理缓存并重构
执行以下命令清理构建缓存后重新编译:cd android && ./gradlew clean cd .. && react-native run-android降级Crisp SDK版本
尝试将react-native-crisp-chat-sdk降级到更早版本(比如0.15.0),避免新版本引入的冲突:npm install react-native-crisp-chat-sdk@0.15.0 --save
内容的提问来源于stack exchange,提问作者Habibur Rahman
相关产品推荐
相关产品推荐

