Sub topic 15
Fixing common setup problems
Assume you know how to use a terminal and understand variables, commands, and project folders. This chapter focuses on diagnosing Flutter setup failures rather than installing every platform tool from scratch.
Start with `flutter doctor`
Run these commands from any directory:
flutter --version
flutter doctor
flutter devicesflutter doctor checks the Flutter SDK, Dart SDK, connected devices, Android tools, and editor integrations. Read the output from top to bottom. Fix the first failure before investigating later warnings because one missing component can cause several secondary errors.
| Message | Likely cause | Usual action |
|---|---|---|
| `flutter: command not found` | Flutter is not on `PATH` | Add the SDK's `bin` directory to `PATH` |
| Android toolchain error | Missing SDK component or license | Install components and accept licenses |
| No devices found | No emulator, simulator, browser, or device is available | Start or connect a run target |
| CocoaPods error | iOS dependencies are not configured | Install or repair CocoaPods on macOS |
Fix the Flutter command
Your shell finds commands by searching directories listed in the PATH environment variable. Add the Flutter SDK's bin directory to that variable, then open a new terminal.
For example, if the SDK is in ~/develop/flutter on Linux or macOS:
export PATH="$HOME/develop/flutter/bin:$PATH"
flutter doctorThis change lasts only for the current shell. Add the same export command to your shell startup file, such as ~/.zshrc or ~/.bashrc, if you want it to persist. On Windows, add the Flutter bin directory through the Environment Variables settings.
If flutter runs but points to an unexpected installation, inspect the selected executable:
which flutterOn Windows, use:
where.exe flutterRemove stale or duplicate Flutter paths when the result is not the SDK you intended to use.
Fix Android and iOS toolchain errors
For Android, open Android Studio's SDK Manager and install the Android SDK, platform tools, and a platform version required by your project. Then run:
flutter doctor --android-licenses
flutter doctorRead each license prompt and accept it only if it matches your development environment.
iOS development requires macOS, Xcode, and an iOS simulator or connected device. If Flutter reports a CocoaPods problem, install CocoaPods using the method recommended for your macOS setup, then run pod install from the iOS directory of the project. Do not delete lock files merely to hide a dependency conflict. Identify the package or version causing the conflict first.
Fix “no devices found”
A run target is where Flutter launches the app. Start an Android emulator or iOS simulator before running:
flutter emulators
flutter emulators --launch <emulator-id>
flutter devices
flutter runYou can also run in a browser or on a desktop target if that platform is enabled. A physical Android device may require Developer Options and USB debugging. Reconnect it, approve the computer on the device, and run flutter devices again.
Understand common project failures
Run commands from the directory containing pubspec.yaml. If dependencies are missing, use:
flutter pub get
flutter runIf generated files or cached package data appear inconsistent, try:
flutter clean
flutter pub get
flutter runflutter clean removes build output. It does not remove your Dart source code, but the next build takes longer.
Exercise
flutter doctor passes, but flutter run reports that no device is available. What should you check first?
Show answer
Run flutter devices, then start an emulator, simulator, browser, desktop target, or physical device and run the command again.