Unity开发游戏Google Play预发布测试崩溃问题求助
Google Play预发布测试两处崩溃问题分析与修复
崩溃问题1:Google Play Instant Apps后台服务启动异常
错误信息
FATAL EXCEPTION: main Process: com.android.vending:instant_app_installer, PID: 19323 java.lang.RuntimeException: Unable to start receiver com.google.android.finsky.instantapps.PhenotypeUpdateReceiver: android.app.BackgroundServiceStartNotAllowedException: Not allowed to start service Intent { act=com.google.android.gms.phenotype.UPDATE cmp=com.android.vending/com.google.android.finsky.instantapps.PhenotypeUpdateService }: app is in background uid UidRecord{64ad173 u0a135 TRNB bg:+13m22s373ms idle change:uncached procs:0 seq(0,0,0)} at android.app.ActivityThread.handleReceiver(ActivityThread.java:4317) at android.app.ActivityThread.access$1600(ActivityThread.java:247) at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2064) at android.os.Handler.dispatchMessage(Handler.java:106) at android.os.Looper.loopOnce(Looper.java:201) at android.os.Looper.loop(Looper.java:288) at android.app.ActivityThread.main(ActivityThread.java:7839) at java.lang.reflect.Method.invoke(Native Method) at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:548) at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1003) Caused by: android.app.BackgroundServiceStartNotAllowedException: Not allowed to start service Intent { act=com.google.android.gms.phenotype.UPDATE cmp=com.android.vending/com.google.android.finsky.instantapps.PhenotypeUpdateService }: app is in background uid UidRecord{64ad173 u0a135 TRNB bg:+13m22s373ms idle change:uncached procs:0 seq(0,0,0)} at android.app.ContextImpl.startServiceCommon(ContextImpl.java:1861) at android.app.ContextImpl.startService(ContextImpl.java:1817) at android.content.ContextWrapper.startService(ContextWrapper.java:774) at alj.a(PG:2) at alm.a(PG:3) at wnv.a(PG:2) at com.google.android.finsky.instantapps.PhenotypeUpdateReceiver.onReceive(PG:6) at android.app.ActivityThread.handleReceiver(ActivityThread.java:4308) ... 9 more
原因分析
这个崩溃发生在Google Play的instant_app_installer进程,和你的游戏进程无关。是Google Play Instant Apps组件在后台尝试启动服务,触发了Android 12及以上版本的后台服务启动限制——系统禁止后台应用启动非前台服务,避免不必要的资源消耗。
修复方案
这是Google Play自身的适配问题,无需修改游戏代码:
- 可尝试在Google Play控制台内部测试设置中,关闭Instant Apps相关测试选项;
- 正式发布后该问题大概率会自动消失,也可等待Google修复组件适配漏洞;
- 该崩溃不影响游戏本身运行,无需过度关注。
崩溃问题2:PendingIntent未指定必要标志位(Android 12+适配问题)
错误信息
FATAL EXCEPTION: pool-3-thread-1 Process: com.HefazSofts.AayaanTheRunner, PID: 19257 java.lang.IllegalArgumentException: com.HefazSofts.AayaanTheRunner: Targeting S+ (version 31 and above) requires that one of FLAG_IMMUTABLE or FLAG_MUTABLE be specified when creating a PendingIntent. Strongly consider using FLAG_IMMUTABLE, only use FLAG_MUTABLE if some functionality depends on the PendingIntent being mutable, e.g. if it needs to be used with inline replies or bubbles. at android.app.PendingIntent.checkFlags(PendingIntent.java:375) at android.app.PendingIntent.getBroadcastAsUser(PendingIntent.java:645) at android.app.PendingIntent.getBroadcast(PendingIntent.java:632) at androidx.work.impl.utils.ForceStopRunnable.getPendingIntent(ForceStopRunnable.java:174) at androidx.work.impl.utils.ForceStopRunnable.isForceStopped(ForceStopRunnable.java:108) at androidx.work.impl.utils.ForceStopRunnable.run(ForceStopRunnable.java:86) at androidx.work.impl.utils.SerialExecutor$Task.run(SerialExecutor.java:75) at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1167) at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:641) at java.lang.Thread.run(Thread.java:920)
原因分析
你的游戏目标SDK版本为31(Android 12)及以上,而依赖的androidx.work旧版本创建PendingIntent时未指定FLAG_IMMUTABLE或FLAG_MUTABLE标志位,违反了Android 12+的强制要求,导致崩溃。
修复方案
针对Unity项目,可按以下方式解决:
- 升级androidx.work库版本:确保使用2.7.0及以上版本,该版本已默认给
PendingIntent添加FLAG_IMMUTABLE标志。可通过修改项目gradle配置或Unity Package Manager更新相关Android支持包; - 更新第三方插件:若游戏使用了依赖
androidx.work的插件(如后台任务、推送服务),直接升级插件至最新版本,开发者通常已修复该适配问题; - 手动添加标志位:若无法升级库,可编写Android插件,在创建
PendingIntent时手动指定FLAG_IMMUTABLE(优先推荐,仅需修改PendingIntent内容时才用FLAG_MUTABLE)。
内容的提问来源于stack exchange,提问作者Hefaz
相关产品推荐
相关产品推荐

