Skip to content

Expose Android package output items#11674

Open
Redth wants to merge 7 commits into
mainfrom
redth/android-publish-outputs
Open

Expose Android package output items#11674
Redth wants to merge 7 commits into
mainfrom
redth/android-publish-outputs

Conversation

@Redth

@Redth Redth commented Jun 16, 2026

Copy link
Copy Markdown
Member

Pull Request
title and
description
should follow the
commit-messages.md workflow documentation, and in particular should include:

  • Useful description of why the change is necessary.

    Android package outputs are currently hard for custom targets and CI workflows to discover because final APK/AAB paths are calculated during the build and dotnet publish re-discovers them with extension globs. This adds a stable @(ApplicationArtifact) item group so callers can consume authoritative application artifact paths without duplicating Android packaging logic, while leaving room for other .NET mobile platforms to populate the same item group.

    The implementation collects @(ApplicationArtifact) after copy/sign/universal APK creation and uses the same item group for publish outputs after dotnet publish copies packages to $(PublishDir). The custom metadata surface is intentionally small: PackageFormat, Signed, PackageId, and optional Abi for per-ABI APK outputs only. Package file names and paths are available through MSBuild well-known metadata such as %(Filename)%(Extension) and %(FullPath).

  • Links to issues fixed

    N/A

  • Unit tests

    Added coverage in XASdkTests.DotNetPublish for Debug APK and Release aab;apk publish outputs, including direct assertions that package entries flow through @(ResolvedFileToPublish) during _CalculateAndroidFilesToPublish, plus PackagingTest.CheckSignApk coverage for signed APK application artifacts including per-ABI cases and Abi metadata.

    Local validation included target XML parsing, git diff --check, and MSBuild smoke projects for package/publish item metadata and optional per-ABI Abi metadata. A full test-project build could not run in this worktree because external/xamarin-android-tools/src/Microsoft.Android.Build.BaseTasks/MSBuildReferences.projitems is missing.

Add metadata-rich AndroidPackageOutput and AndroidPublishedPackageOutput item groups so custom MSBuild targets and CI can discover final APK/AAB outputs without recalculating file names.

Wire the publish target to consume the package output items, cover publish/signing scenarios in tests, and document the new item metadata.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Comment thread Documentation/docs-mobile/building-apps/build-items.md Outdated
Comment thread src/Xamarin.Android.Build.Tasks/Xamarin.Android.Common.targets Outdated
Comment on lines +2681 to +2685
<Target Name="_CollectAndroidPackageOutputs"
Condition=" '$(AndroidApplication)' == 'true' "
DependsOnTargets="_ValidateAndroidPackageProperties">
<ItemGroup>
<AndroidPackageOutput Remove="@(AndroidPackageOutput)" />

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could the item group be created at evaluation time? Or does it need to be in a target?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good question. I think this needs to be target-time collection for this surface. A top-level ItemGroup would be evaluated before _GetAndroidPackageName / _ValidateAndroidPackageProperties have finalized $(_AndroidPackage) and before _CopyPackage, _Sign, and _CreateUniversalApkFromBundle have actually produced the files.

If we declared it at evaluation time, we would either need to predict paths that might not be produced for the current target graph, package format, per-ABI settings, or incremental state, or use Exists() / globs too early and get empty or stale results. Keeping this in a target lets us clear the item group and include only package files that actually exist after the package/sign targets run. Publish then updates the same @(AndroidPackageOutput) items to point at the copied files in $(PublishDir).

Redth and others added 5 commits June 16, 2026 16:56
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
@Redth Redth marked this pull request as ready for review June 16, 2026 21:28
@Redth Redth requested a review from simonrozsival as a code owner June 16, 2026 21:28
Copilot AI review requested due to automatic review settings June 16, 2026 21:28

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.

Pull request overview

This PR makes Android packaging outputs discoverable by introducing a stable @(AndroidPackageOutput) item group (and a GetAndroidPackageOutputs target) so custom targets and CI workflows can consume authoritative APK/AAB paths without reimplementing packaging logic.

Changes:

  • Add _CollectAndroidPackageOutputs + GetAndroidPackageOutputs, and wire collection into build/sign/package order so outputs are available after packaging/signing.
  • Update dotnet publish flow to publish packages via @(AndroidPackageOutput) (instead of filename globs) and then rewrite the item group to point at $(PublishDir) copies.
  • Add test coverage and documentation for the new item group.

Reviewed changes

Copilot reviewed 7 out of 7 changed files in this pull request and generated 3 comments.

Show a summary per file
File Description
src/Xamarin.Android.Build.Tasks/Xamarin.Android.Common.targets Adds package-output collection target and public target returning @(AndroidPackageOutput) with metadata.
src/Xamarin.Android.Build.Tasks/Microsoft.Android.Sdk/targets/Microsoft.Android.Sdk.BuildOrder.targets Schedules _CollectAndroidPackageOutputs after package/sign/universal APK creation and in related target dependency chains.
src/Xamarin.Android.Build.Tasks/Microsoft.Android.Sdk/targets/Microsoft.Android.Sdk.Publish.targets Publishes using @(AndroidPackageOutput) and updates items to the final publish paths after copy.
src/Xamarin.Android.Build.Tasks/Tests/Xamarin.Android.Build.Tests/XASdkTests.cs Adds dotnet publish assertions ensuring package outputs flow into ResolvedFileToPublish and @(AndroidPackageOutput).
src/Xamarin.Android.Build.Tasks/Tests/Xamarin.Android.Build.Tests/PackagingTest.cs Adds assertions that signed APK outputs (including per-ABI) appear in @(AndroidPackageOutput) with correct metadata.
Documentation/docs-mobile/building-apps/build-targets.md Mentions @(AndroidPackageOutput) for SignAndroidPackage (needs a section for the new GetAndroidPackageOutputs target).
Documentation/docs-mobile/building-apps/build-items.md Documents the new @(AndroidPackageOutput) item group and its metadata.

Comment on lines +314 to +332
<Project xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<Target Name="WriteAndroidPackageOutputItems" AfterTargets="Publish">
<WriteLinesToFile
File="$(MSBuildProjectDirectory)/android-package-output-items.txt"
Lines="%(AndroidPackageOutput.FullPath)|%(AndroidPackageOutput.Filename)%(AndroidPackageOutput.Extension)|%(AndroidPackageOutput.PackageFormat)|%(AndroidPackageOutput.Signed)|%(AndroidPackageOutput.PackageId)"
Overwrite="true" />
</Target>
<Target Name="WriteResolvedPackagePublishItems" AfterTargets="_CalculateAndroidFilesToPublish">
<ItemGroup>
<_ResolvedPackagePublishItem
Include="@(ResolvedFileToPublish)"
Condition=" '%(ResolvedFileToPublish.Extension)' == '.apk' Or '%(ResolvedFileToPublish.Extension)' == '.aab' " />
</ItemGroup>
<WriteLinesToFile
File="$(MSBuildProjectDirectory)/resolved-package-publish-items.txt"
Lines="@(_ResolvedPackagePublishItem->'%(FullPath)|%(RelativePath)')"
Overwrite="true" />
</Target>
</Project>
Comment on lines +551 to +558
<Project xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<Target Name="WriteAndroidPackageOutputItems" AfterTargets="Build">
<WriteLinesToFile
File="$(MSBuildProjectDirectory)/android-package-output-items.txt"
Lines="%(AndroidPackageOutput.Filename)%(AndroidPackageOutput.Extension)|%(AndroidPackageOutput.PackageFormat)|%(AndroidPackageOutput.Signed)|%(AndroidPackageOutput.PackageId)|%(AndroidPackageOutput.Abi)"
Overwrite="true" />
</Target>
</Project>
Comment on lines +156 to +158
Package files created by this target are available in the
[`@(AndroidPackageOutput)`](build-items.md#androidpackageoutput) item group.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
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.

3 participants