7

i get this message when try to run flutter application on the Windows,

Building Windows application...
CMake Error at CMakeLists.txt:2 (project):
  Generator

    Visual Studio 16 2019

  could not find any instance of Visual Studio.

i have installed Visual Studio 2022 with many tools like in the image below enter image description here

and this what I got from Flutter Doctor:
E:\mp\my_class>flutter doctor
Doctor summary (to see all details, run flutter doctor -v):
[√] Flutter (Channel beta, 2.8.0-3.2.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.2)
[√] Android Studio (version 2020.3)
[√] IntelliJ IDEA Ultimate Edition (version 2021.2)
[√] VS Code (version 1.62.3)
[√] Connected device (3 available)

• No issues found!
Osama Mohammed
  • 2,433
  • 13
  • 29
  • 61

6 Answers6

4

Visual Studio 2022 is only supported in version 2.9 or later (which at the time of writing is only on the master channel). The fact that doctor doesn't show any indication that 2022 won't work is a bug.

smorgan
  • 20,228
  • 3
  • 47
  • 55
  • 1
    If you do want to use Visual Studio 2022 with flutter 2.8.x, there are instructions about how to fix up CMake here: https://stackoverflow.com/a/69951396/120398 – David Fraser Jan 19 '22 at 09:37
  • 1
    With Flutter 2.10 you can now use VS 2022, you even only need to install the BuildTools with C++ package, without the need of the actual IDE. https://visualstudio.microsoft.com/downloads/#build-tools-for-visual-studio-2022 – User Rebo Feb 06 '22 at 10:24
1

this problem has been solved by just uninstalling Visual Studio 2022 with its components, and reinstalling Visual Studio 2019 version 16 as shown in the error message, and now it is working !!! , actually, someone answered this solution, but he seems removed his answer ....by the way, thank you

Osama Mohammed
  • 2,433
  • 13
  • 29
  • 61
1

flutter 2.10 should fix this. there is an existing solution for it by rename VSCODE 16 2019 to VSCODE 17 2022

En Hui Lim
  • 85
  • 8
0

Let’s forget about CMakeSettings.json for a second.

Can you build a VS 2019/2017 project with CMake standalone?

cd foobar/ cmake -B build/vs2019 -G "Visual Studio 16 2019" cmake -B build/vs2017 -G "Visual Studio 15 2017" If this doesn’t work it means you don’t have the necessary software installed on your system. You’ll need to look at your VS installations.

If that doesn’t work consider refreshing your installations:

vs studio repair

Also I understand this is frustrating. It’s just how Microsoft decided to make their C++ build environment. They decided to tie their compiler to their IDE. That approach has trade offs.

At our company we actually don’t even rely on VS for our drivers to compile using MSVC. Since it’s a pain to ensure developers use the same compiler. We actually run our own packaging system around MSVC to ensure we have easily reproducible builds with strict semantic versioning control. but try android studio. This means extra work to understand the MSVC C++ environment, but it also means we don’t have to worry about updating Visual Studio breaking developer builds. Or dev A uses a slightly different compiler then dev B. Or devs using a different compiler than our CI.

  • thank you, but I made a repair, and it is still showing me the same problem, actually, I have never used visual studio or Cmaker before, so I didn't understand what you mean, I am a flutter developer – Osama Mohammed Dec 03 '21 at 11:03
-1

I had the same problem. And this is how I fixed it:

  1. Check if you have Microsoft Redistributable , if not download and install from Microsoft's official site.

https://learn.microsoft.com/en-us/cpp/windows/latest-supported-vc-redist?view=msvc-170

  1. Install Visual Studio 19 . You can still keep Visual Studio 22(which in this case can only be supported in version 2.9 or later).

  2. Restart your IDE

  3. Clean project and rebuild it.

  4. Run your project and enjoy.

This should do the magic.

-2

I believe it is due to the system C++ environment not being deployed.

Follow these steps

-Open Visual Studio

-Go to Tools -> Get Tools and Features

-In the "Workloads" tab enable "Desktop development with C++"

-Click Modify at the bottom right

Then Visual C++ tools for CMake will be enabled

Tell me if this works

  • but I have already done this, as you can see in the image (Desktop development with C++) is already enabled, and still same problem – Osama Mohammed Dec 03 '21 at 10:28