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

使用Capacitor 4构建Ionic应用提交华为应用市场失败求助

解决华为应用市场构建失败(android:exported缺失)问题

错误原因

targetSdkVersion升级到32(Android 12及以上)后,系统要求所有包含intent-filter的组件(Activity、Receiver、Service等)必须显式声明android:exported属性,而你使用的华为Cordova推送插件中的HmsLocalNotificationBootEventReceiver未添加该属性,导致Manifest合并失败。

解决方案

1. 优先升级华为推送插件到最新版本

华为官方已针对Android 12适配更新了插件,升级到最新版可自动修复该问题:

  • 若使用Cordova插件,执行命令:
    ionic cordova plugin update cordova-plugin-hms-push
    npm update @hmscore/cordova-plugin-hms-push
    
  • 升级后重新执行构建命令,验证问题是否解决。

2. 手动在主Manifest中补充属性

如果升级插件无效,可在项目主android/app/src/main/AndroidManifest.xml中手动声明该Receiver并添加android:exported:

  1. 确保Manifest根元素包含tools命名空间:
    <manifest xmlns:android="http://schemas.android.com/apk/res/android"
        xmlns:tools="http://schemas.android.com/tools"
        package="你的应用包名">
    
  2. 添加Receiver声明(接收开机广播需设为true):
    <receiver
        android:name="com.huawei.hms.cordova.push.receiver.HmsLocalNotificationBootEventReceiver"
        android:exported="true"
        tools:node="merge">
        <intent-filter>
            <action android:name="android.intent.action.BOOT_COMPLETED" />
            <action android:name="android.intent.action.QUICKBOOT_POWERON" />
        </intent-filter>
    </receiver>
    
    tools:node="merge"用于合并插件中已有的Receiver配置,避免冲突。

3. 通过Gradle Manifest Merger强制设置属性

若上述方法均无效,可在android/app/build.gradle中添加规则,构建时自动为目标Receiver补充属性:

android {
    defaultConfig {
        ...
        manifestPlaceholders = [
            "HmsLocalNotificationBootEventReceiverExported": "true"
        ]
    }
    ...
    android.applicationVariants.all { variant ->
        variant.outputs.each { output ->
            output.processManifest.doLast {
                def manifestFile = output.processManifest.manifestOutputFile
                def content = manifestFile.getText('UTF-8')
                content = content.replace(
                    '<receiver android:name="com.huawei.hms.cordova.push.receiver.HmsLocalNotificationBootEventReceiver">',
                    '<receiver android:name="com.huawei.hms.cordova.push.receiver.HmsLocalNotificationBootEventReceiver" android:exported="true">'
                )
                manifestFile.write(content, 'UTF-8')
            }
        }
    }
}

内容的提问来源于stack exchange,提问作者Serj Malko

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.08.22 02:18:09