我试图通过加载简单的URL(例如:在www.google.com中使用搜索(在webView中键入。然后我的应用程序突然强制关闭,并在logcat中发现以下错误:
2020-12-03 09:51:52.971 1952-1994/? E/ActivityManager: ANR in com.example.dev
PID: 15463
Reason: Input dispatching timed out (InputMethod, Waiting to send non-key event because the touched window has not finished processing certain input events that were delivered to it over 500.0ms ago. Wait queue length: 1. Wait queue head age: 8139.8ms.)
Load: 8.15 / 8.47 / 6.62
CPU usage from 0ms to 8150ms later (2020-12-03 09:51:44.750 to 2020-12-03 09:51:52.900):
14% 1952/system_server: 7.4% user + 7.4% kernel / faults: 7633 minor 8 major
13% 15463/com.example.dev: 8.3% user + 4.9% kernel / faults: 6864 minor 1 major
2.1% 1158/media.codec: 1.5% user + 0.5% kernel / faults: 31058 minor
8% 3217/cnss_diag: 6.7% user + 1.3% kernel
4.5% 15559/com.google.android.webview:sandboxed_process0:org.chromium.content.app.SandboxedProcessService0:0: 3.9% user + 0.6% kernel / faults: 892 minor
0% 1183/media.swcodec: 0% user + 0% kernel / faults: 10006 minor
0% 5046/com.google.android.inputmethod.latin: 0% user + 0% kernel / faults: 3681 minor
0.4% 154/kswapd0: 0% user + 0.4% kernel
2% 758/surfaceflinger: 1.1% user + 0.9% kernel / faults: 621 minor
2% 2482/com.android.phone: 1.1% user + 0.9% kernel / faults: 1926 minor
2% 5358/kworker/u16:15: 0% user + 2% kernel
1.5% 725/android.hardware.wifi@1.0-service: 1.5% user + 0% kernel / faults: 33 minor
1.4% 6/kworker/u16:0: 0% user + 1.4% kernel
1.4% 449/mmc-cmdqd/0: 0% user + 1.4% kernel
0.2% 1098/media.extractor: 0.1% user + 0% kernel / faults: 3943 minor
1.4% 1197/kworker/u16:14: 0% user + 1.4% kernel
1.4% 15107/com.microsoft.teams: 0.9% user + 0.4% kernel / faults: 2184 minor 5 major
1.2% 3188/adbd: 0% user + 1.2% kernel / faults: 3 minor
0.1% 16114/com.google.android.apps.turbo: 0.1% user + 0% kernel / faults: 1780 minor 1 major
0.8% 591/logd: 0.1% user + 0.7% kernel / faults: 19 minor
0.7% 443/cfinteractive: 0% user + 0.7% kernel
0.7% 3242/irq/61-1008000.: 0% user + 0.7% kernel
0.6% 1/init: 0.3% user + 0.2% kernel / faults: 111 minor
0.6% 715/android.hardware.graphics.composer@2.1-service: 0.1% user + 0.4% kernel / faults: 192 minor
0.6% 2328/scheduler_threa: 0% user + 0.6% kernel
0.4% 290/kgsl_worker_thr: 0% user + 0.4% kernel
0% 1212/tombstoned: 0% user + 0% kernel / faults: 38 minor
0.4% 2173/com.android.bluetooth: 0.1% user + 0.3% kernel / faults: 187 minor
0.4% 4030/com.google.android.gms: 0.3% user + 0.1% kernel / faults: 274 minor
0.3% 79/smem_native_rpm: 0% user + 0.3% kernel
0.3% 721/android.hardware.sensors@1.0-service: 0.1% user + 0.2% kernel / faults: 147 minor
0.3% 14780/kworker/0:2: 0% user + 0.3% kernel
0.3% 16010/logcat: 0.3% user + 0% kernel
0.2% 7/rcu_preempt: 0% user + 0.2% kernel
0.2% 113/kworker/u17:0: 0% user + 0.2% kernel
0% 707/android.hardware.camera.provider@2.4-service: 0% user + 0% kernel / faults: 52 minor
0.2% 1026/jbd2/dm-2-8: 0% user + 0.2% kernel
0% 1070/zygote: 0% user + 0% kernel / faults: 57 minor
0.2% 1103/netd: 0.1% user + 0.1% kernel / faults: 141 minor 8 major
0.2% 1157/wificond: 0% user + 0.2% kernel
0.2% 1346/msm_irqbalance: 0.1% user + 0.1% kernel / faults: 24 minor
0.2% 2194/com.android.systemui: 0.2% user + 0% kernel / faults: 196 minor
0% 8/rcu_sched: 0% user + 0% kernel
0.1% 10/rcuop/0: 0% user + 0.1% kernel
0.1% 18/rcuop/1: 0% user + 0.1% kernel
0.1% 25/rcuop/2: 0% user + 0.1% kernel
0% 33/rcuos/3: 0% user + 0% kernel
0.1% 39/rcuop/4: 0% user + 0.1% kernel
0% 40/rcuos/4: 0% user + 0% kernel
0% 53/rcuop/6: 0% user + 0% kernel
0% 54/rcuos/6: 0% user + 0% kernel
0% 81/kworker/4:1: 0% user + 0% kernel
0.1% 116/kworker/u17:1: 0% user + 0.1% kernel
0% 215/hwrng: 0% user + 0% kernel
0.1% 580/ueventd: 0.1% user + 0% kernel / faults: 11 minor
0.1% 593/hwservicemanager: 0.1% user + 0% kernel / faults: 55 minor
0% 595/android.hardware.keymaster@4.0-service-qti: 0% user + 0% kernel / faults: 60 minor
0.1% 705/android.system.suspend@1.0-service: 0.1% user + 0% kernel / faults: 1 minor
0.1% 714/android.hardware.graphics.allocator@2.0-service: 0% user + 0.1% kernel
我的发现:
- 此错误仅发生在我开始打开键盘并在webView中键入时,其他菜单或功能没有问题
- 在我的自定义键盘上使用不同的应用程序,打开webView并在其中输入是有效的,所以我认为我的webView有问题
知道是什么导致了这个错误吗?以及如何找到根本原因?或任何解决方案来解决这个问题
已解决
由于我的自定义键盘与WebView在同一进程中(因为它仍在相同的应用程序中(,主线程中的多个进程导致了问题。我正在尝试使用一个具有更好RAM和CPU的高端设备,我发现它可以从强制关闭中幸存下来,但仍然有一个滞后的打字回调,所以我在日志中尽量减少了这种警告的可能性:
2020-12-03 14:41:48.700 23019-23019/com.example.dev W/InputConnectionWrapper.ICC: Timed out waiting on IInputContextCallback
2020-12-03 14:41:48.745 23019-23019/com.example.dev I/Choreographer: Skipped 239 frames! The application may be doing too much work on its main thread.
针对这个问题,我发现另一个开发人员也遇到了类似的问题请参阅:在安卓上使用自定义键盘等待IInputContextCallback时超时
因此,解决方案是通过添加属性android:process=":processname"
,在我的自定义键盘和打开的WebView之间创建一个单独的进程
(进程名称可以是任何内容,引用:https://developer.android.com/guide/topics/manifest/activity-element)
在我的情况下,我选择我的键盘服务作为单独的过程,问题消失了
Android中的ANR(应用程序未响应(错误发生在应用程序的UI线程被长时间阻塞时,因为应用程序无法及时响应输入事件或运行BroadCastReceivers。为输入事件触发ANR的超时时间为5秒。这可能是由于UI线程中执行的阻塞调用(如与网络相关的请求或文件系统访问(,或者是由于代码中的某些死锁。
此链接提供有关如何调试ANR的信息https://developer.android.com/topic/performance/vitals/anr
如果你的电脑上安装了带有SDK平台工具的adb,你可以使用root访问权限从设备/模拟器中提取ANR跟踪文件。另一种方法是从包含ANR跟踪的设备中获取错误报告。跟踪将在ANR时提供应用程序中所有线程的堆栈跟踪。通过此操作,您可以识别阻塞调用/死锁。
要提取ANR跟踪文件(需要root访问权限(
adb root
adb pull /data/anr .
或者收集错误报告
adb bugreport
如果没有root访问权限,请使用"设置"UI中的"开发人员选项"进行错误报告。
所有这些和其他调试方法都在上面的Android开发者网站链接中进行了解释。