Flutter踩坑中

优点

1、网上随处可见的就不再赘述了,我最受益的就是 比Compose更快的及时刷新,我可以在我的Android设备上以最短的延迟见到我写的界面

槽点

1、插件对Android GRADLE和AGP 版本的向下兼容不好,易出现如下

csharp 复制代码
A failure occurred while executing com.android.build.gradle.internal.tasks.CheckAarMetadataWorkAction
  > 3 issues were found when checking AAR metadata:

      1.  Dependency 'androidx.browser:browser:1.9.0' requires Android Gradle plugin 8.9.1 or higher.

          This build currently uses Android Gradle plugin 8.7.3.

此时有两个选择,第一是升级AGP ,风险是引发其他插件问题,第二选择是逐个尝试插件的版本 ,如果该插件(此时我用的是url_launcher) 每个低版本都不能适配我的Android环境,那么我可能只能改为第一个选择了。

2、问题1 我选择了第一方案后 ,重新编译工程是小时级别的了 ,gradle文件都在本地 ,不知道他在下载什么

agsl 复制代码
Flutter assets will be downloaded from https://storage.flutter-io.cn. Make sure you trust this source!
Flutter assets will be downloaded from https://storage.flutter-io.cn. Make sure you trust this source!
Font asset "td_icons.ttf" was tree-shaken, reducing it from 367144 to 1536 bytes (99.6% reduction). Tree-shaking can be disabled by providing the --no-tree-shake-icons flag when building your app.
Font asset "MaterialIcons-Regular.otf" was tree-shaken, reducing it from 1645184 to 2160 bytes (99.9% reduction). Tree-shaking can be disabled by providing the --no-tree-shake-icons flag when building your app.

FAILURE: Build failed with an exception.

* What went wrong:
Execution failed for task ':app:mergeReleaseNativeLibs'.
> Could not resolve all files for configuration ':app:releaseRuntimeClasspath'.
   > Failed to transform armeabi_v7a_release-1.0.0-e4b8dca3f1b4ede4c30371002441c88c12187ed6.jar (io.flutter:armeabi_v7a_release:1.0.0-e4b8dca3f1b4ede4c30371002441c88c12187ed6) to match attributes {artifactType=android-jni, org.gradle.category=library, org.gradle.libraryelements=jar, org.gradle.status=release, org.gradle.usage=java-runtime}.
      > Could not download armeabi_v7a_release-1.0.0-e4b8dca3f1b4ede4c30371002441c88c12187ed6.jar (io.flutter:armeabi_v7a_release:1.0.0-e4b8dca3f1b4ede4c30371002441c88c12187ed6)
         > Could not get resource 'https://storage.flutter-io.cn/download.flutter.io/io/flutter/armeabi_v7a_release/1.0.0-e4b8dca3f1b4ede4c30371002441c88c12187ed6/armeabi_v7a_release-1.0.0-e4b8dca3f1b4ede4c30371002441c88c12187ed6.jar'.
            > Read timed out
   > Failed to transform arm64_v8a_release-1.0.0-e4b8dca3f1b4ede4c30371002441c88c12187ed6.jar (io.flutter:arm64_v8a_release:1.0.0-e4b8dca3f1b4ede4c30371002441c88c12187ed6) to match attributes {artifactType=android-jni, org.gradle.category=library, org.gradle.libraryelements=jar, org.gradle.status=release, org.gradle.usage=java-runtime}.
      > Could not download arm64_v8a_release-1.0.0-e4b8dca3f1b4ede4c30371002441c88c12187ed6.jar (io.flutter:arm64_v8a_release:1.0.0-e4b8dca3f1b4ede4c30371002441c88c12187ed6)
         > Could not get resource 'https://storage.flutter-io.cn/download.flutter.io/io/flutter/arm64_v8a_release/1.0.0-e4b8dca3f1b4ede4c30371002441c88c12187ed6/arm64_v8a_release-1.0.0-e4b8dca3f1b4ede4c30371002441c88c12187ed6.jar'.
            > Premature end of Content-Length delimited message body (expected: 38,957,021; received: 3,440,640)
   > Failed to transform x86_64_release-1.0.0-e4b8dca3f1b4ede4c30371002441c88c12187ed6.jar (io.flutter:x86_64_release:1.0.0-e4b8dca3f1b4ede4c30371002441c88c12187ed6) to match attributes {artifactType=android-jni, org.gradle.category=library, org.gradle.libraryelements=jar, org.gradle.status=release, org.gradle.usage=java-runtime}.
      > Could not download x86_64_release-1.0.0-e4b8dca3f1b4ede4c30371002441c88c12187ed6.jar (io.flutter:x86_64_release:1.0.0-e4b8dca3f1b4ede4c30371002441c88c12187ed6)
         > Could not get resource 'https://storage.flutter-io.cn/download.flutter.io/io/flutter/x86_64_release/1.0.0-e4b8dca3f1b4ede4c30371002441c88c12187ed6/x86_64_release-1.0.0-e4b8dca3f1b4ede4c30371002441c88c12187ed6.jar'.
            > Read timed out

* Try:
> Run with --stacktrace option to get the stack trace.
> Run with --info or --debug option to get more log output.
> Run with --scan to generate a Build Scan (powered by Develocity).
> Get more help at https://help.gradle.org.

BUILD FAILED in 20m 27s
Running Gradle task 'assembleRelease'...                         1228.4s
[!] Gradle threw an error while downloading artifacts from the network.
Retrying Gradle Build: #1, wait time: 100ms
Flutter assets will be downloaded from https://storage.flutter-io.cn. Make sure you trust this source!
Font asset "td_icons.ttf" was tree-shaken, reducing it from 367144 to 1536 bytes (99.6% reduction). Tree-shaking can be disabled by providing the --no-tree-shake-icons flag when building your app.
Font asset "MaterialIcons-Regular.otf" was tree-shaken, reducing it from 1645184 to 2160 bytes (99.9% reduction). Tree-shaking can be disabled by providing the --no-tree-shake-icons flag when building your app.
Running Gradle task 'assembleRelease'...                               //

这是AI给的解决方案 ,重试即可 哈哈哈

agsl 复制代码
这个错误**跟 url_launcher 无关**,是 Gradle 下载 Flutter 引擎 jar 文件时网络中断导致的:

Premature end of Content-Length delimited message body (expected: 170,894,936; received: 4,407,243)

r 复制代码
即需要下载约 163MB 的 `arm64_v8a_debug.jar`,但只收到了约 4MB 就断了,是 `storage.flutter-io.cn` 镜像下载不稳定。

**解决方案**:

1. **清除 Gradle 缓存中损坏的下载文件,然后重试**:

```powershell
# 删除损坏的缓存
Remove-Item -Recurse -Force "$env:USERPROFILE.gradle\caches\transforms-*" -ErrorAction SilentlyContinue
Remove-Item -Recurse -Force "$env:USERPROFILE.gradle\caches\modules-2\files-2.1\io.flutter" -ErrorAction SilentlyContinue
  1. 重新运行构建
powershell 复制代码
fvm flutter run

如果镜像源持续不稳定,可以尝试换个网络环境(比如开热点/VPN),或者多试几次。这个 jar 是 Flutter 引擎文件,首次下载成功后会缓存,后续就不用再下了。

复制代码
相关推荐
Sterting18 分钟前
Element-Plus 入门与整体布局
前端·vue.js·elementui
程序员黑豆7 小时前
Java 注释详解:单行、多行与文档注释的完整指南
java·前端·ai编程
剪刀石头布啊8 小时前
antd中可编辑表格中巧用useWatch实现联动高性能效果,以及定制延伸学习
前端
油丶酸萝卜别吃8 小时前
前端转全栈学习路线
前端·学习
浮生望8 小时前
前端路由进阶:History API原理与手写HistoryRouter
前端
陆枫Larry9 小时前
JavaScript 中的竞态是什么,为啥会有竟态?
前端
上海安当技术11 小时前
半天接入:USBKey RESTful API + C 动态库,Web 和 C/S 两套集成路径实战
前端·后端·restful·集成·usbkey
DevUI团队11 小时前
从“即兴创作”到“规格先行”,华为云码道(CodeArts)代码智能体持续深耕企业级规范驱动开发能力
前端·人工智能·后端
weixin_4316004412 小时前
NestJS 入门(3):Guard 如何挡住未登录请求?
前端·后端·学习·nest.js
kyriewen13 小时前
我用Claude Code两天干完了团队两周的排期——周报发出去那一刻我就后悔了
前端·javascript·ai编程