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

复制代码
相关推荐
涛涛ing27 分钟前
OpenAI Astra 泄露:零样本生成 3D 网页,前端开发者慌了吗?
前端
ssshooter1 小时前
现在网页都能提供 MCP 了?!
前端·人工智能·程序员
杉氧1 小时前
状态管理变迁史:为什么我们放弃了 Redux 选择 Zustand?
android·前端·react native
cidy_981 小时前
OpenCode 手动配置火山方舟 Agent Plan 教程
前端
鹏多多1 小时前
PC 网站接入微信登录,这 10 个坑我替你踩完了!
前端·javascript·vue.js
律宏阔2 小时前
微信小程序使用 Orval + OpenAPI 自动生成接口:Axios 兼容踩坑记录
前端·微信小程序
律宏阔2 小时前
微信小程序集成 TDesign 完整记录:解决 NPM packages not found
前端·微信小程序
律宏阔2 小时前
微信小程序 ECharts 瘦身实战:分包异步化 + componentPlaceholder 避开主包 2MB 限制
前端·微信小程序
夏天要喝冰可乐2 小时前
从 Idea 到开源插件:我用 Vibe Coding 做了「文章摆渡」
前端·ai编程·vibecoding
小小小小宇2 小时前
pi agent
前端