You need to enable JavaScript to run this app. 使用flutter_downloader插件下载完成后应用自动崩溃断开Android Studio连接
优惠活动
大模型
产品
解决方案
定价
更多

使用flutter_downloader插件下载完成后应用自动崩溃断开Android Studio连接

集成 flutter_downloader 后下载完成即闪退问题排查

问题场景

  • 应用使用 flutter_downloader 实现PDF文件下载功能
  • 部分文件下载完成后,应用会直接闪退,同时开发设备与IDE的调试连接会中断
  • 核心触发代码如下:
final status = await Permission.storage.request();
if (status.isGranted) {
  await downloadPDF();
} 

downloadPDF() async {
  final externalDir = await getExternalStorageDirectory();
  taskId = await FlutterDownloader.enqueue(
    url: pdfURL,
    savedDir: externalDir.path,
    fileName: "Flamingo Order Details",
    showNotification: true,
    openFileFromNotification: true,
  );
}

控制台原始报错

I/flutter (15913): Fatal: could not find callback
F/libc    (15913): Fatal signal 11 (SIGSEGV), code 1 (SEGV_MAPERR), fault addr 0x0 in tid 15956 (1.raster), pid 15913 (le.order_system)
*** *** *** *** *** *** *** *** *** *** *** *** *** *** *** ***
Build fingerprint: 'motorola/chef/chef_sprout:10/QPTS30.61-18-16-8/03acd:user/release-keys'
Revision: 'pvt'
ABI: 'arm64'
Timestamp: 2021-04-23 16:39:38+0530
pid: 15913, tid: 15956, name: 1.raster  >>> com.example.order_system <<<
uid: 10870
signal 11 (SIGSEGV), code 1 (SEGV_MAPERR), fault addr 0x0
Cause: null pointer dereference
    x0  000000741e5a6478  x1  00000074841cfa00  x2  0000000000000001  x3  0000000000000000
    x4  0000000000000000  x5  00000000ffffffff  x6  00000000ffffffff  x7  0000000b96c6a75c
    x8  0000000080000081  x9  658adf78f7e836ee  x10 0000000000000000  x11 0000000000000000
    x12 0000000000000001  x13 000000747b19fe80  x14 0000007489a0a280  x15 0000000000000000
    x16 000000747b19b050  x17 0000007515c9787c  x18 000000741d05e000  x19 000000741e5a6478
    x20 00000074841cfa00  x21 0000000000000001  x22 0000000000000000  x23 00000074843db380
    x24 000000741e5a7020  x25 000000741e5a7020  x26 0000000000000000  x27 0000000000000001
    x28 0000000000000043  x29 000000741e5a6450
    sp  000000741e5a6420  lr  000000747b013f84  pc  000000747b01c378
backtrace:
      #00 pc 00000000001d8378  /vendor/lib64/egl/libGLESv2_adreno.so (BuildId: 22cc95e0051ae85072c405eeeeeb312d)
      #01 pc 00000000001cff80  /vendor/lib64/egl/libGLESv2_adreno.so (BuildId: 22cc95e0051ae85072c405eeeeeb312d)
      #02 pc 00000000000207b0  /system/lib64/libEGL.so (android::eglSwapBuffersWithDamageKHRImpl(void*, void*, int*, int)+316) (BuildId: 248ba7f2d80e7bb9952a20e1c3493c86)
      #03 pc 000000000001d0a8  /system/lib64/libEGL.so (eglSwapBuffers+80) (BuildId: 248ba7f2d80e7bb9952a20e1c3493c86)
      #04 pc 00000000012ec528  /data/app/com.example.order_system-8XYsushVsEZPOltQ3k8npA==/lib/arm64/libflutter.so (BuildId: e14966237eb013b063fed6484195268f7398b594)
Lost connection to device.

定位思路与解决方案

日志中最早出现的 Fatal: could not find callback 是核心溯源线索,后续图形渲染层的空指针崩溃是插件回调逻辑异常引发的连锁反应

  • 补全插件回调初始化逻辑:在应用入口的 main() 函数中提前完成 flutter_downloader 的回调注册,确保下载状态变更、完成通知等事件能被正常接收,避免插件因找不到可触发的回调通道访问空内存
  • 核对存储路径与权限配置:使用外部存储目录作为下载保存路径时,需要在 AndroidManifest 中完成对应权限声明,适配不同Android版本的分区存储规则,确保插件能正常完成文件写入、路径关联操作
  • 处理通知栏打开文件的逻辑配置:为 openFileFromNotification 参数配套配置对应的文件打开组件,避免插件在尝试唤起文件查看器时访问未初始化的原生对象
  • 排查插件版本兼容问题:旧版本 flutter_downloader 在通知交互场景下会触发Flutter引擎raster线程的图形资源访问异常,升级到经过稳定性验证的插件版本即可规避这类原生层段错误

内容的提问来源于Stack Exchange,提问作者Harsh Sureja

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.10.24 21:36:04