Sub topic 15
Fixing common setup problems
This chapter assumes you have already installed the Flutter SDK, run flutter doctor at least once, and created a project with flutter create. You should be comfortable editing environment variables and running commands in a terminal. The goal is a repeatable method for diagnosing a broken setup, plus fixes for the failures learners hit most often.
A diagnostic method
Most setup problems fall into one of three layers. Check them in order, because a failure in a lower layer causes misleading errors in the layers above it.
- The SDK itself. The
fluttercommand is missing, points at the wrong copy, or the SDK is damaged. - A platform toolchain. Android, Xcode, Chrome, or a desktop compiler is missing or misconfigured.
- The project. Dependencies will not resolve, or cached build output is stale.
Always start with the verbose report:
flutter --version
flutter doctor -vThe -v flag prints the paths Flutter found for each tool. Those paths are often the clue. For example, you may see an Android SDK path that points to an old install.
Layer 1: the SDK
"flutter: command not found"
The shell cannot find the flutter executable because the SDK's bin directory is not on your PATH. On macOS and Linux, add it to your shell profile (~/.zshrc or ~/.bashrc). Adjust the path to where you extracted the SDK:
export PATH="$HOME/development/flutter/bin:$PATH"Open a new terminal, or run source ~/.zshrc, then check which copy the shell resolves:
which flutter
flutter --versionOn Windows, add C:\src\flutter\bin (or your install folder) to the user Path variable in System Properties, then open a new terminal. Editing the variable does not affect terminals that are already open.
Wrong or duplicate installs
If which flutter shows a path you did not expect, an older copy is earlier on PATH. Package managers such as Homebrew or snap can install a second SDK. Keep one SDK and remove the others from PATH. Do not install the SDK in a folder that needs elevated permissions, such as C:\Program Files\, because Flutter writes to its own directory.
A damaged SDK cache
Interrupted downloads can leave the SDK's cached engine artifacts incomplete. Re-download them:
flutter precacheIf the SDK was installed from git and its files are modified, flutter upgrade may refuse to run. Reinstalling in a fresh folder is usually faster than untangling local edits.
Layer 2: platform toolchains
The table maps frequent flutter doctor messages to fixes.
| Message in `flutter doctor` | Likely cause | Fix |
|---|---|---|
| Android toolchain: `cmdline-tools component is missing` | Android command-line tools not installed | In Android Studio, open SDK Manager, SDK Tools, and install "Android SDK Command-line Tools (latest)" |
| Android toolchain: `Android license status unknown` or licenses not accepted | Licenses not accepted | `flutter doctor --android-licenses` |
| `Unable to locate Android SDK` | Flutter cannot find the SDK folder | `flutter config --android-sdk <path>` |
| Xcode: `CocoaPods not installed` | CocoaPods missing | `brew install cocoapods` |
| Xcode: `installation incomplete` | Command-line tools point to the wrong place | `sudo xcode-select --switch /Applications/Xcode.app/Contents/Developer` |
| `Cannot find Chrome executable` | Chrome is missing or in a non-default location | Install Chrome or set `CHROME_EXECUTABLE` |
| Visual Studio: missing components | Desktop C++ workload absent | Install the "Desktop development with C++" workload |
| Linux toolchain: missing packages | Build tools absent | Install clang, cmake, ninja, pkg-config, and GTK headers |
Android
Android problems are the most common. Work through these in order:
flutter doctor --android-licenses
flutter config --android-sdk "$HOME/Android/Sdk"
flutter config --jdk-dir "/path/to/jdk"
flutter doctor -vOnly run the last two config commands if flutter doctor -v shows the wrong SDK or JDK path. Android Studio bundles its own JDK, and Flutter normally finds it. Mixing in a separately installed JDK of a different major version is a frequent cause of Gradle errors. If Gradle fails with a Java version error, make sure Flutter and Gradle use the same JDK.
If a physical Android phone does not appear in flutter devices, check these in order:
- Developer options and USB debugging are enabled on the phone.
- You accepted the "Allow USB debugging" prompt on the phone.
- The cable carries data. Some cables only charge.
adb deviceslists the phone asdevice, notunauthorizedoroffline.
adb devices
adb kill-server
adb start-serverRestarting the adb server fixes many offline states. If the phone shows unauthorized, unplug it, revoke USB debugging authorizations in Developer options, and reconnect.
iOS and macOS
iOS builds need a full Xcode install, not only the command-line tools. After installing or updating Xcode:
sudo xcode-select --switch /Applications/Xcode.app/Contents/Developer
sudo xcodebuild -runFirstLaunch
sudo xcodebuild -license accept
brew install cocoapodsOn Apple Silicon Macs, some older Flutter and CocoaPods combinations needed Rosetta. If CocoaPods errors mention ffi architecture problems, installing CocoaPods through Homebrew avoids most of them. If the iOS simulator is not listed, open it once with open -a Simulator, then run flutter devices again.
Web
Flutter looks for Chrome in its default location. If Chrome is installed elsewhere, or you want to use a Chromium-based browser such as Edge, point Flutter at it:
export CHROME_EXECUTABLE="/path/to/chrome"
flutter devicesIf the Chrome and Edge devices do not appear at all, the web platform may be disabled:
flutter config --enable-webDesktop
Desktop targets need a native compiler. On Windows that is Visual Studio (not Visual Studio Code) with the C++ desktop workload. On Linux, install the build packages. This example is for Debian and Ubuntu:
sudo apt install clang cmake ninja-build pkg-config libgtk-3-devWindows has an extra requirement. Plugins use symbolic links, and Windows only allows them for normal users when Developer Mode is on. If flutter pub get or a build reports that symlink support is required, enable it:
start ms-settings:developersThen turn on Developer Mode in the window that opens.
No devices at all
If flutter doctor is clean but flutter devices is empty or lacks the target you want, list and launch emulators directly:
flutter emulators
flutter emulators --launch <emulator_id>
flutter devicesIf flutter emulators is empty, you have not created a virtual device yet. Create one in Android Studio's Device Manager. On Linux, emulator crashes at startup are often caused by missing hardware acceleration (KVM) or missing GPU drivers.
Layer 3: the project
Dependency resolution fails
flutter pub get fails for four common reasons.
- No network access or a proxy. Set
HTTPS_PROXYin your environment. In regions wherepub.devis slow or blocked, setPUB_HOSTED_URLandFLUTTER_STORAGE_BASE_URLto a mirror your organization trusts. - SDK constraint mismatch. The error says something like "requires SDK version ^3.x". The
environment: sdk:range inpubspec.yamldoes not include your installed Dart version. Runflutter upgrade, or lower the constraint if the code supports older Dart. - Version conflicts between packages. Read the solver message. It names the two packages that disagree. Loosen a version in
pubspec.yamlor runflutter pub upgrade. - A corrupted pub cache. Re-download the cached packages:
flutter pub cache repair
flutter pub getStale build output
After changing SDKs, switching branches, or editing native files, odd errors may come from old build output. Delete it and rebuild:
flutter clean
flutter pub get
flutter runflutter clean removes the build/ directory and generated files. It does not touch your source code, so it is safe to run whenever you doubt the build state.
Version drift
Check your SDK channel and version before comparing results with a tutorial or colleague:
flutter channel
flutter upgrade
flutter --versionThe stable channel is the right default while learning. Beta and main change often and break more.
A repeatable checklist
- Run
flutter doctor -vand fix the first red item, then rerun it. Fixing one item often clears several. - Run
flutter devicesand confirm your target is listed. - Run
flutter pub getand confirm it ends without errors. - Run
flutter cleanif the error mentions generated or cached files. - Run
flutter upgradeonly after the steps above, so you change one thing at a time.
Exercise
flutter doctor reports "Android license status unknown", and flutter doctor -v shows the Android SDK at a path from an old installation. Which two commands, in order, fix this, and why does the order matter?
Show answer
First flutter config --android-sdk <path to the current SDK>, then flutter doctor --android-licenses. The licenses are stored inside a specific SDK folder, so Flutter must point at the correct SDK before you accept them. Accepting licenses first would update the old SDK, and the new one would still report unknown status.
Exercise
A project builds on your laptop, but on a colleague's machine flutter pub get fails with "requires SDK version ^3.x". What is the most likely cause, and what are two ways to resolve it?
Show answer
Their installed Dart SDK (bundled with Flutter) is older than the range in the environment: sdk: constraint in pubspec.yaml. They can run flutter upgrade to get a newer SDK, or the project can lower the constraint if the code does not need newer Dart features.
Exercise
Your Android phone is plugged in but flutter devices does not list it, and adb devices shows it as unauthorized. What do you do?
Show answer
The phone has not trusted this computer. Unplug it, revoke USB debugging authorizations in Developer options, reconnect, and accept the "Allow USB debugging" prompt on the phone. If it still shows as offline, run adb kill-server and adb start-server, then check flutter devices again.