Flutter 错误集合

495 阅读2分钟

Type argument is not within its bounds. Expected: ViewDataBinding Found: ActivityLoginBinding

解决方案

需要在xml布局最完成嵌套layout标签

1741444908216.png

Caused by: java.lang.IllegalStateException: You should Call MMKV.initialize() first.

解决方案

在 Application 初始化 MMKV

MMKV.initialize(this)

Android Studio更改代码 ,必须先clean或rebuild,更改的代码才能编译进去

解决方案

1741363424732.jpg

1741363470548.png

1741363503532.jpg

此处什么都不要动,直接点击Ok,就可以了 image.png

编译工程时 One or more plugins require a higher Android NDK version.Fix this issue by adding the following to

1739612992011.png

大概意思:需要更高的Android NDK版本(比27.0.12077973更高的ndk版本)

解决方案

通过 SDK Tools 下载 对应版本的 ndk 文件

1739619257862.png

配置ndk路径

1739619200473.png

修改 flutter ndkVersion

1739619905154.png

1739619981771.png

major version (Mac电脑)

BuildScript Unsupported class file major version 65

表示你尝试运行一个使用了Java 19(Java SE 19的类文件主要版本号为65)编译的类文件,但在一个不支持该版本的Java虚拟机(JVM)上运行。

解决方案

通过gradle.properties 文件配置 jdk的安装路径

image.png

flutter this and base files have different roots (Windows11电脑)

大概意思就是:对应的依赖位置和项目编译后位置不一致导致

解决方案

添加 环境变量 PUB_CACHE 位置和项目同一个磁盘即可

1739109917976.png

设置完环境变量(最好重启一下电脑)

关闭 Android Studio,打开dos窗口(cmd),进入项目根目录(我没重启是这么执行的,不然在Studio Studio里面执行命令依赖位置还在原来文件里)分别执行如下命令

flutter clean
flutter pub get

1739110110366.png

1739110462027.png

执行完命令后,进到 android目录,执行如下命令:

./gradlew clean
./gradlew build

1739110587122.png

1739110707466.png

Some Android licenses not accepted (Windows11电脑)

1739457894385.png

大概意思就是:Android工具链-为Android设备开发(Android SDK版本35.0.1) ! 一些Android许可证不被接受。要解决这个问题,运行:flutter doctor -android-licenses

解决方案

执行如下命令

flutter doctor --android-licenses

企业微信截图_17394574425528.png

企业微信截图_1739457496538.png

企业微信截图_17394575427988.png

企业微信截图_17394575819160.png

企业微信截图_17394576495813.png

执行如下命令:

flutter doctor

企业微信截图_17394577533359.png

Cannot find Chrome. Try setting CHROME_EXECUTABLE to a Chrome executable (Windows11电脑)

1739458371422.png

解决方案

下载谷歌浏览器 并安装

1739458699407.jpg

image.png

执行如下命令

flutter doctor

1739459017613.png

Visual Studio not installed; this is necessary to develop Windows apps. (Windows11电脑)

企业微信截图_1739459597840.png

解决方案

下载并安装visualstudio

出现如下错误:

Visual Studio is missing necessary components. Please re-run the Visual Studio installer for the "Desktop development with C++" workload, and include these components: image.png

解决方案

企业微信截图_17394600082847.png

企业微信截图_17394601333658.png

执行如下命令

flutter doctor

1739461838558.png

编译Android+Flutter混合工程 Task:flutter:copyFlutterAssetsRelease (Windows电脑)

解决方案

微信图片_20250215170818.png

修改 flutter sdk 下面的flutter.groovy 文件

1739610643419.png

1739610464756.png