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:
- The bootstrap fails (cmdline-tools not installed)
- The VS Code extension falls back to manual mode
- Manual mode also fails because
sdkmanager was never installed
- 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:
- TEMP redirect: Redirect
TEMP/TMP to a sibling directory of the SDK path (avoids cross-volume move issues)
- 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)
Summary
maui android installintermittently 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'sFileUtil.ExtractAndInstall— tracked upstream at dotnet/android-tools#365.The
ExtractZipSafecall extracts files and disposes theZipArchive, but Windows Defender's minifilter driver is still asynchronously scanning the newly created files whenDirectory.Move()executes immediately after. SinceMoveFileExWrequires exclusive access to the source directory tree, it fails withUnauthorizedAccessException.Impact on MAUI CLI
When this happens during
maui android install:sdkmanagerwas never installedSuggested Fix (CLI-side)
Until
android-toolsadds retry logic inMoveWithRollback(see dotnet/android-tools#365), the MAUI CLI could add its own retry around theExtractAndInstallcall in the SDK bootstrap flow. This avoids re-downloading the archive on each retry.Alternatively, when
ExtractAndInstallfails with an access-denied error, the CLI could wait briefly and retry theDirectory.Moveportion specifically.Workaround
In
vscode-mauiwe've added:TEMP/TMPto a sibling directory of the SDK path (avoids cross-volume move issues)maui android installCLI command up to 2 additional times with exponential backoff when an access-denied error is detectedThis works but is wasteful since it re-downloads the archive on each retry.
Environment
Xamarin.Android.Tools.AndroidSdk1.0.143-preview.10vscode-maui)