Flutter bugly native崩溃-ALooper_pollOnce

错误日志

#00 pc 000000000006f06c /apex/com.android.runtime/lib64/bionic/libc.so (abort+160)
#01 pc 00000000002c0e1c /data/app/com.jancsinn.label-RzHisDk1xqVVsQQ3ZRWQMQ==/lib/arm64/libflutter.so
#02 pc 00000000002e1238 /data/app/com.jancsinn.label-RzHisDk1xqVVsQQ3ZRWQMQ==/lib/arm64/libflutter.so
#03 pc 00000000002e1b4c /data/app/com.jancsinn.label-RzHisDk1xqVVsQQ3ZRWQMQ==/lib/arm64/libflutter.so
#04 pc 00000000002e31fc /data/app/com.jancsinn.label-RzHisDk1xqVVsQQ3ZRWQMQ==/lib/arm64/libflutter.so
#05 pc 0000000000318ff8 /data/app/com.jancsinn.label-RzHisDk1xqVVsQQ3ZRWQMQ==/lib/arm64/libflutter.so
#06 pc 000000000030b8a0 /data/app/com.jancsinn.label-RzHisDk1xqVVsQQ3ZRWQMQ==/lib/arm64/libflutter.so
#07 pc 0000000000311208 /data/app/com.jancsinn.label-RzHisDk1xqVVsQQ3ZRWQMQ==/lib/arm64/libflutter.so
#08 pc 00000000002e2584 /data/app/com.jancsinn.label-RzHisDk1xqVVsQQ3ZRWQMQ==/lib/arm64/libflutter.so
#09 pc 00000000002e49ec /data/app/com.jancsinn.label-RzHisDk1xqVVsQQ3ZRWQMQ==/lib/arm64/libflutter.so
#10 pc 0000000000017d8c /system/lib64/libutils.so (_ZN7android6Looper9pollInnerEi+856)
#11 pc 0000000000017994 /system/lib64/libutils.so (_ZN7android6Looper8pollOnceEiPiS1_PPv+56)
#12 pc 0000000000013684 /system/lib64/libandroid.so (ALooper_pollOnce+96)
#13 pc 00000000002e4afc /data/app/com.jancsinn.label-RzHisDk1xqVVsQQ3ZRWQMQ==/lib/arm64/libflutter.so
#14 pc 00000000002e1884 /data/app/com.jancsinn.label-RzHisDk1xqVVsQQ3ZRWQMQ==/lib/arm64/libflutter.so
#15 pc 00000000002e359c /data/app/com.jancsinn.label-RzHisDk1xqVVsQQ3ZRWQMQ==/lib/arm64/libflutter.so
#16 pc 00000000000ce1b0 /apex/com.android.runtime/lib64/bionic/libc.so
#17 pc 0000000000070ba8 /apex/com.android.runtime/lib64/bionic/libc.so

分析

全是flutter so报错, 毫无头绪。
仔细看日志,发现两点:

  1. 所有报错的机型cpu架构均为 aarch64
  2. 多条类似日志包含 Looper 信息,怀疑跟flutter looper有关,关键日志如下
    #10 pc 0000000000017d8c /system/lib64/libutils.so (_ZN7android6Looper9pollInnerEi+856)
    #11 pc 0000000000017994 /system/lib64/libutils.so (_ZN7android6Looper8pollOnceEiPiS1_PPv+56)
    #12 pc 0000000000013684 /system/lib64/libandroid.so (ALooper_pollOnce+96)

查找原因

依据这两点google搜索无果。
手动查询github Flutter库issues,
查到如下issue#68687
这个问题中:华为部分机型崩溃,报错日志和我们的报错日志关键信息相同
issue中崩溃原因是因为调用了

io.exit(n)

正好,我们的android app 有一个手动退出的弹窗,也主动调用了dart的 exit(0)用于退出app,遂怀疑也是 退出app时发生了崩溃

验证

找到一部cpu架构是aarch64的华为手机,多次用app中弹窗退出的方式退出app, 过一会儿,发现bugly上报崩溃,崩溃日志相同。

解决方法

因为需求中必须要能主动退出app, 采用channel的方式实现,java中调用exit(0),崩溃不再复现