Skip to content

[Microsoft.Android.Sdk] Ship .NET 12 Android as NuGet library packs - #13769

Open
jonathanpeppers wants to merge 9 commits into
mainfrom
jonathanpeppers-android-library-packs
Open

jonathanpeppers wants to merge 9 commits into
mainfrom
jonathanpeppers-android-library-packs

Conversation

@jonathanpeppers

@jonathanpeppers jonathanpeppers commented Nov 24, 2026 •

Copy link
Copy Markdown
Member

Agent assessment

Self-reported assessment, not an independent review.

Assessed revision: 133c6c84225df331167614d851afe0800f1625a0

Dimension Assessment Rationale
Change confidence 6/10 ↑ All failures from CI build 1699465 that this PR caused now have a fix: UnsupportedMonoAotPropertyFailsBuild passes locally (6 of 6), and the net11.0 reference assertion passes locally.
↑ dotnet restore then dotnet run installs the app and passes the environment variables on a Pixel 6 Pro.
↑ The Tools packages pack locally without .symbols.nupkg files; the changed pipeline YAML files parse.
↓ CI has not run on this revision. The signing and MSI conversion changes run only in the official Xamarin.Android pipeline, so they are not verified.
↓ Device tests were not run through the test runner locally.
↓ dotnet run before restore stays broken until dotnet/sdk#57403 is fixed.
↓ The package rename affects downstream consumers (dotnet/maui darc, VS insertion).

Context: https://gist.github.com/jonathanpeppers/3266a1498009182dd9df434e32e52734

This is the first step towards building Android apps without a workload. .NET 12 projects get the Android build from the Microsoft.Android NuGet package. The android workload stays for now, but it lists all of our packages as "kind": "library" packs, as dotnet/maui does, so restore works offline. Later, we can delete the workload and move the remaining targets to dotnet/sdk.

Packages

  • Microsoft.Android: one dependency group per net12.0-android[API]. It is a multi-targeted Microsoft.Build.NoTargets project.
  • Microsoft.Android.net12.0: MSBuild targets, tasks, analyzer, and the native runtimes in native/[runtime]/[rid]/. NuGet does not know about runtime flavors, so the _AndroidResolveRuntimePackageAssets target adds these files.
  • Microsoft.Android.net12.0.Ref.[API]: Mono.Android.dll and Java.Interop.dll, as ref/ and runtimes/android/lib/ assets.
  • Microsoft.Android.Tools.[Darwin|Linux|Windows]: tools/aapt2. Each package sets $(Aapt2ToolPath) only on its own OS. These packages contain no pdbs, so they have no .symbols.nupkg.

These replace the Microsoft.Android.Sdk.[OS], Microsoft.Android.Ref.[API], and Microsoft.Android.Runtime.* packs, and the implicit FrameworkReference items.

Workload

Restore does not import targets from packages, so WorkloadManifest.targets sets only what restore needs: $(TargetPlatformSupported), the default $(TargetPlatformVersion), $(RuntimeIdentifiers), and the properties that request the ILLink, Crossgen2, and NativeAOT packs. It also sets $(MicrosoftAndroidPackageVersion). A project without a Microsoft.Android PackageReference fails with the new XA1052 error. net11.0-android projects still use the Microsoft.Android.Sdk.net11 workload pack.

The templates add the PackageReference with the version of the templates. In this repo, Directory.Build.targets adds it.

Local builds

ConfigureLocalWorkload packs the packages with $(AndroidPackVersion) into bin/[Configuration]/dotnet/library-packs, and removes old extracted copies from the NuGet cache. After you edit .targets files, run it again.

Restore

Restore, and the first evaluation of dotnet run, do not import targets from packages:

  • WorkloadManifest.targets sets $(RunAOTCompilation) to false during restore. Otherwise the Mono workload requests its AOT packs and restore fails with NETSDK1147: ... mobile-librarybuilder, instead of the build reporting XA1044.
  • Known limitation: dotnet run on a project that was never restored builds the app, but does not install it. The SDK evaluates the project before restore and reuses that evaluation for ComputeAvailableDevices and DeployToDevice: dotnet run skips ComputeAvailableDevices and DeployToDevice when they come from a NuGet package and the project is not restored sdk#57403. Templates restore when they create the project, so dotnet new android followed by dotnet run works. DotNetRunEnvironmentVariables now runs dotnet restore first.

CI

aapt2 comes from Google's prebuilt build-tools archives for all three OSes, so the macOS job builds all three Tools packages. Before, the Linux job also built Microsoft.Android.Tools.Linux, which gave two packages with the same id and version but different bytes. The Linux job now only builds and checks the SDK. The nuget-linux-* artifacts and the Linux signing job are removed. The MSI conversion skips *Linux* packages, as it does for *Darwin*.

Open questions

  • SignList.xml now matches aapt2 by file name. The internal Arcade signing already did this. I did not check the sign-artifacts template in azure-pipelines.yaml.
  • dotnet/maui consumes Microsoft.Android.Sdk.Windows through darc; it must change to Microsoft.Android.
  • The XA1052 text is in WorkloadManifest.targets, so it is not localized.

Validation

On Windows, with the local SDK:

  • dotnet-local.cmd test bin\TestDebug\net11.0\Xamarin.Android.Build.Tests.dll with filters for DotNetNew, DotNetPublish, MauiTargetFramework (net11.0 and net12.0), BuildAfterUpgradingNuget, RuntimeLibraryFiltering, SdkPackageDoesNotContainCPlusPlusArchives, trimmable typemap (CoreCLR and NativeAOT), CheckIncludedAssemblies, CheckIncludedNativeLibraries, DotNetBuildLibrary, DotNetBuildBinding, and ProjectDependencies: all passed. Skipped cases are unsupported configurations.
  • After the CI test fixes: CodeBehindTests, MultiTfmTransitiveReference, InvalidR8ObfuscationModeIsValidatedOnlyForR8, and CompareAapt2AndManagedParserOutput: 34 passed.
  • Microsoft.Android.Tools.proj for Darwin, Linux, and Windows: three .nupkg files, no .symbols.nupkg.
  • After merging main: DotNetNew, SuccessfulBuildFew, InvalidR8ObfuscationModeIsValidatedOnlyForR8, MultiTfmTransitiveReference, BuildAfterUpgradingNuget, and MauiTargetFramework: 36 passed, 2 skipped. The tests/TrimmingTests case BooleanAndCharCallbacks.cs builds.
  • After the latest merge of main: Xamarin.Android.Build.Tests.csproj and Xamarin.Android.Build.Tasks build with 0 errors. I did not run tests again.
  • dotnet-local.cmd test --test-modules bin/TestDebug/net11.0/Xamarin.Android.Build.Tests.dll --filter "Name~UnsupportedMonoAotPropertyFailsBuild": failed 2 of 6 before the RunAOTCompilation change, 6 of 6 passed after it.
  • By hand on a Pixel 6 Pro, an app from dotnet new android --no-restore: dotnet run -e RUNENV_FOO=... without restore does not install the app (Invalid packageName); after dotnet restore, it installs, starts, and logs the variable.
  • Microsoft.Android.Build.Tasks.Tests with GenerateTrimmableTypeMap: 64 passed.
  • Debug, Release, and NativeAOT template apps start on a Pixel 6 Pro.

I did not run the full test suites or MSBuildDeviceIntegration locally. On Windows, its teardown runs adb kill-server, which would disconnect the devices shared with other work on this machine.

jonathanpeppers and others added 2 commits November 24, 2026 16:04
Context: https://gist.github.com/jonathanpeppers/3266a1498009182dd9df434e32e52734

As an intermediate step towards workload-free Android builds, .NET 12 projects get the Android build from the `Microsoft.Android` NuGet. The `android` workload stays, but it lists all of our packages as `"kind": "library"` packs (like dotnet/maui), so restore works offline. A future step deletes the workload and moves the remaining targets to dotnet/sdk.

### Packages

  * `Microsoft.Android`: one dependency group per `net12.0-android[API]`. It is a multi-targeted `Microsoft.Build.NoTargets` project, packed after the packages below.
  * `Microsoft.Android.net12.0`: MSBuild targets, tasks, analyzer, `buildTransitive/` props, and the native runtimes in `native/[runtime]/[rid]/`. NuGet does not know about runtime flavors, so the `_AndroidResolveRuntimePackageAssets` target adds these files.
  * `Microsoft.Android.net12.0.Ref.[API]`: `Mono.Android.dll` and `Java.Interop.dll`, as `ref/` and `runtimes/android/lib/` assets.
  * `Microsoft.Android.Tools.[Darwin|Linux|Windows]`: `tools/aapt2`. Each one sets `$(Aapt2ToolPath)` only on its own host OS. `SignList.xml` now matches `aapt2` by file name.

These replace the `Microsoft.Android.Sdk.[OS]`, `Microsoft.Android.Ref.[API]`, and `Microsoft.Android.Runtime.*` packs, and the `FrameworkReference` items.

### Workload

`WorkloadManifest.targets` only sets what restore needs, because restore does not import targets from packages: `$(TargetPlatformSupported)`, the default `$(TargetPlatformVersion)`, `$(RuntimeIdentifiers)`, and the properties that request the ILLink, Crossgen2, and NativeAOT packs. It also sets `$(MicrosoftAndroidPackageVersion)`. Without a `Microsoft.Android` `PackageReference`, the build fails with the new XA1052 error. net11.0-android projects still use the `Microsoft.Android.Sdk.net11` workload pack.

Projects must add:

```xml
<PackageReference Include="Microsoft.Android" Version="..." />
```

The templates add it with the version of the templates. In this repository, `Directory.Build.targets` adds it with `$(MicrosoftAndroidPackageVersion)`.

### Local builds

`ConfigureLocalWorkload` packs the library packs with `$(AndroidPackVersion)` into `bin/[Configuration]/dotnet/library-packs`, and removes the extracted copies from the NuGet cache. After editing `.targets` files, run it again. Test projects extract the packages from `library-packs`.

### Validation

  * `dotnet-local.cmd test bin\TestDebug\net11.0\Xamarin.Android.Build.Tests.dll` with focused filters: `DotNetNew`, `DotNetPublish`, `MauiTargetFramework` (net11.0 and net12.0), `BuildAfterUpgradingNuget`, `RuntimeLibraryFiltering`, `SdkPackageDoesNotContainCPlusPlusArchives`, trimmable typemap tests (CoreCLR and NativeAOT), `CheckIncludedAssemblies`, `CheckIncludedNativeLibraries`, `DotNetBuildLibrary`, `DotNetBuildBinding`, `ProjectDependencies`: all passed; skipped cases are unsupported configurations.
  * `dotnet-local.cmd test` for `Microsoft.Android.Build.Tasks.Tests` with `GenerateTrimmableTypeMap`: 64 passed.
  * Debug, Release, and NativeAOT template apps start on a Pixel 6 Pro.

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
  * CodeBehindTests and MultiTfmTransitiveReference build projects
    outside the repository, so add the Microsoft.Android PackageReference
    in the tests (XA1052).
  * InvalidR8ObfuscationModeIsValidatedOnlyForR8: restore, so the
    package targets are imported (MSB4057).
  * TestEnvironment: make extracted package files executable on Unix,
    like NuGet does, so tools/aapt2 can run.
  * DotNetInstallAndRunMinorAPILevels: net11.0 projects use
    Microsoft.Android.Ref.[API], not the net12.0 packages.
  * InstallWithoutSharedRuntime: Install with fast deployment only
    builds the device ABI. The test did not check anything before, because
    GetSupportedRuntimes returned nothing.

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
jonathanpeppers and others added 4 commits November 30, 2026 08:19
net11.0 targeting-pack references have no NuGetPackageId metadata, so
check the path of @(ReferencePath) instead.

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
…id-library-packs

# Conflicts:
#	src/Xamarin.Android.Build.Tasks/Microsoft.Android.Sdk/in/Microsoft.Android.Sdk.BundledVersions.in.targets
#	tests/Mono.Android-Tests/Directory.Build.targets
…id-library-packs

# Conflicts:
#	src/Xamarin.Android.Build.Tasks/Tests/Xamarin.Android.Build.Tests/NativeAotBuildTests.cs
#	src/Xamarin.Android.Build.Tasks/Tests/Xamarin.Android.Build.Tests/XASdkTests.cs
#	tests/MSBuildDeviceIntegration/Tests/InstallTests.cs
Restore does not import the Microsoft.Android package targets, so the
Mono workload saw $(RunAOTCompilation)=true and requested its AOT packs:

    error NETSDK1147: To build this project, the following workloads must be installed: mobile-librarybuilder

Set $(RunAOTCompilation) to false during restore in WorkloadManifest.targets,
which is imported before the Mono workload's. The build still reports
XA1044, because the package targets read the project's value.

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
`dotnet run` evaluates the project before restore and reuses that
evaluation for DeployToDevice, so on a project that was never restored it
does not find the target from the Microsoft.Android NuGet and skips
deployment: dotnet/sdk#57403

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
@jonathanpeppers

Copy link
Copy Markdown
Member Author

/azp run Xamarin.Android-PR

@azure-pipelines

Copy link
Copy Markdown
No pipelines are associated with this pull request.

jonathanpeppers and others added 2 commits December 2, 2026 11:51
The macOS job already builds all three Microsoft.Android.Tools packages. The Linux job built Microsoft.Android.Tools.Linux again from the same prebuilt Google aapt2, which gave two packages with the same id and version but different bytes. The Linux job now only builds and checks the SDK; the Linux signing job and the nuget-linux-* artifacts are removed.

The Tools packages contain no pdbs, so do not create .symbols.nupkg files for them.

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
@jonathanpeppers
jonathanpeppers marked this pull request as ready for review December 2, 2026 17:58
Copilot AI balanced review requested due to automatic review settings December 2, 2026 18:14

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 was unable to review this pull request due to rate limiting. Please try again later. See Usage limits for GitHub Copilot for details.

This branch has not been deployed

No deployments
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