升级后立即夸大正在进行的通知布局时崩溃.仅Android 10 [英] Crash while inflating ongoing-notification layout right after upgrade. Android 10 only

查看:165
本文介绍了升级后立即夸大正在进行的通知布局时崩溃.仅Android 10的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

几个月前,它突然开始发生了.仅限Android 10.

It started to happen out of the blue a couple of months ago. Android 10 only.

用户升级到我们的应用程序的新版本后,启动时发生崩溃.

After the user upgrades to a new version of our app, a crash happens on launch.

对于给定的用户,该崩溃仅观察一次.因此,我们认为崩溃是在升级到新版本后立即发生的.崩溃的是新版本(而不是旧版本).

The crash is only observed once for a given user. So we think the crash happens right after the upgrade to the new build. It is the new build that crashes (not the old one).

这是当机的例子.

Fatal Exception: android.app.RemoteServiceException: Bad notification(tag=null, id=30) posted from package yo.app, 
crashing app(uid=10613, pid=16365): 
Couldn't inflate contentViewsandroid.view.InflateException: Binary XML file line #19 in yo.app:layout/sky_eraser_main: 
Binary XML file line #19 in yo.app:layout/sky_eraser_main: Error inflating class androidx.appcompat.widget.Toolbar
       at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2052)
       at android.os.Handler.dispatchMessage(Handler.java:107)
       at android.os.Looper.loop(Looper.java:214)
       at android.app.ActivityThread.main(ActivityThread.java:7710)
       at java.lang.reflect.Method.invoke(Method.java)
       at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:516)
       at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:950)

崩溃因构建而异.但是模式是一样的.

The crashes look different from build to build. But the pattern is the same.

让我抄录我们认为正在发生的事情.

Let me transcribe what is happening in our opinion.

有一个持续的通知(id = 30)显示温度(我们正在制作天气应用).由于膨胀了RemoteViews布局时发生崩溃,该通知无法发布.

There is an ongoing notification (id=30) displaying the temperature (we are making a weather app). The notification is not able to post because of a crash while inflating its RemoteViews layout.

似乎原来的布局已被另一个替换,完全无关的布局(在我们应用的其他位置使用了sky_eraser_main).错误的布局因构建而异.似乎整数布局ID混杂在一起.难道是R8进行了一些奇怪的优化的结果?

It seems that the original layout is substituted by another, completely unrelated layout (sky_eraser_main used in another place of our app). The wrong layout is different from build to build. It looks as though integer layout-ids are getting mixed up. Could it be the result of some weird R8 optimisation?

很遗憾,我们无法在本地重现崩溃.

Unfortunately, we are not able to reproduce the crash locally.

您是否有解决这些崩溃的想法?

Do you have an idea how to tackle these crashes?

上下文

  • 目标SDK:30
  • 已部署为Android应用包.
  • minifyEnabled = true
  • 这是一个kotlin跨平台项目.

推荐答案

根据您的解释,资源引用似乎随着应用程序启动而更新.这个人有同样的问题

From what you've been explaining looks like the resource references got updated as the app launches. This guy has the same problem

从本质上讲, R 类是整个Android Studio构建系统自动生成的类,每当您添加,删除和编辑资源文件时,该类都会自动生成.在一天结束时,最后"字段中的每个字段都将保留下来. R 类(可绘制,id,布局等)保存一个int值.出于某些未知的未知原因,在您对Android 10(以及很可能在Android 11或Android的某些其他依赖供应商的实现)中进行更新后首次启动该应用程序时,这些引用也会得到更新.

Essentially, the R class is an autogenerated class by the whole Android Studio build system that gets autogenerated whenever you add, remove and edit resource files. At the end of the day, each field of the "final" R classes (drawable, id, layout, etc.) hold an int value. And for some dark unknown reasons those references are getting updated at the time you first launch the app after an update on Android 10, (and very probably in Android 11 or some other vendor-dependant implementations of Android)

根据他的回答中的评论部分(超过100个),投票似乎没有解决方法.如果设法捕获任何异常,我将尝试 try-catch 布局的膨胀并中止通知.

And as per the comment section in his answer (100+) votes doesn't seem to have a fix. I would try to try-catch the inflation of the layout and abort the notification if I manage to catch any exceptions.

另一种方法是使用 WorkManager 之类的方法来延迟通知的启动,以确保在 NotifyWork 插入之前,引用已被更新

Another approach would be to delay the launch of the notification using something like WorkManager to ensure that the references got updated by the time the NotifyWork kicks in

这篇关于升级后立即夸大正在进行的通知布局时崩溃.仅Android 10的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆