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

React Native适配Android12仍报错:第三方服务未设置android:exported

解决React Native适配Android 12+时第三方组件未设置android:exported的问题

问题根源

你遇到的问题是com.wix.reactnativenotifications.fcm.FcmInstanceIdListenerService来自react-native-notifications第三方依赖库,该库内部的AndroidManifest.xml未给这个组件添加android:exported属性。Android 12+要求所有带intent filter的组件必须显式声明该属性,而你仅修改了项目自身的两个Manifest文件,库的Manifest会和你的清单合并,导致合并后的文件里这个组件仍缺失该属性。

解决步骤

  • 优先升级依赖库
    检查react-native-notifications是否有适配Android 12+的新版本,新版本通常已补全android:exported属性。在项目根目录执行命令更新:

    npm install react-native-notifications@latest --save
    # 或使用yarn
    yarn add react-native-notifications@latest
    

    更新后重新编译打包,多数情况下问题可解决。

  • 在项目Manifest中覆盖组件属性
    若无法升级库,可在你项目的AndroidManifest.xml中重新声明该组件,显式设置android:exported属性:

    <service
        android:name="com.wix.reactnativenotifications.fcm.FcmInstanceIdListenerService"
        android:exported="false"> <!-- 该服务无需对外暴露,设为false即可 -->
        <intent-filter>
            <action android:name="com.google.firebase.INSTANCE_ID_EVENT" />
        </intent-filter>
    </service>
    

    注:android:exported值需根据组件用途判断,若需接收外部应用Intent则设为true,否则设为false。

  • 查看合并后的Manifest确认问题
    通过Android Studio查看最终合并的Manifest文件,验证组件属性是否正确设置:

    1. 打开React Native项目下的android目录
    2. 点击菜单栏Tools > App Links Assistant > Open Merged Manifest
    3. 搜索FcmInstanceIdListenerService,检查该组件的android:exported属性状态

验证解决

修改完成后重新生成APK/App Bundle,在Android 12+设备或模拟器上安装测试,确认安装无报错。

内容的提问来源于stack exchange,提问作者Aman Ahmed

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.08.18 12:10:48