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

复制代码
相关推荐
咩咩啃树皮5 小时前
第40篇:Vue3组件化开发精讲——组件拆分、复用、父子通信、工程化架构
java·前端·架构
阳光是sunny5 小时前
LangGraph中的Reducer是什么
前端·人工智能·后端
触底反弹5 小时前
一文搞懂 Tailwind CSS 弹性布局:从原理到实战
前端·css·html
阳光是sunny5 小时前
从链到图:LangGraph 入门基础全解析
前端·人工智能·后端
小林ixn6 小时前
从 ??= 到 onKeyDown:一个 React 组件的“自我修养”
前端·javascript·react.js
REDcker6 小时前
显示分辨率标准对照详解
前端·网络·分辨率·显示·屏幕
এ慕ོ冬℘゜7 小时前
前端实战:jQuery 多条件联合搜索(标题模糊查询 + 日历时间段筛选)
前端·javascript·jquery
武子康7 小时前
Search Console Platform Properties 扩大 SEO 资产边界:从 Page Ranking 到 Topic Coverage(5 类误读边界 + 3 表数据层设计)
前端·人工智能·后端
一点一木7 小时前
从60首歌到1个网站:输入你的故事,还你一首歌
前端·github
IT_陈寒9 小时前
Vue这个特性差点让我加班到凌晨,谁懂啊
前端·人工智能·后端