当前位置: 首页 > article >正文

flutter在windows平台中运行报错

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
    }


http://www.kler.cn/a/468486.html

相关文章:

  • vulnhub靶场-potato(至获取shell)
  • HarmonyOS:@Builder装饰器:自定义构建函数
  • Linux之信号量
  • MCGS学习记录
  • Android12 App窗口创建流程
  • Python入门教程 —— 模块和包
  • BOOST 库在机器视觉中的应用及示例代码分析
  • 【C++】B2099 矩阵交换行
  • 基于 GitHub Actions 的流程自动化实践
  • Apache Traffic存在SQL注入漏洞(CVE-2024-45387)
  • 感冒之嗓子红肿,咽红且痛,微恶风寒,无浑身疼痛,无清鼻涕
  • Redis数据库笔记—— Hash(哈希)的扩容机制(rehash)
  • Python爬虫基础——requests模块
  • Harmony OS开发-ArkTS语言速成五
  • 嵌入式Linux(二)·配置VMware使用USB网卡连接STM32MP157实现Windows、Ubuntu以及开发板之间的通信
  • 基于海思soc的智能产品开发(camera sensor的两种接口)
  • React中的合成事件
  • 源代码编译安装X11及相关库、vim,配置vim(2)
  • 智能工厂的设计软件 应用场景的一个例子:为AI聊天工具添加一个知识系统 之13 方案再探之4:特定于领域的模板 之 div模型(完整版)
  • SpringCloud源码-Ribbon
  • Python爬虫基础——案例:爬取豆瓣电影动画排行榜
  • 蓝桥杯备赛:C++基础,顺序表和vector(STL)
  • Zabbix5.0版本(监控Nginx+PHP服务状态信息)
  • Earth靶场
  • SQL 基础教程 - SQL UPDATE 语句
  • [python3]Excel解析库-calamine,10倍openpyxl性能