升级targetSDK34后FCM内嵌通话需配置RECEIVER_EXPORTED/RECEIVER_NOT_EXPORTED
1. 广播接收器的API 34兼容配置
从Android 14(API 34)开始,所有静态注册的广播接收器(除了仅接收系统广播的特例)必须显式声明android:exported属性,或者在动态注册时指定RECEIVER_EXPORTED/RECEIVER_NOT_EXPORTED标记。
结合你的情况,错误大概率来自flutter_callkeep插件自动注册的广播接收器(比如处理来电状态的接收器),当前0.3.4版本未适配API 34要求,可通过以下两种方式解决:
方式一:升级flutter_callkeep插件
直接将插件版本升级到最新稳定版(如1.0.x及以上),新版本已经适配了API 34的广播接收器属性要求,无需手动修改Manifest。
方式二:手动补充广播接收器配置
如果暂时无法升级插件,需要在<application>标签内手动添加插件注册的广播接收器,并指定android:exported属性:
<!-- flutter_callkeep默认注册的广播接收器示例,根据实际插件代码调整 --> <receiver android:name="com.github.cloudwebrtc.flutter_callkeep.CallKeepBroadcastReceiver" android:exported="false"> <!-- 仅内部使用,设为false;若需接收外部广播则设为true --> <intent-filter> <action android:name="android.intent.action.PHONE_STATE" /> <action android:name="android.intent.action.NEW_OUTGOING_CALL" /> </intent-filter> </receiver>
另外,如果你自己注册了RECEIVE_BOOT_COMPLETED对应的接收器,也必须添加android:exported属性:
<receiver android:name=".YourBootCompletedReceiver" android:exported="true"> <!-- BOOT_COMPLETED是系统广播,但API 34仍需显式声明 --> <intent-filter> <action android:name="android.intent.action.BOOT_COMPLETED" /> </intent-filter> </receiver>
2. Firebase FCM适配API 34的额外步骤
FCM适配API 34需要完成以下几点:
升级Firebase依赖版本
确保项目使用的Firebase BOM版本在29.0.0及以上(推荐使用最新稳定版),这样依赖的FCM库已经适配API 34。在android/build.gradle中更新:
dependencies { // 替换为最新版本的Firebase BOM implementation platform('com.google.firebase:firebase-bom:32.7.0') implementation 'com.google.firebase:firebase-messaging' }
检查FCM广播接收器配置
新版本的FCM库会自动为FirebaseMessagingReceiver添加android:exported属性,但如果你的Manifest中手动注册了该接收器,需确保添加该属性:
<receiver android:name="com.google.firebase.messaging.FirebaseMessagingReceiver" android:exported="true" android:permission="com.google.android.c2dm.permission.SEND"> <intent-filter> <action android:name="com.google.android.c2dm.intent.RECEIVE" /> <category android:name="${applicationId}" /> </intent-filter> </receiver>
适配通知权限
API 33及以上版本需要申请POST_NOTIFICATIONS权限,确保Manifest中已添加:
<uses-permission android:name="android.permission.POST_NOTIFICATIONS" />
同时在应用运行时主动请求该权限(如果应用需要展示通知)。
内容的提问来源于stack exchange,提问作者nayoon

