Why the “Android SDK license not accepted” error appears
When Flutter builds an Android app it invokes the Android SDK tools. If any of the required SDK components have an unaccepted license, the build process stops with the message "Android SDK license not accepted". This usually happens after a fresh SDK installation, after updating Android Studio, or when the ANDROID_HOME path points to a different SDK version.
Step‑by‑step guide to Fix Android SDK License
1. Verify that the Android SDK is installed correctly
Open Android Studio → Preferences (or Settings on Windows) → Appearance & Behavior → System Settings → Android SDK. Make sure the SDK path displayed matches the ANDROID_HOME environment variable you will set later.
2. Accept licenses using the built‑in Flutter command
Flutter provides a helper that walks you through each pending license. Run it from a terminal:
/// This Dart script runs the Flutter license‑acceptance command.
import 'dart:io';
Future main() async {
final result = await Process.run('flutter', ['doctor', '--android-licenses'], runInShell: true);
stdout.write(result.stdout);
stderr.write(result.stderr);
}When you execute the script (or simply run flutter doctor --android-licenses directly), you will be prompted to accept each license by typing y.
Tip: If the command hangs, ensure that your terminal has permission to executesdkmanager. Running the script withsudoon macOS/Linux may be required.
3. Accept licenses via the Android SDK manager (optional)
Some developers prefer to use the SDK manager directly. The following Dart snippet launches the sdkmanager tool and feeds it the --licenses flag:
/// Runs the Android SDK manager to accept all pending licenses.
import 'dart:io';
Future acceptAllLicenses() async {
final result = await Process.run(
'sdkmanager',
['--licenses'],
runInShell: true,
);
stdout.write(result.stdout);
stderr.write(result.stderr);
}After the script finishes, all SDK component licenses will be marked as accepted.
4. Set the required environment variables
- ANDROID_HOME – points to the root folder of the Android SDK (e.g.,
/Users/you/Library/Android/sdk). - PATH – must include
$ANDROID_HOME/toolsand$ANDROID_HOME/platform-tools.
On macOS/Linux you can add the following lines to ~/.bashrc or ~/.zshrc:
export ANDROID_HOME=$HOME/Library/Android/sdk
export PATH=$PATH:$ANDROID_HOME/tools:$ANDROID_HOME/platform-toolsOn Windows, set the variables through System Properties → Environment Variables.
5. Clean and rebuild the Flutter project
After the licenses are accepted and the environment is configured, clear any cached build artifacts and run the app again:
/// Helper to clean and rebuild a Flutter project.
import 'dart:io';
Future flutterCleanBuild() async {
await Process.run('flutter', ['clean'], runInShell: true);
await Process.run('flutter', ['pub', 'get'], runInShell: true);
await Process.run('flutter', ['run'], runInShell: true);
}If the build succeeds, the Fix Android SDK License problem is resolved.
Common pitfalls and how to avoid them
- Wrong SDK path: Double‑check that
ANDROID_HOMEpoints to the same SDK folder shown in Android Studio. - Missing
sdkmanager: The tool resides in$ANDROID_HOME/tools/bin. If it is missing, reinstall the "Command line tools" component from the SDK manager. - Running inside a CI environment: Use the non‑interactive flag
yes | sdkmanager --licensesor invoke the Dart script withProcess.runand pipeyautomatically.
Remember: Accepting the licenses is a one‑time operation per SDK installation. If you add new SDK components later, you may need to repeat step 2.
Verification
Run flutter doctor -v. The Android toolchain section should now display All Android licenses accepted.. If any warnings remain, repeat the steps above for the missing components.
Frequently Asked Questions
What does the "Android SDK license not accepted" error mean?
Flutter cannot compile Android code because one or more Android SDK components have pending license agreements. The build stops until those licenses are accepted.
Do I need to run the license command every time I build?
No. Licenses are stored in the SDK directory. You only need to accept them again if you install new SDK packages or switch to a different SDK installation.
Can I automate license acceptance in CI pipelines?
Yes. Use a non‑interactive command such as <code>yes | sdkmanager --licenses</code> or run a Dart script that executes <code>sdkmanager --licenses</code> and pipes <code>y</code> to it.
Why does <code>flutter doctor --android-licenses</code> sometimes hang?
The command may hang if the SDK tools are not on the PATH or if the terminal lacks execution permission. Ensure <code>ANDROID_HOME</code> and <code>PATH</code> are correctly set and that <code>sdkmanager</code> can be launched.
Is it safe to accept all Android SDK licenses?
Yes. The licenses are standard agreements from Google for using the SDK components. Accepting them is required for development and does not affect app distribution.