Skip to content

fix(cli): Android SDK auto-installation failing on Windows - #6892

Open
ndonkoHenri wants to merge 3 commits into
mainfrom
fix/windows-android-sdk-licenses
Open

ndonkoHenri wants to merge 3 commits into
mainfrom
fix/windows-android-sdk-licenses

Conversation

@ndonkoHenri

@ndonkoHenri ndonkoHenri commented Sep 25, 2026 •

Copy link
Copy Markdown
Contributor

Fixes #6522

Problem

On a Windows machine without an Android SDK, flet build apk did not install the SDK: it downloaded the command-line tools, declined every SDK license, installed none of the packages, and still reported Android SDK installed ✅. Flutter then failed with No Android SDK found.

The installer answered the license prompts with cmd.exe /C echo y | sdkmanager.bat …. The space before the pipe is part of what cmd's echo prints, so sdkmanager read "y " and treated it as "no". sdkmanager exits with 0 when it skips a package or when licenses are declined, and the installer only checked the exit code. A single answer could not have accepted the licenses anyway: --licenses asks once before showing them and then once per license.

Fixing that exposed a second problem, which affects every OS. cmdline-tools;latest now resolves to version 23.0 of the command-line tools, which replaces sdkmanager with a wrapper around Google's new Android CLI. The installer installed cmdline-tools;latest first and then used its sdkmanager for the remaining packages. The wrapper:

  • downloads the Android CLI (about 235 MB) into ~/.android on first use;
  • ignores --licenses;
  • rejects --no-metrics, so the Android CLI collects usage metrics by default;
  • on Windows, splits package names such as platforms;android-35 at the ;, because cmd treats ; as an argument separator, so those packages are never found;
  • on Windows 11 ARM64, where the x64-only android.exe runs emulated, exits with 0xC0000409 on every run, even when the package was installed. x64 Windows is untested.

Changes

  • sdkmanager runs directly on every OS, with its answers written to its standard input. This replaces the cmd.exe /C echo y | and sh -c 'yes | …' pipelines. processes.run() gets an input parameter for this.
  • The installer fails when a package directory or licenses/android-sdk-license is missing after sdkmanager returns, instead of trusting the exit code.
  • cmdline-tools;latest is no longer installed, and the pinned command-line tools (12.0) that the installer downloads are preferred over latest when both are present. Flutter only needs a cmdline-tools directory, of any version.
  • Changelog entry.

Not in this PR: an SDK whose only command-line tools are 23.0, for example Android Studio's "Command-line Tools (latest)", still goes through the wrapper when a package is missing, as on 1.0.1. Installing the pinned tools in that case, without prompting users whose SDK is already complete, needs a separate change to install().

Testing

  • Windows 11 ARM64 VM, installing into an empty folder with AndroidSDK.install(), which is what flet build apk runs when no SDK is found:
    • 1.0.1 reproduced the issue. sdkmanager's stdin received b'y \r\n', and only the downloaded command-line tools ended up on disk, with no licenses accepted, yet install() returned normally.
    • This branch installed platform-tools, platforms;android-35 and build-tools;34.0.0 and accepted all 7 licenses, with every sdkmanager call going through the pinned 12.0 tools. It also completed an SDK that already had 23.0 as latest.
    • Calling the 23.0 sdkmanager.bat and android.exe directly on the same VM confirmed the ; splitting and the 0xC0000409 exit codes.
  • macOS, with the real sdkmanager in throwaway SDK folders: an install into an empty folder passes, and feeding the same "y " answer makes the installer raise Error installing Android SDK package "platform-tools" instead of returning.
  • The flet-cli tests and ruff pass.

Test code

import os
import tempfile
from pathlib import Path

from flet_cli.utils.android_sdk import AndroidSDK
from flet_cli.utils.jdk import install_jdk

sdk = Path(tempfile.mkdtemp())  # an empty folder is handled like a missing SDK
os.environ["ANDROID_HOME"] = str(sdk)
AndroidSDK(install_jdk(print), print).install()
print(sorted(p.name for p in sdk.iterdir()))

Summary by Sourcery

Fix Android SDK installation reliability across platforms by using the pinned SDK tools, accepting licenses through standard input, and validating installation results.

Bug Fixes:

  • Fix Android SDK auto-installation on Windows by reliably accepting licenses and verifying that required packages and license files were actually installed.

Enhancements:

  • Prefer the pinned command-line tools over the newer latest tools to avoid incompatible SDK manager behavior across platforms.
  • Support sending input to subprocesses for interactive command execution.

On Windows the installer answered the license prompts with
`cmd.exe /C echo y | sdkmanager.bat ...`. The space before the pipe is part
of what cmd's `echo` prints, so sdkmanager read "y " and declined every
license, which skipped each package. sdkmanager exits with 0 when it skips a
package or when licenses are declined, so the installer reported the SDK as
installed and Flutter later failed with "No Android SDK found". A single
answer could not have accepted the licenses anyway: `--licenses` asks once
before the licenses and once per license.

sdkmanager now runs directly on every platform, with its answers written to
its standard input, and the installer fails when a package directory or the
SDK license file is missing after sdkmanager returns.
Version 23.0 of the Android SDK command-line tools replaces sdkmanager with
a wrapper around the Android CLI. The wrapper downloads the Android CLI on
first use and ignores `--licenses`. It also rejects `--no-metrics`, so the
Android CLI collects usage metrics by default. On Windows, the wrapper
splits package names such as `platforms;android-35` at the `;`. On Windows 11
ARM64, where the x64 `android.exe` runs emulated, every Android CLI run
exits with 0xC0000409, even after installing the package.

Installing `cmdline-tools;latest` brought that version into every new SDK
and made it the sdkmanager used for the remaining packages. Flutter only
needs a `cmdline-tools` directory, so the pinned version that the installer
downloads is enough. `cmdline-tools;latest` is no longer installed, and the
pinned version is preferred over `latest` when both are present.

@sourcery-ai sourcery-ai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hey - I've reviewed your changes and they look great!


Sourcery is free for open source - if you like our reviews please consider sharing them ✨

@cloudflare-workers-and-pages

cloudflare-workers-and-pages Bot commented Sep 25, 2026 •

Copy link
Copy Markdown

Deploying flet-website-v2 with  Cloudflare Pages  Cloudflare Pages

Latest commit: bec12f4
Status: ✅  Deploy successful!
Preview URL: https://a3cadfda.flet-website-v2.pages.dev
Branch Preview URL: https://fix-windows-android-sdk-lice.flet-website-v2.pages.dev

View logs

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot review overview

🟡 Changes recommended

The implementation appears sound, but GitHub currently reports unresolved merge conflicts.

Review effort: Balanced
Findings: None

What changed in this PR

Fixes Android SDK auto-installation by reliably accepting licenses and validating installed packages.

Changes:

  • Sends SDK manager responses through standard input.
  • Prefers pinned command-line tools 12.0 and verifies installation results.
  • Adds the 1.0.2 changelog entry.
File Description
processes.py Adds subprocess input support.
android_sdk.py Fixes SDK package and license installation.
CHANGELOG.md Documents the Windows fix.

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

bug: running flet build apk without Android SDK installed fails to properly install Android SDK

2 participants