活动介绍
file-type

理解与分析Android ANR问题

PDF文件

下载需积分: 13 | 2.16MB | 更新于2024-07-16 | 71 浏览量 | 3 下载量 举报 1 收藏
download 立即下载
"Application-Not-Responding(ANR)-Analyze.pdf 是一份由 MTK (MediaTek) 内部提供的技术文档,主要探讨了 Android 应用程序无响应(ANR)问题的分析和处理。该文档由 Lenovo 的 Wangylh 在2013年8月26日创建。文档内容包括对ANR的定义、关键信息、分析方法、示例、MTK的帮助需求以及关于 Monkey ANR 的讨论。" ANR(Application Not Responding)是Android操作系统中的一个术语,指的是当应用程序在主线程中执行时间过长,无法及时响应用户操作时,系统会弹出一个对话框,告知用户应用未响应。这种情况通常发生在UI线程被阻塞,无法处理触摸事件或者广播接收器在规定时间内未完成工作的情况下。 ANR的类型主要包括以下几种: 1. **Input Event ANR**:当应用程序在5秒内没有处理输入事件(如触摸屏幕)时,系统将触发ANR。 2. **Broadcast Receiver ANR**:如果广播接收者在10秒内未完成其工作,也会引发ANR。 3. **Service ANR**:服务在20秒内没有完成onStartCommand()或onBind()方法,同样会导致ANR。 分析ANR通常涉及以下步骤: 1. **查看ANR日志**:系统会记录ANR事件,并将其保存在设备的/data/anr/traces.txt文件中。这些日志包含了堆栈跟踪信息,可以帮助定位问题所在。 2. **分析堆栈跟踪**:通过分析日志,找出导致主线程阻塞的代码行,这可能是因为长时间运行的计算任务、网络请求、数据库操作或其他阻塞操作。 3. **检查主线程**:确保主线程没有执行耗时的操作,所有可能阻塞的操作应放到子线程中处理。 4. **使用开发者工具**:Android Studio等开发环境提供了强大的调试工具,如Systrace,可以可视化地分析应用程序的性能和线程状态。 在处理ANR时,可能需要MTK的帮助,尤其是当问题与硬件或平台特定的组件有关时。Monkey ANR是指使用Monkey测试工具进行自动化测试时出现的ANR情况,Monkey工具会模拟随机用户输入,从而暴露应用在不同场景下的潜在问题。 解决ANR的关键在于优化应用程序的性能,确保主线程的流畅运行,避免长时间占用主线程资源。这可能需要调整代码结构,使用异步处理,合理安排任务优先级,以及充分理解Android的多线程模型。对于开发者来说,理解和处理ANR至关重要,因为它直接影响到用户的使用体验和对应用的评价。

相关推荐

filetype

D:\Users\Downloads\Log\youtube\bugreport-RMX5313IN-AP3A.240905.015.A2-2025-06-19-11-34-32\bugreport-RMX5313IN-AP3A.240905.015.A2-2025-06-19-11-34-32.txt (155 hits) Line 15125: WINDOW MANAGER LAST ANR (dumpsys window lastanr) Line 116973: ------ VM TRACES AT LAST ANR (/data/anr/anr_2025-06-19-11-19-10-783: 2025-06-19 11:19:18) ------ Line 116973: ------ VM TRACES AT LAST ANR (/data/anr/anr_2025-06-19-11-19-10-783: 2025-06-19 11:19:18) ------ Line 116986: anr < Line 116996: anr < Line 117006: anr < Line 117016: anr < Line 199851: "anrV33-1" prio=5 tid=16 TimedWaiting Line 201580: at anrp.run(PG:35) Line 201676: at anrp.run(PG:35) Line 201731: at anrp.run(PG:35) Line 201752: at anrp.run(PG:35) Line 221720: ------ ANR FILES (ls -lt /data/anr/) ------ Line 221722: -rw------- 1 system system 4661511 2025-06-19 11:19 anr_2025-06-19-11-19-10-783 Line 221723: -rw------- 1 system system 5125123 2025-06-19 11:18 anr_2025-06-19-11-18-28-676 Line 221724: -rw------- 1 system system 5110113 2025-06-19 11:18 anr_2025-06-19-11-17-59-943 Line 221725: -rw------- 1 system system 5170843 2025-06-19 11:15 anr_2025-06-19-11-15-30-180 Line 221726: -rw------- 1 system system 5211710 2025-06-19 11:15 anr_2025-06-19-11-14-59-431 Line 221727: -rw------- 1 system system 5249604 2025-06-19 11:13 anr_2025-06-19-11-13-33-120 Line 221728: -rw------- 1 system system 2550071 2025-06-18 12:01 anr_2025-06-18-12-01-29-071 Line 221729: -rw------- 1 system system 2661757 2025-06-18 12:01 temp_anr_204762592841438826.txt Line 221730: -rw------- 1 system system 4501038 2025-06-18 12:01 anr_2025-06-18-12-00-54-648 Line 221731: -rw------- 1 system system 2790621 2025-06-18 12:00 temp_anr_6131620412329269920.txt Line 221732: -rw------- 1 system system 4774064 2025-06-18 12:00 anr_2025-06-18-12-00-30-005 Line 221733: -rw------- 1 system system 2962603 2025-06-18 12:00 temp_anr_4436968846206332345.txt Line 221734: -rw------- 1 system system 4909259 2025-06-18 12:00 anr_2025-06-18-12-00-06-676 Line 221735: -rw------- 1 system system 5561152 2025-06-18 11:59 anr_2025-06-18-11-59-15-525 Line 221736: -rw------- 1 system system 2486347 2025-06-18 11:58 anr_2025-06-18-11-58-50-107 Line 221737: -rw------- 1 system system 2513502 2025-06-18 11:58 temp_anr_7627520979123128223.txt Line 221738: -rw------- 1 system system 2547664 2025-06-18 11:58 temp_anr_7306873162887901303.txt Line 221739: -rw------- 1 system system 4468182 2025-06-18 11:58 anr_2025-06-18-11-58-19-450 Line 221740: -rw------- 1 system system 5457289 2025-06-18 11:56 anr_2025-06-18-11-56-37-891 Line 221741: -rw------- 1 system system 1325229 2025-06-18 11:54 anr_2025-06-18-11-53-47-163 Line 221742: -rw------- 1 system system 5504454 2025-06-18 11:52 anr_2025-06-18-11-52-01-409 Line 239615: backstage_power/android.app.gate_fgs_timeout_anr_behavior: READ_ONLY + DISABLED (system), DISABLED (device_config) Line 240829: system_performance/com.android.server.utils.anr_timer_freezer: READ_ONLY + DISABLED (system), DISABLED (device_config) Line 240830: system_performance/com.android.server.utils.anr_timer_service: READ_ONLY + DISABLED (system), DISABLED (device_config) Line 259422: service_start_foreground_anr_delay_ms=10000 Line 259437: short_fgs_anr_extra_wait_duration=10000 Line 288694: ACTIVITY MANAGER LAST ANR (dumpsys activity lastanr) Line 300808: importance=400 pss=0.00 rss=0.00 description=bg anr: Input dispatching timed out (Application does not have a focused window). state=empty trace=/data/system/procexitstore/anr_2025-06-18-11-53-47-163.gz Line 300808: importance=400 pss=0.00 rss=0.00 description=bg anr: Input dispatching timed out (Application does not have a focused window). state=empty trace=/data/system/procexitstore/anr_2025-06-18-11-53-47-163.gz Line 307584: importance=230 pss=0.00 rss=347MB description=user request after error: No response to onStartJob state=empty trace=/data/system/procexitstore/anr_2025-06-19-11-19-10-783.gz Line 307588: importance=230 pss=0.00 rss=483MB description=remove task state=empty trace=/data/system/procexitstore/anr_2025-06-19-11-17-59-943.gz Line 307604: importance=230 pss=0.00 rss=452MB description=user request after error: Input dispatching timed out (8b6aa1e com.google.android.youtube/com.google.android.youtube.app.honeycomb.Shell$HomeActivity (server) is not responding. Waited 5001ms for FocusEvent(hasFocus=true)). state=empty trace=/data/system/procexitstore/anr_2025-06-19-11-15-30-180.gz Line 307608: importance=100 pss=0.00 rss=0.00 description=user request after error: Input dispatching timed out (96080e6 com.google.android.youtube/com.google.android.youtube.app.honeycomb.Shell$HomeActivity (server) is not responding. Waited 5000ms for FocusEvent(hasFocus=true)). state=empty trace=/data/system/procexitstore/anr_2025-06-19-11-14-59-431.gz Line 437707: Job Completions com.coloros.gallery3d/com.oplus.gallery.framework.abilities.scan.manager.GalleryScanService: successful_finish(7x) anr(1x) Line 437719: 11 starts, 1 anrs Line 439978: Job Completions @[email protected]/androidx.work.impl.background.systemjob.SystemJobService: unknown:-1(1x) canceled(14x) successful_finish(24x) anr(1x) Line 439989: 15 starts, 6 anrs Line 441158: Job Completions in.mohalla.sharechat/androidx.work.impl.background.systemjob.SystemJobService: canceled(5x) successful_finish(6x) anr(9x) Line 441159: Job Completions in.mohalla.sharechat/com.google.android.datatransport.runtime.scheduling.jobscheduling.JobInfoSchedulerService: successful_finish(3x) anr(6x) Line 473593: backstage_power/android.app.gate_fgs_timeout_anr_behavior=false Line 475571: system_performance/com.android.server.utils.anr_timer_freezer=false Line 475572: system_performance/com.android.server.utils.anr_timer_service=false Line 476935: 2025-06-17 11:36:45 system_app_anr (compressed text, 232873 bytes) Line 476936: 2025-06-17 11:37:09 system_app_anr (compressed text, 201571 bytes) Line 476937: 2025-06-17 11:40:22 system_app_anr (compressed text, 222123 bytes) Line 476938: 2025-06-17 11:41:13 system_app_anr (compressed text, 185557 bytes) Line 476939: 2025-06-17 11:41:38 system_app_anr (compressed text, 241609 bytes) Line 476940: 2025-06-17 11:42:13 system_app_anr (compressed text, 248915 bytes) Line 476941: 2025-06-17 11:54:53 system_app_anr (compressed text, 167694 bytes) Line 476942: 2025-06-17 11:55:43 system_app_anr (compressed text, 190039 bytes) Line 476943: 2025-06-17 11:58:39 system_app_anr (compressed text, 245539 bytes) Line 476944: 2025-06-17 12:17:04 system_app_anr (compressed text, 214445 bytes) Line 476945: 2025-06-17 12:22:01 system_app_anr (compressed text, 241492 bytes) Line 476947: 2025-06-18 11:52:20 system_app_anr (compressed text, 260400 bytes) Line 476948: 2025-06-18 11:54:13 system_app_anr (compressed text, 196046 bytes) Line 476949: 2025-06-18 11:57:01 system_app_anr (compressed text, 245540 bytes) Line 476950: 2025-06-18 11:58:36 system_app_anr (compressed text, 256724 bytes) Line 476951: 2025-06-18 11:58:53 system_app_anr (compressed text, 83697 bytes) Line 476952: 2025-06-18 11:59:29 system_app_anr (compressed text, 255379 bytes) Line 476953: 2025-06-18 12:00:19 system_app_anr (compressed text, 248849 bytes) Line 476959: 2025-06-19 11:13:43 system_app_anr (compressed text, 238808 bytes) Line 476960: 2025-06-19 11:15:08 system_app_anr (compressed text, 236177 bytes) Line 476961: 2025-06-19 11:15:37 system_app_anr (compressed text, 220894 bytes) Line 476962: 2025-06-19 11:18:08 system_app_anr (compressed text, 223886 bytes) Line 476963: 2025-06-19 11:18:36 system_app_anr (compressed text, 218263 bytes) Line 476964: 2025-06-19 11:19:19 system_app_anr (compressed text, 236600 bytes) Line 483662: es_u_anr_count=3 Line 483663: es_u_anr_window_ms=21600000 Line 483780: <0>com.google.android.youtube::anr: Line 483792: <0>in.mohalla.sharechat::anr: Line 483836: <0>com.google.android.apps.subscriptions.red::anr: Line 483844: <0>com.google.android.youtube::anr: Line 483852: <0>com.google.android.googlequicksearchbox::anr: Line 483858: <0>com.android.providers.calendar::anr: Line 483868: <0>com.android.providers.downloads::anr: Line 483876: <0>com.google.android.apps.messaging::anr: Line 483884: <0>com.oplus.sau::anr: Line 483892: <0>com.heytap.market::anr: Line 483900: <0>com.google.android.configupdater::anr: Line 483908: <0>com.google.android.providers.media.module::anr: Line 483916: <0>com.google.android.apps.safetyhub::anr: Line 483924: <0>in.mohalla.sharechat::anr: Line 483932: <0>com.android.vending::anr: Line 483942: <0>com.google.android.adservices.api::anr: Line 483950: <0>android::anr: Line 483958: <0>com.android.launcher3::anr: Line 483966: <0>com.instagram.android::anr: Line 483974: <0>com.google.android.deskclock::anr: Line 483982: <0>com.google.android.as::anr: Line 483990: <0>com.google.android.gm::anr: Line 484000: <0>com.google.android.apps.tachyon::anr: Line 484008: <0>com.google.android.permissioncontroller::anr: Line 484014: <0>com.google.android.setupwizard::anr: Line 484022: <0>com.android.providers.settings::anr: Line 484030: <0>com.facebook.services::anr: Line 484038: <0>com.google.android.as.oss::anr: Line 484046: <0>com.google.android.apps.wellbeing::anr: Line 484054: <0>com.google.android.dialer::anr: Line 484062: <0>com.google.android.apps.nbu.files::anr: Line 484070: <0>com.google.android.apps.docs::anr: Line 484078: <0>com.google.android.apps.maps::anr: Line 484086: <0>com.google.android.webview::anr: Line 484094: <0>com.coloros.weather2::anr: Line 484102: <0>com.google.android.networkstack::anr: Line 484110: <0>com.google.android.rkpdapp::anr: Line 484118: <0>com.google.android.contacts::anr: Line 484126: <0>com.android.chrome::anr: Line 484134: <0>com.nearme.gamecenter::anr: Line 484142: <0>com.nearme.statistics.rom::anr: Line 484150: <0>com.google.android.gms::anr: Line 484158: <0>com.google.android.tts::anr: Line 484166: <0>com.google.android.apps.walletnfcrel::anr: Line 484174: <0>com.google.android.partnersetup::anr: Line 484182: <0>com.google.android.videos::anr: Line 484190: <0>com.coloros.lockassistant::anr: Line 484200: <0>com.google.android.apps.photos::anr: Line 484208: <0>com.google.android.calendar::anr: Line 484218: <0>com.facebook.katana::anr: Line 484226: <0>com.coloros.phonemanager::anr: Line 484234: <0>com.android.imsserviceentitlement::anr: Line 484242: <0>com.android.settings::anr: Line 484250: <0>com.fitbit.FitbitMobile::anr: Line 484258: <0>com.grofers.customerapp::anr: Line 484266: <0>com.myntra.android::anr: Line 484274: <0>com.google.android.apps.turbo::anr: Line 484282: <0>com.oplus.lfeh::anr: Line 484288: <0>com.google.android.apps.carrier.carrierwifi::anr: Line 484298: <0>com.oppo.quicksearchbox::anr: Line 484306: <0>com.google.android.apps.youtube.music::anr: Line 484314: <0>com.facebook.appmanager::anr: Line 484322: <0>com.coloros.gallery3d::anr: Line 484330: <0>com.snapchat.android::anr: Line 484340: <0>com.google.android.inputmethod.latin::anr: Line 484348: <0>com.glance.internet::anr: Line 484354: <0>com.google.android.apps.restore::anr: Line 484363: Category{anr}: 3 events in +6h0m0s0ms Line 506990: 4x unknown:-1, 38x canceled, 82x successful_finish, 1x anr Line 544392: com.unisoc.traceur.anrstartdumpperfetto: Line 546673: com.unisoc.traceur.anrsavedumpperfetto: Line 708996: _id:585 name:anr_show_background pkg:com.android.settings value:0 default:0 defaultSystemSet:true Line 709073: _id:275 name:dropbox:data_app_anr pkg:com.google.android.gms value:disabled Line 709643: setting: anr_show_background generation:2

filetype

2025-07-18 09:37:24.226 1425-1425 vendor.qti...al-service ven...qti.hardware.perf-hal-service E ExtendedPerfBoost: extended_perfboost_verification() 738: Ok, set boost params. hintid=4225 hinttype=1 prio=3, clientpid=2569 packagename=com.example.text params=boost:1 cpu0:1804800 cpu4:2496000 cpu7:2592000 cpumask:ff 2025-07-18 09:37:24.248 20986-20986 Zygote usap64 E process_name_ptr:20986 com.example.text 2025-07-18 09:37:24.319 27603-3228 SuggestManager com.miui.securitycenter.remote E openApp name = com.example.text 2025-07-18 09:37:24.327 4285-5371 ActivityManagerWrapper com.miui.home E getRecentTasks: mainTaskId=10282 userId=0 windowMode=1 baseIntent=Intent { act=android.intent.action.MAIN flag=268435456 cmp=ComponentInfo{com.example.text/com.example.text.MainActivity} } 2025-07-18 09:37:24.335 27603-13357 AntiFraud com.miui.securitycenter.remote E hookDetectUnsafeAppStart error, android.content.pm.PackageManager$NameNotFoundException: com.example.text at android.app.ApplicationPackageManager.getApplicationInfoAsUser(ApplicationPackageManager.java:515) at android.app.ApplicationPackageManager.getApplicationInfo(ApplicationPackageManager.java:498) at android.app.ApplicationPackageManager.getApplicationInfo(ApplicationPackageManager.java:492) at w2.b.f(Unknown Source:12) at w2.b$c.onForegroundInfoChanged(Unknown Source:21) at com.miui.gamebooster.mutiwindow.b$a.onForegroundInfoChanged(Unknown Source:152) at miui.process.IForegroundInfoListener$Stub.onTransact(IForegroundInfoListener.java:86) at android.os.Binder.execTransactInternal(Binder.java:1351) at android.os.Binder.execTransact(Binder.java:1282) 2025-07-18 09:37:24.337 8279-10833 SuggestManager com.miui.securitycenter.remote E openApp name = com.example.text ---------------------------- PROCESS STARTED (20986) for package com.example.text ----------------------------