React Native中@notifee/react-native运行报错问题求助
问题排查与解决方案
从报错截图的Manifest合并错误来看,核心原因是Android 12+(API 31及以上)强制要求所有组件(Activity、Service、BroadcastReceiver等)显式声明android:exported属性,而@notifee/react-native的部分内置组件未配置该属性,导致编译时Manifest合并失败。
以下是针对性解决步骤:
补全主Activity的
android:exported属性
打开android/app/src/main/AndroidManifest.xml,确保主启动Activity已添加该属性(启动页Activity设为true):<activity android:name=".MainActivity" android:exported="true" ...> <intent-filter> <action android:name="android.intent.action.MAIN" /> <category android:name="android.intent.category.LAUNCHER" /> </intent-filter> </activity>覆盖第三方库组件的
android:exported配置
在AndroidManifest.xml的<application>标签中添加工具属性,强制替换未配置的组件:<application ... tools:replace="android:exported" xmlns:tools="http://schemas.android.com/tools">同时显式声明@notifee相关组件并指定
exported值(非对外暴露的组件设为false):<receiver android:name="com.notifee.core.ForegroundServiceReceiver" android:exported="false" /> <service android:name="com.notifee.core.ForegroundService" android:exported="false" />升级@notifee/react-native到最新版本
旧版本库未适配API31+的exported要求,执行命令升级:npm install @notifee/react-native@latest清理缓存后重新构建
清除旧编译缓存避免残留配置:cd android && ./gradlew clean && cd .. npx react-native run-android
额外检查:确认android/build.gradle中的compileSdkVersion和targetSdkVersion均设置为33或更高:
android { compileSdkVersion 33 defaultConfig { targetSdkVersion 33 ... } }
内容的提问来源于stack exchange,提问作者János Komáromi
相关产品推荐
相关产品推荐

