PS D:\F\luichun> flutter run
当运行flutter项目时,【解决如下报错】
/C:/flutter/packages/flutter/lib/src/painting/star_border.dart:530:27: Error: The getter 'Matrix4' isn't defined for the class '_StarGenerator'.
- '_StarGenerator' is from 'package:flutter/src/painting/star_border.dart' ('/C:/flutter/packages/flutter/lib/src/painting/star_border.dart').
Try correcting the name to the name of an existing getter, or defining a getter or field named 'Matrix4'.
squashMatrix.multiply(Matrix4.translationValues(-rect.center.dx, -rect.center.dy, 0));
^^^^^^^
/C:/flutter/packages/flutter/lib/src/semantics/semantics.dart:643:9: Error: 'Matrix4' isn't a type.
final Matrix4? transform;
^^^^^^^
/C:/flutter/packages/flutter/lib/src/semantics/semantics.dart:1756:3: Error: 'Matrix4' isn't a type.
Matrix4? _transform;
^^^^^^^
/C:/flutter/packages/flutter/lib/src/semantics/semantics.dart:1757:17: Error: 'Matrix4' isn't a type.
set transform(Matrix4? value) {
^^^^^^^
/C:/flutter/packages/flutter/lib/src/semantics/semantics.dart:2745:12: Error: Undefined name 'Matrix4'.
return Matrix4.identity().storage;
^^^^^^^
/C:/flutter/packages/flutter/lib/src/semantics/semantics.dart:3213:9: Error: 'Vector3' isn't a type.
final Vector3 vector = Vector3(point.dx, point.dy, 0.0);
^^^^^^^
/C:/flutter/packages/flutter/lib/src/semantics/semantics.dart:3213:26: Error: Method not found: 'Vector3'.
final Vector3 vector = Vector3(point.dx, point.dy, 0.0);
^^^^^^^
/C:/flutter/packages/flutter/lib/src/semantics/semantics.dart:3510:13: Error: 'Matrix4' isn't a type.
final Matrix4 inverse = Matrix4.identity();
^^^^^^^
/C:/flutter/packages/flutter/lib/src/semantics/semantics.dart:3510:31: Error: The getter 'Matrix4' isn't defined for the class 'SemanticsOwner'.
- 'SemanticsOwner' is from 'package:flutter/src/semantics/semantics.dart' ('/C:/flutter/packages/flutter/lib/src/semantics/semantics.dart').
Try correcting the name to the name of an existing getter, or defining a getter or field named 'Matrix4'.
final Matrix4 inverse = Matrix4.identity();
^^^^^^^
Target kernel_snapshot failed: Exception
FAILURE: Build failed with an exception.
* What went wrong:
Execution failed for task ':app:compileFlutterBuildDebug'.
> Process 'command 'C:\flutter\bin\flutter.bat'' finished with non-zero exit value 1
* 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 get full insights.
* Get more help at https://help.gradle.org
BUILD FAILED in 8s
Running Gradle task 'assembleDebug'... 9.3s
Error: Gradle task assembleDebug failed with exit code 1
PS D:\F\luichun>
查看本地版本
PS D:\F\luichun> flutter --version
Flutter 3.19.4 • channel stable • https://github.com/flutter/flutter.git
Framework • revision 68bfaea224 (10 months ago) • 2024-03-20 15:36:31 -0700
Engine • revision a5c24f538d
Tools • Dart 3.3.2 • DevTools 2.31.1
PS D:\F\luichun>
PS D:\F\luichun> flutter channel stable
Flutter assets will be downloaded from https://storage.googleapis.com. Make sure you trust this source!
Switching to flutter channel 'stable'...
Upgrading engine...
Flutter assets will be downloaded from https://storage.googleapis.com. Make sure you trust this source!
Successfully switched to flutter channel 'stable'.
To ensure that you're on the latest build from this channel, run 'flutter upgrade'
PS D:\F\luichun>
使用本地版本
# 切换到 stable 渠道
flutter channel stable
升级flutter
PS D:\F\luichun> flutter upgrade
[√] Chrome - develop for the web
[√] Visual Studio - develop Windows apps (Visual Studio Community 2022 17.9.5)
[√] Android Studio (version 2023.2)
[√] VS Code (version 1.96.2)
[√] Connected device (4 available)
[√] Network resources
! Doctor found issues in 1 category.
PS D:\F\luichun>
清理缓存
# 1. 清理项目
PS D:\F\luichun> flutter clean
# 2. 获取新依赖
PS D:\F\luichun> flutter pub get
# 3. 运行项目
PS D:\F\luichun> flutter run
开启本地windows的开发者选项
start ms-settings:developers
运行项目
flutter run
前提:你可以上google
如你再次运行时遇到
WARNING: [Processor] Library 'C:\Users\luich\.gradle\caches\modules-2\files-2.1\androidx.media2\media2-session\1.2.1\f927563711e36371c19b2e86fb7ccf1c3f259ca4\media2-session-1.2.1.aar' contains references to both AndroidX and old support library. This seems like the library is partially migrated. Jetifier will try to rewrite the library anyway.
Example of androidX reference: 'androidx/media2/session/MediaBrowser$Builder'
Example of support library reference: 'android/support/v4/media/session/MediaSessionCompat$Token'
这个警告是关于 media2-session 库中同时存在 AndroidX 和旧版 support library 的引用。这通常与音频相关的功能有关。让我们解决这个问题:
首先检查你的项目是否真的需要 media2-session。在 pubspec.yaml 中查找相关依赖:
dependencies:
vector_math: ^2.1.4
win32: ^5.10.0
# 检查是否有音频相关的依赖
在 android/app/build.gradle 中确保正确配置 AndroidX:
# 添加
dependencies {
implementation "androidx.media2:media2-session:1.2.1"
}
# 添加
defaultConfig {
// TODO: Specify your own unique Application ID (https://developer.android.com/studio/build/application-id.html).
applicationId "com.luichun.luichun"
// You can update the following values to match your application needs.
// For more information, see: https://docs.flutter.dev/deployment/android#reviewing-the-gradle-build-configuration.
minSdkVersion flutter.minSdkVersion
targetSdkVersion flutter.targetSdkVersion
versionCode flutterVersionCode.toInteger()
versionName flutterVersionName
# 添加
android.useAndroidX=true
# 添加
android.enableJetifier=true
}