[Error Handling] How to Resolve “The Flutter SDK is installed in a protected folder and may not function correctly”

When using Flutter in VS Code, the following message might appear:
“The Flutter SDK is installed in a protected folder and may not function correctly”.

After researching and solving this issue, I would like to share the solution. I hope this helps anyone experiencing a similar error.

Why Does This Message Appear?

This message appears because the folder where Flutter is installed is protected, requiring special permissions.

Typically, when installed, the Flutter installation folder is created in “C:\Program Files”. However, since “C:\Program Files” is protected, the message appears.

Solution

The solution is simple: move the Flutter installation folder to a non-protected folder. The steps are as follows:

  1. Move the folder
  2. Change environment variables
  3. Delete cache information (if necessary)

1. Move the Folder

For example, create an Apps folder (or any folder name you prefer) and move Flutter there:
“C:\Program Files\flutter” → “C:\Apps\flutter”

2. Change Environment Variables

If you have set environment variables as shown below, modifications are required.

3. Delete Cache Information (if necessary)

After making the above changes, if you run “build_runner“, you may encounter the following error:

Deprecated. Use dart run instead. Could not find a file named "pubspec.yaml" in
"C:\Program Files\flutter\packages\flutter

This error occurs because the cache is referencing the old folder. Running the following command in the terminal will resolve the error:

flutter packages get

If the Error Still Occurs

Although the above steps resolved the issue for me, it might not work for everyone. The problem could be that the cache files in the “/flutter/.pub-cache” folder have not been updated.

To clear the cache files, execute the following three commands in the terminal:

flutter clean
flutter pub get
dart pub get

Try Running Again

By following these steps, I hope the message will disappear and you will be able to run the “build_runner” command successfully.

Copied title and URL