flutter在windows平台中运行报错

[复制链接]
发表于 2025-11-15 22:12:14 | 显示全部楼层 |阅读模式

马上注册,结交更多好友,享用更多功能,让你轻松玩转社区。

您需要 登录 才可以下载或查看,没有账号?立即注册

×
  1. PS D:\F\luichun> flutter run
复制代码
当运行flutter项目时,【办理如下报错】
  1. /C:/flutter/packages/flutter/lib/src/painting/star_border.dart:530:27: Error: The getter 'Matrix4' isn't defined for the class '_StarGenerator'.
  2. - '_StarGenerator' is from 'package:flutter/src/painting/star_border.dart' ('/C:/flutter/packages/flutter/lib/src/painting/star_border.dart').
  3. Try correcting the name to the name of an existing getter, or defining a getter or field named 'Matrix4'.
  4.     squashMatrix.multiply(Matrix4.translationValues(-rect.center.dx, -rect.center.dy, 0));
  5.                           ^^^^^^^
  6. /C:/flutter/packages/flutter/lib/src/semantics/semantics.dart:643:9: Error: 'Matrix4' isn't a type.
  7.   final Matrix4? transform;
  8.         ^^^^^^^
  9. /C:/flutter/packages/flutter/lib/src/semantics/semantics.dart:1756:3: Error: 'Matrix4' isn't a type.
  10.   Matrix4? _transform;
  11.   ^^^^^^^
  12. /C:/flutter/packages/flutter/lib/src/semantics/semantics.dart:1757:17: Error: 'Matrix4' isn't a type.
  13.   set transform(Matrix4? value) {
  14.                 ^^^^^^^
  15. /C:/flutter/packages/flutter/lib/src/semantics/semantics.dart:2745:12: Error: Undefined name 'Matrix4'.
  16.     return Matrix4.identity().storage;
  17.            ^^^^^^^
  18. /C:/flutter/packages/flutter/lib/src/semantics/semantics.dart:3213:9: Error: 'Vector3' isn't a type.
  19.   final Vector3 vector = Vector3(point.dx, point.dy, 0.0);
  20.         ^^^^^^^
  21. /C:/flutter/packages/flutter/lib/src/semantics/semantics.dart:3213:26: Error: Method not found: 'Vector3'.
  22.   final Vector3 vector = Vector3(point.dx, point.dy, 0.0);
  23.                          ^^^^^^^
  24. /C:/flutter/packages/flutter/lib/src/semantics/semantics.dart:3510:13: Error: 'Matrix4' isn't a type.
  25.       final Matrix4 inverse = Matrix4.identity();
  26.             ^^^^^^^
  27. /C:/flutter/packages/flutter/lib/src/semantics/semantics.dart:3510:31: Error: The getter 'Matrix4' isn't defined for the class 'SemanticsOwner'.
  28. - 'SemanticsOwner' is from 'package:flutter/src/semantics/semantics.dart' ('/C:/flutter/packages/flutter/lib/src/semantics/semantics.dart').
  29. Try correcting the name to the name of an existing getter, or defining a getter or field named 'Matrix4'.
  30.       final Matrix4 inverse = Matrix4.identity();
  31.                               ^^^^^^^
  32. Target kernel_snapshot failed: Exception
  33. FAILURE: Build failed with an exception.
  34. * What went wrong:
  35. Execution failed for task ':app:compileFlutterBuildDebug'.
  36. > Process 'command 'C:\flutter\bin\flutter.bat'' finished with non-zero exit value 1
  37. * Try:
  38. > Run with --stacktrace option to get the stack trace.
  39. > Run with --info or --debug option to get more log output.
  40. > Run with --scan to get full insights.
  41. * Get more help at https://help.gradle.org
  42. BUILD FAILED in 8s
  43. Running Gradle task 'assembleDebug'...                              9.3s
  44. Error: Gradle task assembleDebug failed with exit code 1
  45. PS D:\F\luichun>
复制代码
检察当地版本
  1. PS D:\F\luichun> flutter --version
  2. Flutter 3.19.4 • channel stable • https://github.com/flutter/flutter.git
  3. Framework • revision 68bfaea224 (10 months ago) • 2024-03-20 15:36:31 -0700
  4. Engine • revision a5c24f538d
  5. Tools • Dart 3.3.2 • DevTools 2.31.1
  6. PS D:\F\luichun>
  7. PS D:\F\luichun> flutter channel stable
  8. Flutter assets will be downloaded from https://storage.googleapis.com. Make sure you trust this source!
  9. Switching to flutter channel 'stable'...
  10. Upgrading engine...
  11. Flutter assets will be downloaded from https://storage.googleapis.com. Make sure you trust this source!
  12. Successfully switched to flutter channel 'stable'.
  13. To ensure that you're on the latest build from this channel, run 'flutter upgrade'
  14. PS D:\F\luichun>
复制代码
使用当地版本
  1. # 切换到 stable 渠道
  2. flutter channel stable
复制代码
升级flutter
  1. PS D:\F\luichun> flutter upgrade
  2. [√] Chrome - develop for the web
  3. [√] Visual Studio - develop Windows apps (Visual Studio Community 2022 17.9.5)
  4. [√] Android Studio (version 2023.2)
  5. [√] VS Code (version 1.96.2)
  6. [√] Connected device (4 available)
  7. [√] Network resources
  8. ! Doctor found issues in 1 category.
  9. PS D:\F\luichun>
复制代码
整理缓存
  1. # 1. 整理项目PS D:\F\luichun> flutter clean# 2. 获取新依赖PS D:\F\luichun> flutter pub get# 3. 运行项目PS D:\F\luichun> flutter run
复制代码
开启当地windows的开发者选项
  1.    start ms-settings:developers
复制代码


运行项目
  1. flutter run
复制代码
条件:你可以上google

如你再次运行时遇到
  1. 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.
  2. Example of androidX reference: 'androidx/media2/session/MediaBrowser$Builder'
  3. Example of support library reference: 'android/support/v4/media/session/MediaSessionCompat$Token'
复制代码
这个告诫是关于 media2-session 库中同时存在 AndroidX 和旧版 support library 的引用。这通常与音频相干的功能有关。让我们办理这个题目:
起首查抄你的项目是否真的须要 media2-session。在 pubspec.yaml 中查找相干依赖:
  1. dependencies:
  2.   vector_math: ^2.1.4
  3.   win32: ^5.10.0
  4.   # 检查是否有音频相关的依赖
复制代码
在 android/app/build.gradle 中确保精确设置 AndroidX:
  1. # 添加
  2. dependencies {
  3.     implementation "androidx.media2:media2-session:1.2.1"
  4. }
  5. # 添加
  6.     defaultConfig {
  7.         // TODO: Specify your own unique Application ID (https://developer.android.com/studio/build/application-id.html).
  8.         applicationId "com.luichun.luichun"
  9.         // You can update the following values to match your application needs.
  10.         // For more information, see: https://docs.flutter.dev/deployment/android#reviewing-the-gradle-build-configuration.
  11.         minSdkVersion flutter.minSdkVersion
  12.         targetSdkVersion flutter.targetSdkVersion
  13.         versionCode flutterVersionCode.toInteger()
  14.         versionName flutterVersionName
  15.         # 添加
  16.         android.useAndroidX=true
  17.         # 添加
  18.         android.enableJetifier=true
  19.     }
复制代码
回复

使用道具 举报

登录后关闭弹窗

登录参与点评抽奖  加入IT实名职场社区
去登录
快速回复 返回顶部 返回列表