Skip to content

Fix AcceptLicensesAsync silently ignoring exit code failures#288

Draft
Copilot wants to merge 4 commits intofeature/sdk-managerfrom
copilot/sub-pr-275
Draft

Fix AcceptLicensesAsync silently ignoring exit code failures#288
Copilot wants to merge 4 commits intofeature/sdk-managerfrom
copilot/sub-pr-275

Conversation

Copy link
Contributor

Copilot AI commented Feb 25, 2026

AcceptLicensesAsync discarded exitCode/stderr entirely, meaning genuine sdkmanager failures (bad JAVA_HOME, process errors, etc.) were silently treated as success.

Changes

  • Exit code handling in AcceptLicensesAsync: Non-zero exits now check output for known benign phrases before deciding to fail
    • Tolerated: output contains "licenses have already been accepted" or "all sdk package licenses accepted"
    • Otherwise: logs error and throws InvalidOperationException with stderr for diagnostics
if (exitCode != 0) {
    var output = (stdout ?? string.Empty) + Environment.NewLine + (stderr ?? string.Empty);
    var outputLower = output.ToLowerInvariant ();

    if (outputLower.Contains ("licenses have already been accepted") ||
        outputLower.Contains ("all sdk package licenses accepted")) {
        logger (TraceLevel.Info, $"License acceptance already completed (exit code {exitCode}).");
        return;
    }

    logger (TraceLevel.Error, $"License acceptance failed (exit code {exitCode}): {stderr}");
    throw new InvalidOperationException ($"Failed to accept SDK licenses: {stderr}");
}
  • Tests added for the exit code handling using a fake sdkmanager executable (shell script on Unix, .bat on Windows):
    • Exit code 0 completes successfully
    • Exit code 1 with "All SDK package licenses accepted." is tolerated (benign)
    • Exit code 1 with "Licenses have already been accepted." is tolerated (benign)
    • Exit code 1 with an unrecognized error message throws InvalidOperationException

✨ Let Copilot coding agent set things up for you — coding agent works faster and does higher quality work when set up for your repo.

rmarinho and others added 2 commits February 24, 2026 20:00
Adds SdkManager to Xamarin.Android.Tools.AndroidSdk for programmatic
Android SDK setup. Two-phase approach: manifest-driven bootstrap
downloads cmdline-tools, then delegates to sdkmanager CLI.

New files:
- SdkManager.cs: Bootstrap, list, install, uninstall, update, licenses
- EnvironmentVariableNames.cs: Centralized env var constants
- Models/Sdk/: SdkPackage, SdkLicense, SdkManifestComponent, etc.
- ProcessUtils.cs: Extended with StartProcess helpers
- SdkManagerTests.cs: Unit tests for parsing and configuration

Modified:
- JdkInfo.cs: Use EnvironmentVariableNames constants

Key design decisions:
- Manifest-driven (no hardcoded URLs), supports Google manifest
- XmlReader streaming parse, SHA-1 verification, Zip Slip protection
- p/invoke chmod on Unix, ArrayPool buffers on NET5_0_OR_GREATER
- License presentation API for IDE/CLI UI
- IDisposable, CancellationToken, netstandard2.0 compatible

Closes #271

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Co-authored-by: rmarinho <1235097+rmarinho@users.noreply.github.com>
Copilot AI changed the title [WIP] WIP address feedback on SDK bootstrap and sdkmanager wrapper PR Fix AcceptLicensesAsync silently ignoring exit code failures Feb 25, 2026
@rmarinho
Copy link
Member

@copilot how do we test this?

Co-authored-by: rmarinho <1235097+rmarinho@users.noreply.github.com>
Copy link
Contributor Author

Copilot AI commented Feb 25, 2026

@copilot how do we test this?

Added 4 tests in commit c35e787 using a fake sdkmanager shell script (.bat on Windows) that emits controlled output and exit codes:

  • AcceptLicensesAsync_ExitCodeZero_Succeeds — exit 0 completes normally
  • AcceptLicensesAsync_NonZeroWithAllLicensesAcceptedInStdout_Succeeds — exit 1 + "All SDK package licenses accepted." is tolerated
  • AcceptLicensesAsync_NonZeroWithLicensesAlreadyAcceptedInStdout_Succeeds — exit 1 + "Licenses have already been accepted." is tolerated
  • AcceptLicensesAsync_NonZeroWithUnknownError_Throws — exit 1 + unknown error text throws InvalidOperationException

@rmarinho rmarinho force-pushed the feature/sdk-manager branch 3 times, most recently from 6afcbfa to 05eefc5 Compare February 27, 2026 17:44
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.

2 participants