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

Ionic Cordova打包APK/App Bundle时android:exported属性缺失问题求助

解决Ionic Cordova构建时AndroidManifest.xml中android:exported属性被覆盖的问题

1. 从插件源头修改配置(避免构建覆盖)

手动修改platforms/android下的AndroidManifest.xml会被Cordova构建流程覆盖,必须修改对应插件的配置文件:

  • 处理nl.xservices.plugins.ShareChooserPendingIntent
    找到插件目录plugins/nl.xservices.plugins.share下的plugin.xml,找到对应<activity>标签,添加android:exported="true"(该组件需接收外部分享意图,设为true):

    <activity android:name="nl.xservices.plugins.ShareChooserPendingIntent"
              android:exported="true">
      <!-- 保留原有intent filter内容 -->
    </activity>
    
  • 处理com.gae.scaffolder.plugin.MyFirebaseMessagingService
    找到Firebase消息插件目录(如plugins/cordova-plugin-firebase-messaging)下的plugin.xml,给<service>标签添加android:exported="false"(推送服务仅内部使用,无需对外暴露):

    <service android:name="com.gae.scaffolder.plugin.MyFirebaseMessagingService"
             android:exported="false">
      <!-- 保留原有intent filter内容 -->
    </service>
    
  • 处理com.google.android.gms.analytics.AnalyticsReceiver
    找到谷歌分析插件目录(如plugins/cordova-plugin-google-analytics)下的plugin.xml,给<receiver>标签添加android:exported="false"(统计接收器仅内部接收事件):

    <receiver android:name="com.google.android.gms.analytics.AnalyticsReceiver"
              android:exported="false">
      <!-- 保留原有intent filter内容 -->
    </receiver>
    

2. 配置主Launcher Activity

带android.intent.category.LAUNCHER的主Activity需设置android:exported="true"(作为应用入口,系统需能启动),直接在项目根目录config.xml的<platform name="android">节点下添加:

<edit-config file="AndroidManifest.xml" target="/manifest/application/activity[@android:name='MainActivity']" mode="merge">
    <activity android:exported="true" />
</edit-config>

3. 清理并重新构建

修改完成后,执行以下命令确保配置生效:

ionic cordova platform rm android
ionic cordova platform add android@latest
ionic cordova build android --prod --release

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.07.25 23:33:24