In Flutter, what do flutter config --jdk-dir and --android-sdk change, and how does the tool otherwise find a JDK and the Android SDK?
answer
- per-user settings, not per-project
- empty string removes a setting
- config first, then Android Studio
- ANDROID_HOME before ANDROID_SDK_ROOT
- platform flags like enable-web
basics
~10 sflutter config stores per-user overrides: --jdk-dir and --android-sdk pin the JDK and Android SDK paths. Without them Flutter tries Android Studio's JDK, then JAVA_HOME, then PATH, and reads ANDROID_HOME for the SDK.
solid answer
~40 s`flutter config` writes a per-user settings file that every Flutter command on that machine reads. `--android-sdk <path>` sets the Android SDK directory; without it Flutter uses `ANDROID_HOME`, then the deprecated `ANDROID_SDK_ROOT`, then well-known locations. `--jdk-dir <path>` sets the JDK; without it the order is the JDK bundled with the latest Android Studio, then `JAVA_HOME`, then `java` on `PATH`. Setting a value to an empty string removes it, and `flutter config --list` prints everything set. The same command toggles platforms: `--no-enable-web` or `--no-enable-android` hide a target from devices, `create` and doctor, and `--clear-features` restores the defaults. Afterwards the tool reminds you to restart open editors so they pick up the new settings.
code
bash · 6 linesflutter config --list
flutter config --jdk-dir "/Library/Java/JavaVirtualMachines/jdk-17/Contents/Home"
flutter config --android-sdk "$HOME/Android/Sdk"
flutter config --jdk-dir="" # remove the override, back to auto-discovery
flutter config --no-enable-web # hide web targets on this machine
flutter config --clear-features # restore every feature flag to its defaultgo deeper
Know that flutter config stores machine settings and that --android-sdk and --jdk-dir fix doctor errors about missing paths.
Explain the search order for the JDK and Android SDK, that the settings are per user, and that platform flags are on by default today.
Use doctor -v's JDK source line to resolve conflicting JDKs, clear stale overrides with an empty string, and trim unused platforms from doctor and device lists.
Decide what a team standardises at machine level versus in the repository, so setup is reproducible without hiding per-project SDK needs in personal config.
## What flutter config is `flutter config` (alias `flutter configure`) edits the Flutter tool's **per-user settings file**. It is not stored in a project and not in the SDK checkout: on macOS and Linux it lives under the user's config directory (`~/.config/flutter/settings` by default), and on Windows in a `.flutter_settings` file in the home directory. Every `flutter` invocation by that user reads it, whatever project or SDK version is running. That makes it the right place for machine facts — where this laptop's JDK and Android SDK live — and the wrong place for project decisions. ## Paths: --jdk-dir and --android-sdk The Android build needs two locations: an **Android SDK** and a **JDK** to run Gradle and `sdkmanager`. Flutter finds both automatically, and `flutter config` overrides the search. | Setting | Overrides | Search order when unset | |---|---|---| | `--android-sdk <dir>` | the Android SDK directory | `ANDROID_HOME`, then `ANDROID_SDK_ROOT` (deprecated), then well-known install locations | | `--jdk-dir <dir>` | the JDK home | JDK bundled with the latest Android Studio, then `JAVA_HOME`, then `java` on `PATH` | | `--android-studio-dir <dir>` | the Android Studio install | well-known install locations | The JDK order is the one that surprises people: **Android Studio's bundled JDK beats `JAVA_HOME`**. A developer who exports `JAVA_HOME` for another project can still see Flutter using a different JDK. `flutter doctor -v` shows the result as `Java binary at: <path>` followed by its source — Flutter configuration, Android Studio, `JAVA_HOME` or the system `PATH` — and a reminder of the `flutter config --jdk-dir` command. Practical rules: - Paths with spaces must be quoted, because extra words are rejected as `Too many arguments`. - **An empty string removes a setting**: `flutter config --jdk-dir=""` returns to automatic discovery. - `flutter config --list` prints every setting, including feature flags shown as `(Not set)` when they are at their default. ## Platform flags The same command toggles features, one flag per platform or experiment: 1. `--enable-web`, `--enable-android`, `--enable-ios`, `--enable-macos-desktop`, `--enable-linux-desktop`, `--enable-windows-desktop`. 2. Their `--no-` forms, which **disable** a target. 3. `--clear-features`, which removes every stored flag and restores the defaults. In current Flutter these platform features are **enabled by default on every channel**, so `flutter config --enable-web` is effectively a no-op on a fresh machine; old tutorials needed it when web was still opt-in. The useful direction today is the opposite. A developer who never targets the web can run `--no-enable-web` to drop Chrome from `flutter devices` and doctor, and a machine that only builds iOS can run `--no-enable-android` so the Android toolchain section disappears from doctor. Doctor's `Feature flags:` line in `-v` output lists what is enabled and any flag that differs from its default. ## Other settings worth knowing - `--build-dir` sets a relative build output directory; absolute paths are rejected. - `--analytics` / `--no-analytics` toggles the tool's usage reporting. - `--clear-ios-signing-settings` and `--select-ios-signing-settings` manage the saved development certificate choice for running on iOS devices. After any change the tool prints `You may need to restart any open editors for them to read new settings.` — IDE plugins cache the configuration. ## When to use which mechanism | Need | Use | |---|---| | This machine's JDK or SDK is in an unusual place | `flutter config --jdk-dir` / `--android-sdk` | | A shell session needs a different SDK temporarily | the `ANDROID_HOME` variable, which Flutter reads when no config value is set | | A project must build with a particular Flutter version | a per-project SDK pin, not `flutter config` |
- A teammate sets JAVA_HOME to JDK 21, but flutter doctor -v still reports another JDK. Why?Flutter consults `JAVA_HOME` only after two higher-priority sources: a `jdk-dir` in its config and the JDK bundled with the latest Android Studio. If either exists, it wins. The `Java binary at:` line says which source was used; `flutter config --jdk-dir` pins the JDK explicitly.
- Why is flutter config the wrong place to record a project's required SDK version?Its settings are per user and apply to every project that user builds, and nothing in them selects an SDK version. Paths and platform toggles describe the machine; a project's Flutter version belongs in a per-project pin that travels with the repository.
saying these in an interview costs you the question
- Believes flutter config writes into the project's pubspec.yaml
- Assumes JAVA_HOME always outranks Android Studio's bundled JDK
- Thinks flutter config --enable-web is still required before a web run
- Tries to remove a setting by deleting the SDK instead of passing an empty string
- Expects IDEs to pick up new settings without a restart