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

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.08.02 13:55:41