Cordova 12.0.0构建Android Release Bundle时processReleaseMainManifest失败求助
解决Cordova 12构建Android Bundle时
android:exported属性缺失问题 问题根源
Android 12(API 31)及以上版本强制要求所有四大组件(Activity、Service、Receiver、Provider)必须显式声明android:exported属性(取值为true或false),否则Manifest合并阶段会触发processReleaseMainManifest任务失败。你遇到的报错,是因为cordova-plugin-autostart插件的三个Receiver组件未添加该属性。
解决方案
以下是两种直接可行的解决方式,按优先级推荐:
方式1:升级或手动修复插件
- 优先尝试升级插件:先执行
cordova plugin list查看当前插件版本,若插件仓库有适配Android 12的新版本,执行以下命令更新:cordova plugin remove cordova-plugin-autostart cordova plugin add cordova-plugin-autostart@最新版本号 - 无新版本则手动修改插件Manifest:
- 找到插件在项目中的Manifest配置位置:
platforms/android/app/src/main/java/com/tonikorin/cordova/plugin/autostart目录下的插件Manifest文件(或插件res/xml目录中的配置片段) - 给三个Receiver添加
android:exported="true"属性(这三个Receiver监听系统广播,设为true符合需求):<receiver android:name="com.tonikorin.cordova.plugin.autostart.BootCompletedReceiver" android:exported="true"> <intent-filter> <action android:name="android.intent.action.BOOT_COMPLETED" /> <action android:name="android.intent.action.QUICKBOOT_POWERON" /> </intent-filter> </receiver> <receiver android:name="com.tonikorin.cordova.plugin.autostart.UserPresentReceiver" android:exported="true"> <intent-filter> <action android:name="android.intent.action.USER_PRESENT" /> </intent-filter> </receiver> <receiver android:name="com.tonikorin.cordova.plugin.autostart.PackageReplacedReceiver" android:exported="true"> <intent-filter> <action android:name="android.intent.action.MY_PACKAGE_REPLACED" /> </intent-filter> </receiver> - 修改后重新执行构建命令:
cordova build android --release -- --packageType=bundle
- 找到插件在项目中的Manifest配置位置:
方式2:通过config.xml强制覆盖属性
如果不想修改插件源码,可在项目根目录的config.xml中添加edit-config标签,给三个Receiver注入android:exported属性:
<platform name="android"> <!-- 给BootCompletedReceiver添加exported属性 --> <edit-config file="AndroidManifest.xml" target="/manifest/application/receiver[@name='com.tonikorin.cordova.plugin.autostart.BootCompletedReceiver']" mode="merge"> <receiver android:exported="true" /> </edit-config> <!-- 给UserPresentReceiver添加exported属性 --> <edit-config file="AndroidManifest.xml" target="/manifest/application/receiver[@name='com.tonikorin.cordova.plugin.autostart.UserPresentReceiver']" mode="merge"> <receiver android:exported="true" /> </edit-config> <!-- 给PackageReplacedReceiver添加exported属性 --> <edit-config file="AndroidManifest.xml" target="/manifest/application/receiver[@name='com.tonikorin.cordova.plugin.autostart.PackageReplacedReceiver']" mode="merge"> <receiver android:exported="true" /> </edit-config> </platform>
添加后执行cordova prepare android同步配置,再重新运行构建命令。
注意事项
- 若你升级Gradle到8.0后出现额外兼容问题,可在
platforms/android/build.gradle中把Gradle版本回退到Cordova 12默认的7.6版本。
内容的提问来源于stack exchange,提问作者murahbanget
相关产品推荐
相关产品推荐

