[Flutter] Escaping the Setup Hell: From OneDrive Errors to Tangled Environment Variables

Hello! Today, I want to share my dynamic troubleshooting journey while setting up Flutter for the first time. What I thought would be a simple installation turned into a day-long struggle thanks to an unexpected enemy: OneDrive.

If you are setting up Flutter on Windows for the first time or keep getting mysterious path errors, I hope this post will be a ray of light for you! ✨


🚨 1. The Curse of OneDrive: Permission Error

I happily installed Flutter and tried to run my first app, only to be greeted by these terrifying red lines of text.

[Error Message]

Plaintext

Flutter failed to delete a directory at "C:\Users\OneDrive\Coding\flutter\bin\cache\pkg\sky_engine". 
The flutter tool cannot access the file or directory.

[Cause & Solution] The culprit was OneDrive Synchronization. If you place the Flutter SDK (installation folder) inside a OneDrive-synced folder, OneDrive locks the files to sync them to the cloud. When Flutter tries to execute code and delete or modify temporary cache files, access is denied, causing the tool to crash.

👉 Solution: I completely moved the Flutter folder to a pure local drive far away from OneDrive’s reach (e.g., C:\flutter).


🚨 2. The Stubborn Ghost of OneDrive: Tangled Environment Variables & Cache

I moved Flutter to the C drive and updated the Path environment variable to C:\flutter\bin… but the terminal kept throwing the exact same OneDrive path error from step 1. It was driving me crazy.

[Cause & Solution] The issue was that Windows and VS Code were still prioritizing and remembering the old address. To banish this ghost, you need to do three things:

  1. Thoroughly Clean System Environment Variables
    • I ran $env:Path -split ';' in PowerShell to check the priority, and oh my, the OneDrive path was still sitting at the very top.
    • I opened Edit the system environment variables in Windows, and instead of just checking the ‘User variables’, I checked the ‘System variables’ (the bottom section). I found the hidden old OneDrive path inside the Path variable there and completely deleted it.
  2. Delete Project Cache/Leftovers
    • In the VS Code file explorer, I completely deleted the .dart_tool folder, .vscode folder, and pubspec.lock file. (Don’t worry, they are automatically regenerated when you run the app).
  3. Reboot (⭐️ MOST IMPORTANT)
    • If you mess with Windows environment variables, no questions asked—you MUST reboot your computer for the changes to fully apply!

🚨 3. Flutter Disappeared? Command Not Found

[Error Message]

Plaintext

The term 'flutter' is not recognized as the name of a cmdlet, function, script file...

[Cause & Solution] I deleted the old Flutter folder from OneDrive and set up the new environment variables perfectly. However, I forgot one crucial detail: I hadn’t actually downloaded and extracted the new Flutter SDK into the new path (C:\flutter\bin) yet. (Facepalm…)

👉 Solution: I downloaded the Windows SDK zip file from the official Flutter website and made sure to extract it directly into C:\, which beautifully created the C:\flutter\bin directory. After that, running flutter doctor in the terminal recognized it perfectly!


🚨 4. Android Toolchain & Licenses Error

Flutter was finally recognized, but the flutter doctor checkup showed red flags in the Android section.

[Error Message]

Plaintext

[!] Android toolchain - develop for Android devices
    X cmdline-tools component is missing.
    X Android license status unknown.

[Solution] This is a very common error caused by missing command-line tools for the Android emulator and unaccepted Google developer agreements.

  1. Open Android Studio -> Click the Gear icon (Settings) -> Open SDK Manager.
  2. Select the SDK Tools tab -> Check Android SDK Command-line Tools (latest) and click Apply to install.
  3. Once installed, go back to the VS Code terminal and type: flutter doctor --android-licenses
  4. For every long license agreement that pops up on the screen, just spam y (Yes) and hit enter until you’ve agreed to all of them. Fixed!

🚨 5. The Final Hurdle: VS Code Cannot Find the SDK

[Error Message] A popup appeared in the bottom right corner of VS Code:

Plaintext

Could not find a Flutter SDK. Please download, or, if already downloaded, click 'Locate SDK'.

[Solution] Because I deleted the .vscode folder (which contains project settings) earlier in Step 2 to clear the cache, VS Code forgot where the new Flutter SDK was located. 👉 I simply clicked the blue [Locate SDK] button on the popup, navigated to C:\flutter, and selected the folder. Setup 100% complete!


💡 Today’s Hard-Learned Lesson

“Never place your development tools (SDKs) and project folders in cloud-synchronized directories like OneDrive!”

I spent a massive amount of time just on the setup, but thanks to this struggle, I now have a perfect understanding of Flutter’s environment variables and structure.

위로 스크롤