问题:
最近,我有一个关于android anr的问题,它已经让我困扰了好几天。当webview对象即将创建第一次应用程序第一次运行安装后有时不是每次!!!它发生在Android 4.4及以上版本。
个人分析:
原始问题是,当我尝试初始化第三个sdk时,我的应用程序有时变成了我的应用程序并且我非常确定它不是我的代码导致这一点。我检查了/data/anr/traces.txt
并进行了分析当anr发生时的日志(如下)。
01-14 14:14:38.933 17851-17851/com.xxx.xxx.XXX I/WebViewFactory: Loading com.android.chrome version 55.0.2883.91 (code 288309102)
01-14 14:14:38.964 17851-17851/com.xxx.xxx.XXX I/cr_LibraryLoader: Time to load native libraries: 4 ms (timestamps 8842-8846)
01-14 14:14:38.964 17851-17851/com.xxx.xxx.XXX I/cr_LibraryLoader: Expected native library version number "55.0.2883.91", actual native library version number "55.0.2883.91"
01-14 14:14:38.968 17851-17851/com.xxx.xxx.XXX I/cr_LibraryLoader: Expected native library version number "55.0.2883.91", actual native library version number "55.0.2883.91"
01-14 14:14:38.969 17851-17851/com.xxx.xxx.XXX I/chromium: [INFO:library_loader_hooks.cc(163)] Chromium logging enabled: level = 0, default verbosity = 0
01-14 14:15:40.092 17851-17856/com.xxx.xxx.XXX I/art: Thread[2,tid=17856,WaitingInMainSignalCatcherLoop,Thread*=0xa950d000,peer=0x12c26280,"Signal Catcher"]: reacting to signal 3
01-14 14:15:40.224 17851-17856/com.xxx.xxx.XXX I/art: Wrote stack traces to '/data/anr/traces.txt'
01-14 14:16:45.201 17851-20383/com.xxx.xxx.XXX W/cr_ChildProcLauncher: Create a new ChildConnectionAllocator with package name = com.android.chrome, inSandbox = true
01-14 14:16:45.201 17851-17851/com.xxx.xxx.XXX I/cr_BrowserStartup: Initializing chromium process, singleProcess=false
以下是正常日志。
01-16 14:49:03.641 4032-4032/com.xxx.xxx.XXX I/Timeline: Timeline: Activity_launch_request time:57082043
01-16 14:49:03.932 4032-4032/com.xxx.xxx.XXX I/WebViewFactory: Loading com.google.android.webview version 45.0.2454.95 (code 246109560)
01-16 14:49:04.004 4032-4032/com.xxx.xxx.XXX I/cr.library_loader: Time to load native libraries: 43 ms (timestamps 2362-2405)
01-16 14:49:04.004 4032-4032/com.xxx.xxx.XXX I/cr.library_loader: Expected native library version number "", actual native library version number ""
01-16 14:49:04.018 4032-4032/com.xxx.xxx.XXX V/WebViewChromiumFactoryProvider: Binding Chromium to main looper Looper (main, tid 1) {10aaffa1}
01-16 14:49:04.018 4032-4032/com.xxx.xxx.XXX I/cr.library_loader: Expected native library version number "", actual native library version number ""
01-16 14:49:04.024 4032-4032/com.xxx.xxx.XXX I/chromium: [INFO:library_loader_hooks.cc(121)] Chromium logging enabled: level = 0, default verbosity = 0
01-16 14:49:04.038 4032-4032/com.xxx.xxx.XXX I/cr.BrowserStartup: Initializing chromium process, singleProcess=true
正如我们所看到的那样。应用程序需要将近两分钟的时间来处理铬过程并困住ui线程并最终导致anr。为什么我非常确定导致这个问题的铬是因为我试图删除第三个sdk,在Webview wv = new Webview(this);
onCreate()
MainActivity.java
中新增一个webview对象android system webview
。我仍然得到anr和相同的错误日志。
尝试方式:
google.com
版本恢复到较低版本。它不起作用。google.com
的被阻止的网络。所以我认为它可能会导致问题,我使用的网络代理可以访问#if __IOS__
//your ios specific code
#endif
#if __ANDROID__
//your android specific code
#endif
并且它对我有用。不会发生任何问题更多。结论:
我几乎无能为力。事实上,让我感到困惑的是它似乎是一个非常普遍的问题,但我没有在网络上发现任何相关材料或某些人有同样的问题。任何答案或经验都会有所帮助。