Reputation: 197
When I am trying to launch flutter desktop application, this error occurred to me:
"CMake Error at CMakeLists.txt:2 (project):
Generator
Visual Studio 16 2019
could not find any instance of Visual Studio.
Building Windows application...
Exception: Unable to generate build files"
What I did...
1- Installed Visual Studio 2022 with (Desktop development with C++ and Universal Windows Platform development)
2- Run these commands:
flutter config --enable-windows-desktop
flutter create .
flutter run -d windows
Also I tried to use dev channel:
flutter channel dev
flutter upgrade
flutter config--enable-windows-uwp-desktop
And these what I have when I run flutter devices and flutter doctor
flutter devices
4 connected devices: Windows (desktop) • windows • windows-x64 • Microsoft Windows [Version 10.0.22000.318] Windows (UWP) (desktop) • winuwp • windows-uwp-x64 • Chrome (web) • chrome • web-javascript • Google Chrome 94.0.4606.81 Edge (web) • edge • web-javascript • Microsoft Edge 95.0.1020.44
flutter doctor
[√] Flutter (Channel dev, 2.6.0-11.0.pre, on Microsoft Windows [Version 10.0.22000.318], locale en-US)
[√] Android toolchain - develop for Android devices (Android SDK version 31.0.0)
[√] Chrome - develop for the web
[√] Visual Studio - develop for Windows (Visual Studio Community 2022 17.0.0)
[√] Android Studio (version 2020.3)
[√] VS Code (version 1.61.1)
[√] Connected device (4 available)
• No issues found!
Upvotes: 16
Views: 48329
Reputation: 613
In my case, the issue shows up in only my project. If I create a new project and run works perfectly. However, I couldn't run the project that I intended to run. I've tried this.
Remove-Item -Recurse -Force .\windows
flutter clean
flutter create .
flutter pub get
and runUpvotes: 2
Reputation: 51
Do not run flutter build (I was running: flutter pub run msix:create --store) in PS (PowerShell) terminal, run it in the command prompt.
The above worked for me.
Upvotes: 1
Reputation: 21
try deleting the windows sdk then reinstalling it at https://developer.microsoft.com/en-us/windows/downloads/sdk-archive/
Upvotes: 1
Reputation: 56
I had this error many time now and i tried everything but one thing that solved it for me, was moving the flutter project highter up in the windows file structure, because windows (and apparently cmake) has problems creading or writing binaries too far down.
Upvotes: 1
Reputation: 19
You can copy the
lib/main.dart
file and just recreate the flutter project by running this command in PowerShell to any directory you like:
flutter create chatapp
Upvotes: 0
Reputation: 109
In my case only running flutter clean && flutter pub
gets the issue resolved..
Upvotes: 5
Reputation: 99
I finally found the solution
flutter is looking for app.so file in project_folder\build\windows\runner\Debug\data\app.so;
but the app.so file is actually in project_folder\build\windows\runner
to fix the problem just move app.so file from project_folder\build\windows\runner\ to project_folder\build\windows\runner\Debug\data\ and it will work
Upvotes: 1
Reputation: 2098
flutter clean
flutter create .
Upvotes: 17
Reputation: 11
Go flutter/packages/flutter_tools/lib/src/windows and open build_windows.dart file and on line 24 change:
const int kCurrentUwpTemplateVersion = Visual Studio 17 2022;
Save the file and run flutter. Select the windows device. It will run fine by now without any errors 🎉.
Upvotes: 1
Reputation: 196
3rd Feb 2022 Update: The latest version of Flutter, version 2.10 stable, has this issue fixed along with stable desktop support for Windows.
Update: The flutter beta channel (2.9.0-0.1.pre onwards) comes with a fix.
According to this issue on the main flutter repo, Flutter prior to version 2.9 does not support Visual Studio 2022. If you want to build while targeting Windows you'll either have to install VS 2019 alongside 2022 or use this workaround:
The current workaround is : download your appropriate flutter version, edit _cmakeVisualStudioGeneratorIdentifier in https://github.com/flutter/flutter/blob/master/packages/flutter_tools/lib/src/windows/build_windows.dart#L25-L28 to your appropriate CMake Visual Studio Generator. You can get the currently available CMake Visual Studio Generators on this page : https://cmake.org/cmake/help/latest/manual/cmake-generators.7.html#id13.
By default the _cmakeVisualStudioGeneratorIdentifier comes with CMake Visual Studio 2019 Generator. If you are going to use CMake Visual Studio 2022 Generator - firstly ensure your visual studio 2022 distribution contains Cmake 3.21 or later, refer https://cmake.org/cmake/help/latest/generator/Visual%20Studio%2017%202022.html for details.
To apply these changes on Windows:
path\to\flutter\packages\flutter_tools\lib\src\windows\build_windows.dart
, and change the constant on line 28 from 'Visual Studio 16 2019'
to 'Visual Studio 17 2022'
flutter_tools.stamp
and flutter_tools.snapshot
in path\to\flutter\bin\cache\
(to cause flutter to regenerate its build tools with the new source code you changed above)flutter clean
to remove cached CMake files referring to the wrong Visual Studio versionflutter run -d windows
to restart the build (successfully, this time)Upvotes: 18