android.os.MessageQueue.nativePollOnce 处的 ANR
我们在应用程序的不同部分看到了此 ANR。 想了解导致此 ANR 的原因吗?
main (native): tid=1 systid=31940
#00 pc 0x5431c libc.so
#01 pc 0x1313a5 libart.so
#02 pc 0x2ab05b libart.so
#03 pc 0x3659 libnativehelper.so
#04 pc 0x9dee9 libandroid_runtime.so
#05 pc 0x65c45 libgui.so
#06 pc 0x11dcd libutils.so
#07 pc 0x11abf libutils.so
#08 pc 0xbcc7d libandroid_runtime.so
at android.os.MessageQueue.nativePollOnce(MessageQueue.java)
at android.os.MessageQueue.next(MessageQueue.java:339)
at android.os.Looper.loop(Looper.java:199)
at android.app.ActivityThread.main(ActivityThread.java:8276)
at java.lang.reflect.Method.invoke(Method.java)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:612)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1006)
这是 firebase 对于此 ANR 的说法 -
发生 ANR 时该线程处于空闲状态。我们没有足够的 确定根本原因的信息。
We are seeing this ANR in different parts of our app.
Wanted to understand what causes this ANR?
main (native): tid=1 systid=31940
#00 pc 0x5431c libc.so
#01 pc 0x1313a5 libart.so
#02 pc 0x2ab05b libart.so
#03 pc 0x3659 libnativehelper.so
#04 pc 0x9dee9 libandroid_runtime.so
#05 pc 0x65c45 libgui.so
#06 pc 0x11dcd libutils.so
#07 pc 0x11abf libutils.so
#08 pc 0xbcc7d libandroid_runtime.so
at android.os.MessageQueue.nativePollOnce(MessageQueue.java)
at android.os.MessageQueue.next(MessageQueue.java:339)
at android.os.Looper.loop(Looper.java:199)
at android.app.ActivityThread.main(ActivityThread.java:8276)
at java.lang.reflect.Method.invoke(Method.java)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:612)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1006)
This is what firebase has to say about this ANR -
This thread was idle when the ANR occurred. We don't have sufficient
information to determine the root cause.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(5)
NativePollOnce:
当CPU等待新任务/消息时出现。
原因:
Ezequiel Adrian 评论)
收集 ANR 的方法:
解决 ANR 的挑战:揭开
ANR 之谜的神秘面纱。 链接
解决方案:
profiler
NativePollOnce:
It appears when the CPU is waiting for a new task/message.
Reasons:
Ezequiel Adrian comment)
Ways to collect ANRs:
Challenges in Solving ANR:
Demystifying the ANRs Puzzle. Link
Solutions:
profiler
面临同样的问题 - 我读到它与 Admob 或统一广告相关,并且 google 有一个开放线程: https://issuetracker.google.com/issues/230950647?pli=1
Facing the same issue - I've read that it related to Admob or unity ads and there is an open thread for google : https://issuetracker.google.com/issues/230950647?pli=1
可能的原因:UI线程被同步屏障阻塞。
如果UI线程的
MessageQueue
有同步屏障,所有消息都会被阻塞(异步消息除外),直到同步屏障已移除。什么会导致此问题?
如果您在非 UI 线程中使视图无效,则可能会遇到此问题。
为什么?
ViewRootImpl
是最顶层的ViewParent
:在
ViewRootImpl
的onDescendantInvalidated
中,它没有检查它是否在 UI 线程中。因此,如果您偶尔在非 UI 线程中
无效
您的视图,您可能会在消息队列中留下同步屏障,而稍后不会被删除,然后您将得到这个 问题。我是否在 ui 线程中
使我的视图无效?
在我的例子中,我向许多视图提供了
BitmapDrawable
,然后我可以更改工作线程中
。这将导致使用 BitmapDrawable 的视图在工作线程中失效。BitmapDrawable
的位图如何检查非 UI 线程中是否有任何视图无效?
在视图层次结构的最顶层
ViewGroup
中,覆盖onDesendantInvalidated
:< strong>问题典型症状
RecyclerView
或ListView
可以正常滚动,但任何视图的点击监听器都不起作用。MessageQueue.nativePollOnce
时发生,BroadcastTimeout
anr 或ServiceTimeout
anr 但不是 KeyDispatchTimeout anrA possible reason: The UI thread was blocked by sync barrier.
If
MessageQueue
of the UI thread has a sync barrier, all messages will be blocked (except asynchronous ones) until the sync barrier removed.What will cause this issue?
If you invalidate your view in a Non-UI thread, you may get this issue.
Why?
ViewRootImpl
is the top-mostViewParent
:Here in
onDescendantInvalidated
ofViewRootImpl
, it didn't check if it's in UI thread.So if you
invalidate
your view in a non-ui thread occasionally, you may leave a sync barrier in the message queue without being removed later and then you will get this issue.Do I
invalidate
my view off ui thread?In my case, I provide
BitmapDrawable
s to many views and then I may change thebitmap
of theBitmapDrawable
in a work thread. This will cause the views using theBitmapDrawable
being invalidated in the work thread.How to check if any views is invalidated in non-ui thread?
In the top-most
ViewGroup
of your view hierarchy, overrideonDescendantInvalidated
:Typical symptoms of the issue
RecyclerView
orListView
can be scrolled normally, but click listeners of any view will not work.MessageQueue.nativePollOnce
BroadcastTimeout
anr or aServiceTimeout
anr but is NOT aKeyDispatchTimeout
anr在最新版本的云消息传递依赖项 v23.0.7 Firebase 上,提及此版本可能会降低 ANR。以下是他在其文档中提到的一句话。
On the latest release of Cloud Messaging dependencies v23.0.7 Firebase Mention that this release might reduce the ANR. here is his words mentioned in its documentation.
就我而言,这是 firebase 云消息传递库中的错误。该错误已在2022年12月8日发布的最新版本23.1.1中修复。
https://firebase.google.com/support/release- Notes/android#messaging_v23-1-1
希望对您有帮助。
In my case, it was an error in the firebase cloud messaging lib. The bug was fixed in the latest version 23.1.1, which was released on 12/8/2022.
https://firebase.google.com/support/release-notes/android#messaging_v23-1-1
Hope it helps you.