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

TargetSDK升级到31后出现PendingIntent FLAG报错,求指导需升级哪些插件

解决Target SDK 31下PendingIntent FLAG必填报错问题

当将Android Target SDK升级到31+后,系统要求创建PendingIntent时必须指定FLAG_IMMUTABLE或FLAG_MUTABLE参数,你的报错正是因为所使用的旧版本插件未适配这一要求。结合你的插件列表,以下是需要优先升级的插件及操作建议:

需要升级的插件及原因

  • @capacitor/push-notifications@1.0.9:推送通知流程会频繁创建PendingIntent,该版本未适配SDK 31的要求,必须升级。
  • @capacitor-community/admob@3.2.0:AdMob的广告回调、通知等逻辑依赖PendingIntent,旧版本无相关适配。
  • @codetrix-studio/capacitor-google-auth@3.1.4:Google登录的授权跳转涉及PendingIntent,需升级以兼容SDK 31。
  • 其余官方核心插件(@capacitor/app、@capacitor/haptics等)均为早期版本,建议同步升级到对应Capacitor主版本的最新稳定版,保障整体兼容性。

升级命令示例(npm)

# 升级推送通知插件
npm install @capacitor/push-notifications@latest

# 升级AdMob社区插件
npm install @capacitor-community/admob@latest

# 升级Google Auth插件
npm install @codetrix-studio/capacitor-google-auth@latest

# 批量升级其余核心插件
npm install @capacitor/app@latest @capacitor/haptics@latest @capacitor/keyboard@latest @capacitor/splash-screen@latest @capacitor/status-bar@latest

后续操作

  1. 插件升级完成后,执行npx cap sync android同步配置到Android项目
  2. 根据你使用的Capacitor主版本(3/4/5),确保插件版本与主版本兼容
  3. 测试推送通知、AdMob广告、Google登录等核心功能,验证适配效果

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.08.05 16:31:02