Android 12安装应用报错INSTALL_PARSE_FAILED_MANIFEST_MALFORMED如何解决?
问题根因
该报错出现在应用
targetSdkVersion >= 31(对应Android 12及以上系统)时:Android 12要求所有包含<intent-filter>的四大组件(Activity、Service、BroadcastReceiver)必须显式声明android:exported属性,不允许缺省。本次报错指向react-native-push-notification库的RNPushNotificationBootEventReceiver广播接收器未适配该规则。
解决方案
方案一:升级官方适配版本
该库在v7.0.0及以上版本已经完成Android 12适配,优先选择升级依赖解决:
- 升级依赖包
npm install react-native-push-notification@latest --save
- 清理构建缓存后重新打包
cd android && ./gradlew clean cd .. && npx react-native run-android
方案二:手动覆写组件配置
如果项目兼容原因无法升级依赖,可直接在项目的android/app/src/main/AndroidManifest.xml中手动覆写该组件配置,显式添加android:exported属性:
- 在
AndroidManifest.xml的<application>标签内添加如下代码:
<!-- 覆写报错的广播接收器配置 --> <receiver android:name="com.dieam.reactnativepushnotification.modules.RNPushNotificationBootEventReceiver" android:exported="true" > <intent-filter> <action android:name="android.intent.action.BOOT_COMPLETED" /> <action android:name="android.intent.action.MY_PACKAGE_REPLACED" /> </intent-filter> </receiver> <!-- 同步补充该库其他组件的exported属性,避免后续同类报错 --> <receiver android:name="com.dieam.reactnativepushnotification.modules.RNPushNotificationPublisher" android:exported="false" /> <service android:name="com.dieam.reactnativepushnotification.modules.RNPushNotificationListenerService" android:exported="true" > <intent-filter> <action android:name="com.google.firebase.MESSAGING_EVENT" /> </intent-filter> </service>
属性说明:如果组件需要接收外部(包含系统)的广播、或允许其他应用调用,设置android:exported="true",仅内部使用设置为false即可
方案三:全局排查补全配置
如果修改后仍有同类报错,全局检查项目所有带<intent-filter>的Activity、Service、BroadcastReceiver,全部补上显式的android:exported属性即可。
内容的提问来源于stack exchange,提问作者vjtechno
相关产品推荐
相关产品推荐

