谷歌aab包在Android 14闪退而apk没问题

发布时间:2024年01月12日

问题原因

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

老办法,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必须增加该标志。

解决

如何增加呢?在Activity里加上这句话即可,这样就不会抛出异常了。

context.registerReceiver(broadcastReceiver, intentFilter, RECEIVER_EXPORTED);
context.registerReceiver(broadcastReceiver, intentFilter, RECEIVER_NOT_EXPORTED);

文章来源:https://blog.csdn.net/egostudio/article/details/135556322
本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。