Skip to content

MAUI CLI: android install fails intermittently with 'Access denied' during cmdline-tools extraction on Windows #282

@rmarinho

Description

@rmarinho

Summary

maui android install intermittently fails on Windows during the cmdline-tools extraction step:

Installing Android SDK: Extracting: Extracting cmdline-tools... [android-tools:error] Failed to move to 'C:\Users\...\Android\sdk\cmdline-tools\19.0': Access to the path '...\extract-<guid>\cmdline-tools' is denied.

Root Cause

This is caused by a race condition in Xamarin.Android.Tools.AndroidSdk's FileUtil.ExtractAndInstall — tracked upstream at dotnet/android-tools#365.

The ExtractZipSafe call extracts files and disposes the ZipArchive, but Windows Defender's minifilter driver is still asynchronously scanning the newly created files when Directory.Move() executes immediately after. Since MoveFileExW requires exclusive access to the source directory tree, it fails with UnauthorizedAccessException.

Impact on MAUI CLI

When this happens during maui android install:

  1. The bootstrap fails (cmdline-tools not installed)
  2. The VS Code extension falls back to manual mode
  3. Manual mode also fails because sdkmanager was never installed
  4. Complete acquisition failure — user has no Android SDK

Suggested Fix (CLI-side)

Until android-tools adds retry logic in MoveWithRollback (see dotnet/android-tools#365), the MAUI CLI could add its own retry around the ExtractAndInstall call in the SDK bootstrap flow. This avoids re-downloading the archive on each retry.

Alternatively, when ExtractAndInstall fails with an access-denied error, the CLI could wait briefly and retry the Directory.Move portion specifically.

Workaround

In vscode-maui we've added:

  1. TEMP redirect: Redirect TEMP/TMP to a sibling directory of the SDK path (avoids cross-volume move issues)
  2. Retry with backoff: Retry the entire maui android install CLI command up to 2 additional times with exponential backoff when an access-denied error is detected

This works but is wasteful since it re-downloads the archive on each retry.

Environment

  • Windows 11, Windows Defender Real-Time Protection enabled
  • MAUI CLI 0.1.0-preview.9.26258.5
  • Xamarin.Android.Tools.AndroidSdk 1.0.143-preview.10
  • Triggered from VS Code MAUI extension (vscode-maui)

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions