谷歌aab包在Android 14闪退而apk没问题(targetsdk 34)

问题原因

Unity应用(target SDK 34)上线到GooglePlay,有用户反馈fold5设备上(Android14系统)疯狂闪退,经测试,在小米手机Android14系统的版本复现成功了,奇怪的是apk直接安装没问题,而打包成aab就是疯狂闪退。

Unity版本Unity2020.3.18f1c1。

老办法,logcat抓包,看看闪退日志。

日志有一行引起了我的注意,也就是在闪退前的报错:

No pending exception expected: java.lang.SecurityException: com.xxx.xxx: One of RECEIVER_EXPORTED or RECEIVER_NOT_EXPORTED should be specified when a receiver isn't being registered exclusively for system broadcasts

既然有错误,就好解决了,现在问ChatGPT没用的,因为ChatGPT经常会瞎编,所以上谷歌搜索下,立马就搜到了。 android - One of RECEIVER_EXPORTED or RECEIVER_NOT_EXPORTED should be specified when a receiver isn't being registered exclusively for system broadcasts - Stack Overflow

 As discussed at Google I/O 2023, registering receivers with intention using the RECEIVER_EXPORTED / RECEIVER_NOT_EXPORTED flag was introduced as part of Android 13 and is now a requirement for apps running on Android 14 or higher (U+).

If you do not implement this, the system will throw a security exception.

To allow the broadcast receiver to receive broadcasts from other apps, register the receiver using the following code:

context.registerReceiver(broadcastReceiver, intentFilter, RECEIVER_EXPORTED);

To register a broadcast receiver that does not receive broadcasts from other apps, including system apps, register the receiver using the following code:

context.registerReceiver(broadcastReceiver, intentFilter, RECEIVER_NOT_EXPORTED);

Note: That call will need minSdkVersion to be 26 (Android 8) al least

Check https://www.delasign.com/blog/android-studio-kotlin-broadcast-recievers-export-or-not/#:~:text=As%20discussed%20at%20Google%20I,will%20throw%20a%20security%20exception.

翻译过来就是,Goole I/O 2023讨论的,使用RECEIVER_EXPORTED / RECEIVER_NOT_EXPORTED标志注册接收者是Android 13的一部分,现在是运行在Android 14或更高版本(U+)上的应用程序的要求。也就是Android14必须增加该标志。

以前使用registerReceiver不需要设置RECEIVER_EXPORTED / RECEIVER_NOT_EXPORTED这个Flag,现在Android14开始需要设置了,所以抛异常,闪退了。

解决思路

问题找到了,也分析好了,但是因为这是Unity工程直接打包出来的aab,像是一个黑箱,而问题就是Unity打包出来写的registerReceiver没有按照Android14的要求传进去Flag,这个我们可以通过日志确定,可以看到堆栈日志显示com.unity3d.player.PlayAssetDeliveryUnityWrapper.registerDownloadStatusListener这个类注册的Receiver,而这个是Unity的类,无法修改。

2024-01-12 17:45:50.379 6394-6494/? A/ongame.isoland4: thread.cc:2529] No pending exception expected: java.lang.SecurityException: com.cottongame.isoland4: One of RECEIVER_EXPORTED or RECEIVER_NOT_EXPORTED should be specified when a receiver isn't being registered exclusively for system broadcasts
    thread.cc:2529]   at java.lang.Exception android.os.Parcel.createExceptionOrNull(int, java.lang.String) (Parcel.java:3057)
    thread.cc:2529]   at java.lang.Exception android.os.Parcel.createException(int, java.lang.String) (Parcel.java:3041)
    thread.cc:2529]   at void android.os.Parcel.readException(int, java.lang.String) (Parcel.java:3024)
    thread.cc:2529]   at void android.os.Parcel.readException() (Parcel.java:2966)
    thread.cc:2529]   at android.content.Intent android.app.IActivityManager$Stub$Proxy.registerReceiverWithFeature(android.app.IApplicationThread, java.lang.String, java.lang.String, java.lang.String, android.content.IIntentReceiver, android.content.IntentFilter, java.lang.String, int, int) (IActivityManager.java:6193)
    thread.cc:2529]   at android.content.Intent android.app.ContextImpl.registerReceiverInternal(android.content.BroadcastReceiver, int, android.content.IntentFilter, java.lang.String, android.os.Handler, android.content.Context, int) (ContextImpl.java:1863)
    thread.cc:2529]   at android.content.Intent android.app.ContextImpl.registerReceiver(android.content.BroadcastReceiver, android.content.IntentFilter, java.lang.String, android.os.Handler) (ContextImpl.java:1803)
    thread.cc:2529]   at android.content.Intent android.app.ContextImpl.registerReceiver(android.content.BroadcastReceiver, android.content.IntentFilter) (ContextImpl.java:1791)
    thread.cc:2529]   at android.content.Intent android.content.ContextWrapper.registerReceiver(android.content.BroadcastReceiver, android.content.IntentFilter) (ContextWrapper.java:766)
    thread.cc:2529]   at void com.google.android.play.core.listener.b.b() ((null):-1)
    thread.cc:2529]   at void com.google.android.play.core.listener.b.f(com.google.android.play.core.listener.StateUpdatedListener) ((null):-1)
    thread.cc:2529]   at void com.google.android.play.core.assetpacks.i.registerListener(com.google.android.play.core.assetpacks.AssetPackStateUpdateListener) ((null):-1)
    thread.cc:2529]   at java.lang.Object com.unity3d.player.a.a(com.unity3d.player.IAssetPackManagerDownloadStatusCallback) ((null):-1)
    thread.cc:2529]   at java.lang.Object com.unity3d.player.PlayAssetDeliveryUnityWrapper.registerDownloadStatusListener(com.unity3d.player.IAssetPackManagerDownloadStatusCallback) ((null):-1)
    thread.cc:2529]   at boolean com.unity3d.player.UnityPlayer.nativeRender() ((null):-2)
    thread.cc:2529]   at boolean com.unity3d.player.UnityPlayer.access$300(com.unity3d.player.UnityPlayer) ((null):-1)
    thread.cc:2529]   at boolean com.unity3d.player.UnityPlayer$e$1.handleMessage(android.os.Message) ((null):-1)
    thread.cc:2529]   at void android.os.Handler.dispatchMessage(android.os.Message) (Handler.java:102)
    thread.cc:2529]   at boolean android.os.Looper.loopOnce(android.os.Looper, long, int) (Looper.java:224)
    thread.cc:2529]   at void android.os.Looper.loop() (Looper.java:318)
    thread.cc:2529]   at void com.unity3d.player.UnityPlayer$e.run() ((null):-1)
    thread.cc:2529] 

解决

目前解决方案是targetsdk改成33,经测试就不闪退了。

如果你需要targetsdk为34,得升级下Unity版本,看看哪个版本修复了这个问题。我们的版本是Unity2020.3.18f1c1。查了3.19的Release Note没有找到相关的修复,懒得找了。

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.hqwc.cn/news/344697.html

如若内容造成侵权/违法违规/事实不符,请联系编程知识网进行投诉反馈email:809451989@qq.com,一经查实,立即删除!

相关文章

【算法】信使(最短路问题)

题目 战争时期,前线有 n 个哨所,每个哨所可能会与其他若干个哨所之间有通信联系。 信使负责在哨所之间传递信息,当然,这是要花费一定时间的(以天为单位)。 指挥部设在第一个哨所。 当指挥部下达一个命令…

详细分析Java中的@Transactional注解

目录 前言1. 基本知识2. 常用属性3. Demo4. 总结 前言 Transactional 是 Spring 框架中用于管理事务的注解。 该注解来源于Spring,对于Spring的基础知识可看我之前的文章: Spring框架从入门到学精(全) 该注解也可用在xxl-job框架…

redis夯实之路-哨兵(Sentinel)机制详解

Sentinel(哨兵)保证了redis的高可用性,一个Sentinel或多个Sentinel组成的系统监视多个主从服务器,当主服务器下线时,自动将一个从服务器升级为主服务器。 sentinel的主要功能 集群监控:负责监控redis mas…

Ubuntu root 远程登录失败

背景:设置了两个系统用户:root、test;test可以登录,可以使用su 命令切换root用户登录成功; 但是直接用root登录,会报错。 查看登录日志的方法: 需要两个远程窗口,在第一个远程窗口…

Komodor:Kubernetes 监控工具全面指南

为了方便起见,Komodor 提供了一个简单的 Web 界面,以帮助您监控 Kubernetes 集群的状态。它拥有付费和免费增值计划,除了在出现问题时通知用户外,还拥有一系列方便的工具,用于跟踪和管理集群中部署的资源的状态。让我们…

Smallpdf扫描、转换、压缩、编辑、签名PDF

【应用名称】:Smallpdf: 扫描、转换、压缩、编辑、签名PDF 【适用平台】:#Android 【软件标签】:#Smallpdf 【应用版本】:1.71.0 【应用大小】:150MB 【软件说明】:通过 Smallpdf,您可以&…

c#多线程中使用SemaphoreSlim

SemaphoreSlim是一个用于同步和限制并发访问的类,和它类似的还有Semaphore,只是SemaphoreSlim更加的轻量、高效、好用。今天说说它,以及如何使用,在什么时候去使用,使用它将会带来什么优势。 代码的业务是&#xff1a…

一元线性回归模型(公式推导+举例应用)

文章目录 引言模型表达式均方误差和优化目标最小二乘法利用协方差和方差求解 k k k和 b b b结论实验分析 引言 一元线性回归是回归分析中简单而重要的一种模型,旨在找到一条直线,以最佳方式拟合输入变量与输出变量之间的关系。在这篇文章中,…

2024年AMC8往年真题练一练和答案详解(6),还有全真模拟题

今天是1月13日,2024年AMC8正式比赛已经倒计时了,昨天AMC主办方给所有参赛选手发了短信通知,关于模拟竞赛的操作方式和实际比赛的要求指南,大家一定要认真阅读,严格按指南操作,六分成长也会详细为大家解读和…

电脑/设备网络共享给其他设备上网

文章目录 一、概述二、设置网络共享2.1 电脑可以上网,通过网络共享让其他设备也可以上网2.2 手机如何使用USB数据线共享网络给电脑 一、概述 现在有如下几种情况: 设备本身不能上网,需要通过电脑上网 笔记本WIFI连热点上网,然后…

MySQL夯实之路-存储引擎深入浅出

innoDB Mysql4.1以后的版本将表的数据和索引放在单独的文件中 采用mvcc来支持高并发,实现了四个标准的隔离级别,默认为可重复读,并且通过间隙锁(next-key locking)策略防止幻读(查询的行中的间隙也会锁定…

Jenkins安装和配置

拉取Jenkins镜像 docker pull jenkins/jenkins 编写jenkins_docker.yml version: "3.1" services:jenkins:image: jenkins/jenkinscontainer_name: jenkinsports:- 8080:8080- 50000:50000volumes:- ./data/:/var/jenkins_home/首次启动会因为数据卷data目录没有权限…