尝试调试 Windows 应用时出现 Flutter 错误

12

我正在尝试使用默认的Flutter项目首次启动Windows应用程序,但它显示了这个错误,特别是。

Unable to start engine without AOT data.
Failed to create view controller.
Error waiting for a debug connection: The log reader stopped unexpectedly, or never started.
Error launching application on Windows.
Exited (sigterm)

这是我的Flutter Doctor -v结果:

[√] Flutter (Channel stable, 2.10.0, on Microsoft Windows [Version
    10.0.19042.1526], locale tr-TR)
    • Flutter version 2.10.0 at D:\src\flutter
    • Upstream repository https://github.com/flutter/flutter.git
    • Framework revision 5f105a6ca7 (2 weeks ago), 2022-02-01 14:15:42 -0800
    • Engine revision 776efd2034
    • Dart version 2.16.0
    • DevTools version 2.9.2

[√] Android toolchain - develop for Android devices (Android SDK version    
    31.0.0)
    • Android SDK at D:\sdk
    • Platform android-31, build-tools 31.0.0
    • ANDROID_HOME = C:\Users\pc\AppData\Local\Android\Sdk
    • Java binary at: D:\Android Studio\jre\bin\java
    • Java version OpenJDK Runtime Environment (build 11.0.10+0-b96-7249189)
    • All Android licenses accepted.

[X] Chrome - develop for the web (Cannot find Chrome executable at
    .\Google\Chrome\Application\chrome.exe)
    ! Cannot find Chrome. Try setting CHROME_EXECUTABLE to a Chrome executable.
[√] Visual Studio - develop for Windows (Visual Studio Community 2022 17.1.0)  
    • Visual Studio at C:\Program Files\Microsoft Visual Studio\2022\Community 
    • Visual Studio Community 2022 version 17.1.32210.238
    • Windows 10 SDK version 10.0.22000.0

[√] Android Studio (version 2020.3)
    • Android Studio at D:\Android Studio
    • Flutter plugin can be installed from:
       https://plugins.jetbrains.com/plugin/9212-flutter
    • Dart plugin can be installed from:
       https://plugins.jetbrains.com/plugin/6351-dart
    • Java version OpenJDK Runtime Environment (build 11.0.10+0-b96-7249189)   

[√] Connected device (2 available)
    • sdk gphone x86 (mobile) • emulator-5554 • android-x86 • Android 11 (API  
      30) (emulator)
    • Windows (desktop)       • windows       • windows-x64 • Microsoft Windows      [Version 10.0.19042.1526]

[√] HTTP Host Availability

我尝试了flutter clean,但它没有起作用。对于这个错误,我该怎么办?


1
你是否已经安装了Chrome浏览器? - Gazihan Alankus
这似乎是与此开放式工单 https://github.com/flutter/flutter/issues/97086 相似的问题。 - Omatt
我添加了解决方案。 - Tolga Yılmaz
10个回答

11

我已经在Github上解决了aceta-minophen的问题(https://github.com/flutter/flutter/issues/97086#issuecomment-1029963716)。

aceta-minophen解决方案

..\build\windows 中找到 app.so 文件。

将文件复制并粘贴到 ..\build\windows\runner\Debug\data 中。

[更新]

升级Flutter到最新版本即可解决此问题:

运行以下命令:

flutter upgrade


1
正如在Github线程中已经提到的那样,这不是一个修复,而是一个解决方法。VS开发人员已经意识到了这个问题。 - Aray Karjauv
2
谢谢。这种解决方法比卸载VS22并安装VS19要快得多,也更容易。 - Chris Swan
1
这并不是无法运行调试构建的解决方法,因为通过这样做,你最终得到的将是一个(大部分)发布构建。 - smorgan
1
它对我起作用了;我安装了VS2022和VS2019;在这个解决方法之前,Windows应用程序只是闪烁并死亡。 - Marcelo Scofano Diniz

5

看起来这个问题与 Visual Studio 的这个版本有关

[√] Visual Studio - develop for Windows (Visual Studio Community 2022 17.1.0)  
    • Visual Studio at C:\Program Files\Microsoft Visual Studio\2022\Community 
    • Visual Studio Community 2022 version 17.1.32210.238
    • Windows 10 SDK version 10.0.22000.0

尝试卸载Visual Studio Community 2022并安装Visual Studio Community 2019

使用Visual Studio 2019一切都像魔法一样顺畅 :)


1
我刚刚经历了同样的痛苦。我刚刚意识到,让一个简单的“Hello World”运行起来是一项艰苦的工作。对于任何遇到这个问题的人,请相信我,你必须将Visual Studio 22卸载并降级到版本19。 - kinsley kajiva
1
我也安装了VS2022和VS2019;Windows应用程序只会闪烁并显示“无法设置AOT...”消息。在我将App.so复制到“..\build\windows\runner\Debug\data”后,它甚至不需要重新加载VS Code就可以正常显示... - Marcelo Scofano Diniz

1

我在使用VS Code启动Windows应用程序时遇到了一些AOT错误,所以我将Visual Studio 2022降级为Visual Studio 2019,这样就可以正常工作了。


1

一个可用于调试的解决方法:

编辑<proj_dir>\windows\flutter\CMakeLists.txt,将$<CONFIG>替换为Debug

这个修改只需要在add_custom_command的结尾处进行一次即可。 此操作是在升级VS 2022到17.1.0后必要的(在17.0.6中工作正常)。 Windows项目的支持最初是通过flutter create --platforms=windows .添加的。

VS Bug:使用$自定义命令时,在17.1.0中CMake->vcxproj出现了退化


1
Flutter 2.10.3 解决了这个问题。

0

重现步骤

        Create a new application.
        run flutter run -d windows --debug

    Expected results: The build should success.
    Actual results: Can't load AOT data from C:\Users\nieti\Desktop\flutter_application_1\build\windows\runner\Debug\data\app.so; no such file. Unable to start engine without AOT data. Failed to create view controller. Error waiting for a debug connection: The log reader stopped unexpectedly, or never started. Error launching application on Windows.
    Logs

Did you manage to solve your issue? Im facing this exact issue but flutter doctor shows that everything is OK and Windows is listed on Connected Devices. Im on Flutter 2.10

嘿!今天我遇到了同样的问题,我通过以下方式解决了这个问题:

Found the app.so file in ..\build\windows
Copied the file and pasted it in ..\build\windows\runner\Debug\data

0

0

2
什么是解决方案?链接到可能会消失的内容是一个坏主意。你能告诉我们视频里有什么吗? - Kenny Mann

0
在我的情况下,app.so文件也不在build/windows中。
解决方法是找到任何一个app.so文件并复制到..\build\windows\runner\Debug\data 在VS Code中使用Go -> 转到文件...

-1

我有另一种解决方案,而不是卸载 Visual Studio 2022 版本,只需修改安装程序内部的设置,并安装最新版本的 Windows SDK,即 Win SDK 10(10.0.20348.0),这将解决 app.so 和 AOTdata 未找到的问题。


不要总是想着降级到2019年的VS,因为使用VS 22时Flutter架构效果更好。只需要相应地修改版本即可。 - Devrohit
1
我已经降级到10.0.20348.0,但在VS22中仍然遇到相同的错误。即使使用10.0.18362.0也是一样的。还有其他需要做的事情吗? - AshishB
降级到Visual Studio 2022 17.0.6应该可以解决问题。这只是最新更新版本17.1.0中的一个错误。希望他们能尽快修复。 - Jogy

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接