Expose Android package output items#11674
Conversation
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>
| <Target Name="_CollectAndroidPackageOutputs" | ||
| Condition=" '$(AndroidApplication)' == 'true' " | ||
| DependsOnTargets="_ValidateAndroidPackageProperties"> | ||
| <ItemGroup> | ||
| <AndroidPackageOutput Remove="@(AndroidPackageOutput)" /> |
There was a problem hiding this comment.
Could the item group be created at evaluation time? Or does it need to be in a target?
There was a problem hiding this comment.
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).
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>
There was a problem hiding this comment.
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 publishflow 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. |
| <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> |
| <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> |
| 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>
Pull Request
title and
description
should follow the
commit-messages.mdworkflow 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 publishre-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 afterdotnet publishcopies packages to$(PublishDir). The custom metadata surface is intentionally small:PackageFormat,Signed,PackageId, and optionalAbifor 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.DotNetPublishfor Debug APK and Releaseaab;apkpublish outputs, including direct assertions that package entries flow through@(ResolvedFileToPublish)during_CalculateAndroidFilesToPublish, plusPackagingTest.CheckSignApkcoverage for signed APK application artifacts including per-ABI cases andAbimetadata.Local validation included target XML parsing,
git diff --check, and MSBuild smoke projects for package/publish item metadata and optional per-ABIAbimetadata. A full test-project build could not run in this worktree becauseexternal/xamarin-android-tools/src/Microsoft.Android.Build.BaseTasks/MSBuildReferences.projitemsis missing.