flutter-android-build-triage
Compare original and translation side by side
🇺🇸
Original
English🇨🇳
Translation
ChineseFlutter Android build triage
Flutter Android构建问题排查
Fix a failing Flutter Android build by locating the blame line — the one line in Gradle's wall of output that names the actual culprit (a plugin, a version, a missing symbol, a full disk) — and matching it to the fix table below. Everything above the blame line is noise.
通过定位问题根源行来修复失败的Flutter Android构建——Gradle大量输出中指明实际问题(插件、版本、缺失符号、磁盘已满)的那一行——并匹配下方的修复表。根源行之上的所有内容都是无效信息。
Steps
步骤
- Reproduce and capture. Run the failing build and keep the output:
Completion criterion: you have 10–60 lines containing the blame line — the line that names the missing/incompatible thing.
flutter build apk --debug 2>&1 | grep -B5 -A15 -iE 'what went wrong|error:|caused by|Could not|ENOSPC|No space|license|sdk' | head -60 - Match the blame line to a row in the symptom table and apply that fix. If the line names a native function (e.g. ), it's a packaging problem, not Dart code — see the native-libs row.
sqlite3_initialize - Verify with a clean build: . Completion criterion: output ends with
flutter clean && flutter pub get && flutter build apk --debug.Built build/app/outputs/flutter-apk/app-debug.apk - If Dart APIs changed (e.g. after a package downgrade), fix call sites and re-run +
flutter analyzeuntil both are clean.flutter test
- 复现并捕获输出。运行失败的构建并保存输出:
完成标准:你已获取包含问题根源行的10–60行内容——该行指明了缺失/不兼容的对象。
flutter build apk --debug 2>&1 | grep -B5 -A15 -iE 'what went wrong|error:|caused by|Could not|ENOSPC|No space|license|sdk' | head -60 - 将问题根源行与症状表中的行匹配并应用相应修复。如果该行提到原生函数(如),则属于打包问题,而非Dart代码问题——请查看原生库相关行。
sqlite3_initialize - 通过清理构建验证:。 完成标准:输出以
flutter clean && flutter pub get && flutter build apk --debug结尾。Built build/app/outputs/flutter-apk/app-debug.apk - 如果Dart API发生变更(例如包降级后),修复调用站点并重新运行+
flutter analyze,直到两者都无问题。flutter test
Symptom table
症状表
| Blame line | Diagnosis | Fix |
|---|---|---|
| Flutter template shipped AGP 9.0.1 + Gradle 9.1; some pub plugins (older DSL) are incompatible with AGP 9 | Pin AGP 8.9.1 in |
Plugin error mentioning | Plugin version pinned far too old (no | Upgrade the plugin to a current major ( |
Runtime | | Downgrade to |
| Disk full (often >95%); partially-written caches corrupt | Free space ( |
| Corrupted cache from an earlier ENOSPC/crash | Run |
| 问题根源行 | 诊断结果 | 修复方案 |
|---|---|---|
Gradle中出现 | Flutter模板默认使用AGP 9.0.1 + Gradle 9.1;部分pub插件(旧版DSL)与AGP 9不兼容 | 在 |
插件错误提及 | 插件版本过于陈旧(无 | 将插件升级至最新主版本( |
运行时出现 | | 降级至 |
| 磁盘已满(通常使用率>95%);部分写入的缓存损坏了 | 释放空间( |
中断运行后 | 之前的ENOSPC/崩溃导致缓存损坏 | 运行 |
Reference
参考信息
- Env stack that worked here: AGP 8.9.1 + Gradle 8.14.3, ,
flutter_secure_storage ^10,file_picker ^10+sqlite3 ^2.9, minSdk 23.sqlite3_flutter_libs ^0.5 - A debug APK is ~150MB; installs over wifi adb are slow but fine (300s timeout).
- Check disk pressure before blaming the network: — most "download failed" errors on a full disk are ENOSPC in disguise.
df -h /System/Volumes/Data
- 验证有效的环境栈:AGP 8.9.1 + Gradle 8.14.3,,
flutter_secure_storage ^10,file_picker ^10+sqlite3 ^2.9,minSdk 23。sqlite3_flutter_libs ^0.5 - 调试APK约150MB;通过wifi adb安装速度较慢但可行(超时时间300秒)。
- 在质疑网络问题前先检查磁盘压力:—— 磁盘已满时大多数“下载失败”错误实际上是ENOSPC的伪装。
df -h /System/Volumes/Data