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 引擎文件,首次下载成功后会缓存,后续就不用再下了。

复制代码
相关推荐
子兮曰1 天前
jev-ultrafast 深度解析:7 秒订机票的浏览器 Agent 是如何炼成的
前端·后端·agent
子兮曰1 天前
Jev 爆发一周:7 秒 Agent 背后的 System One 生态与三场争议
前端·后端·ai编程
前端小万1 天前
写公众号赚了 3000 块后,我做了一款叫 "一键成稿" 的软件
前端·微信小程序
爱勇宝1 天前
ZCode 开源 24 小时:一份没有历史的账本,回答不了"有没有偷代码"
前端·后端·chatglm (智谱)
三十而立洋1 天前
Cookie 详解:从产生到安全,一次讲透
前端·javascript
卡布鲁1 天前
把一个 Vite + Vue3 应用塞进 qiankun (React + Umi3) 主站:十个坑的复盘
前端·javascript·react.js
汉堡大王95271 天前
Jev:不是聊天机器人, 而是一个智能 if 语句
前端·人工智能·后端
梦想很大很大1 天前
从运行事实到回归证据:Workrun 的 Telemetry 与 Evaluation 实践
前端·人工智能·后端
计算机魔术师1 天前
Meta Muse agent 接入 Shopify 的 Shop Pay 实现代理式购物
前端
沙蒿同学1 天前
我用 Go 搭了一条 AI Agent 流水线:从 1 张商品图到一整套淘宝详情页
前端·javascript·后端