dotnet / dotnet/android

Support version-pinned package installation in SdkManager

Open
#12,081 0 comments 0 reactions 0 assignees View on GitHub
android-tools enhancement needs-triage
Dominant language
C#
Stars
2.1k
Forks
579
Avg merge
1d 20h
Merged PRs (30d)
257

Description

## Summary

Add support for installing specific versions/revisions of SDK packages (e.g., `platforms;android-34` revision 2) rather than always getting the latest available version.

## Background

Google's [`android` CLI](https://developer.android.com/tools/agents/android-cli#sdk-install) supports a `package@version` syntax:

```bash
android sdk install platforms/android-34@2 # Install revision 2 specifically
android sdk install --force platforms/android-33@1 # Downgrade to revision 1
```

The underlying `sdkmanager` supports version selection through its arguments, but our `SdkManager.InstallAsync()` currently just passes raw package paths with no version disambiguation.

## Use Cases

1. **Reproducible CI builds**: Teams need to pin exact SDK package revisions across all build agents. Without version pinning, a CI pipeline may break when a new revision is published to the stable channel.
2. **Regression debugging**: When a new revision of build-tools or platforms introduces a regression, developers need to downgrade to the previous revision to isolate the issue.
3. **Compliance & auditing**: Enterprise environments require exact version manifests. Being able to install `build-tools;34.0.0` revision 1 vs revision 2 is critical for reproducibility.
4. **Parity with Google tooling**: The `android` CLI establishes `@version` as the standard syntax for version pinning.

## Proposed Changes

### 1. Parse version suffix

```csharp
// Helper to split "platforms;android-34@2" → ("platforms;android-34", "2")
public static (string Package, string? Version) ParseVersionedPackage(string input);
```

### 2. List all versions of a package

```csharp
// New: list all available revisions, not just latest
Task> ListPackageVersionsAsync(
string packagePath,
CancellationToken cancellationToken = default);
```

### 3. Install with version

```csharp
// Enhanced install that respects @version suffix
Task InstallAsync(IEnumerable packages,
bool acceptLicenses = true,
bool force = false, // allow downgrade
CancellationToken cancellationToken = default);
```

### 4. Force downgrade (`--force`)

Google's `android sdk install --force` allows reverting to an older package version. This likely maps to uninstall + reinstall of the specific version via sdkmanager.

## References

- [Android CLI `sdk install` docs](https://developer.android.com/tools/agents/android-cli#sdk-install) — `package[@version]` syntax, `--force` flag
- [Android CLI `sdk update` docs](https://developer.android.com/tools/agents/android-cli#sdk-update) — `--force` for downgrades
- Downstream consumer: `dotnet/maui-labs` CLI (`maui android sdk install` command)

Contributor guide

No contributing guide indexed for this repository

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.