Skip to content

[Xamarin.Android.Build.Tasks] Move <CollectJarContentFilesForArchive/> to MABT - #13612

Merged
jonathanpeppers merged 1 commit into
mainfrom
simonrozsival-move-collect-jar-content-task
Nov 19, 2026
Merged

jonathanpeppers merged 1 commit into
mainfrom
simonrozsival-move-collect-jar-content-task

Conversation

@simonrozsival

Copy link
Copy Markdown
Member

Context: 5d51368

<CollectJarContentFilesForArchive/> runs on every APK and AAB package build (_BuildApkEmbed and _BuildApkFastDev). It opens and hashes every Java library to collect the extra JAR resources that go into the archive. Today it derives from AndroidTask, which captures the process working directory, and it resolves JAR paths and @(LibraryProjectJars) wildcards against that directory. That is incorrect when several projects build concurrently in one MSBuild process. It also prevents the task from being marked [MSBuildMultiThreadableTask], so multithreaded (-mt) builds cannot run it in-process.

Move the task to Microsoft.Android.Build.Tasks as Microsoft.Android.Tasks.CollectJarContentFilesForArchive, derive it from MultithreadedAndroidTask, mark it [MSBuildMultiThreadableTask], and resolve every file path through TaskEnvironment. Register it for Core and Full MSBuild like the other .NET tasks (Runtime="NET", plus TaskHostFactory on Full). The task's parameters, outputs, include and exclude matching, and XA4330 handling are unchanged. Delete the legacy task rather than maintain two implementations.

Shared helpers

The JAR helpers the task needs move from MonoAndroidHelper.cs into a new partial, MonoAndroidHelper.JavaLibraries.cs, which both task assemblies compile. They are SizeAndContentFileComparer, ExpandFiles(), the TaskEnvironment overloads of DistinctFilesByContent(), and IsEmbeddedReferenceJar(). <DetermineJavaLibrariesToCompile/> and <CheckDuplicateJavaLibraries/> already use these helpers, so they can move later without duplicating code. ExpandFiles() now takes a TaskEnvironment. It still returns paths that use the item's original directory spelling, so __reference__ JARs are still filtered as before. The DistinctFilesByContent() overloads without a TaskEnvironment no longer have callers and are removed.

ELFHelper.StreamHasBinaryBlobSoname() and its private helpers move into ELFHelper.Shared.cs, which is also linked into Microsoft.Android.Build.Tasks. The rest of ELFHelper depends on ELFInfo and MonoAndroidHelper.ZipAlignmentToPageSize(), which are not available there.

Matching semantics

@(AndroidPackagingOptionsExclude) and @(AndroidPackagingOptionsInclude) keep their existing semantics: case-insensitive, unanchored regexes in which only *, ?, and . are translated. The SDK defaults depend on regex syntax such as ^(|root/)R.txt$, and projects can copy those patterns. FileSystemName.MatchesSimpleExpression() cannot express them, and [GeneratedRegex] cannot be used because the patterns are only known at build time. The regex construction is therefore unchanged.

This change makes no performance claims; build time was not measured.

Validation

  • dotnet build src/Microsoft.Android.Build.Tasks/Microsoft.Android.Build.Tasks.csproj -c Debug -m -mt -nr:false -warnaserror:MSB4286,MSB4287,MSB4288: 0 warnings, 0 errors. Microsoft.Build.TaskAuthoring.Analyzer reports no thread-safety violations.
  • ./dotnet-local.sh build src/Xamarin.Android.Build.Tasks/Xamarin.Android.Build.Tasks.csproj -c Debug: 0 errors.
  • ./dotnet-local.sh test bin/TestDebug/net11.0/Xamarin.Android.Build.Tests.dll --filter "FullyQualifiedName~CheckDuplicateJavaLibrariesTests|FullyQualifiedName~DetermineJavaLibrariesToCompile", which exercises the shared helpers: 7 passed.
  • The packaging integration tests that cover include and exclude behavior (CheckExcludedFilesAreMissing, CheckExcludedFilesCanBeModified, CheckIncludedFilesArePresent) could not run locally: the local workload setup fails with NETSDK1147 (missing wasm-tools) before the task runs. CI provides this coverage.

…> to Microsoft.Android.Build.Tasks

Move the task to Microsoft.Android.Build.Tasks as a multithreadable task that resolves paths through TaskEnvironment, and share the Java library helpers it needs with Xamarin.Android.Build.Tasks.

Co-authored-by: Copilot App <[email protected]>
Copilot AI balanced review requested due to automatic review settings November 18, 2026 11:10

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.

🟡 Changes recommended

The working-directory fix lacks a regression test exercising the task across separate project directories to verify resource isolation, wildcard handling, and reference-JAR exclusion.

1 open issue
What changed in this PR

Moves CollectJarContentFilesForArchive into Microsoft.Android.Build.Tasks so JAR resource collection uses project-specific paths and supports in-process multithreaded MSBuild execution.

Changes:

  • Migrates the collector to MultithreadedAndroidTask and resolves paths through TaskEnvironment.
  • Extracts shared Java-library and ELF helpers while preserving packaging matching and reference-JAR filtering.
  • Updates task registration for Core and Full MSBuild and links the required shared sources.
File Description
src/​Xamarin.Android.Build.Tasks/​Xamarin.Android.Common.targets Registers the migrated task for Core and Full MSBuild.
src/​Xamarin.Android.Build.Tasks/​Utilities/​MonoAndroidHelper.JavaLibraries.cs Shares JAR helpers and adds project-relative wildcard resolution.
src/​Xamarin.Android.Build.Tasks/​Utilities/​MonoAndroidHelper.cs Removes extracted helpers and unused overloads.
src/​Xamarin.Android.Build.Tasks/​Utilities/​ELFHelper.Shared.cs Extracts shared binary-blob SONAME detection.
src/​Xamarin.Android.Build.Tasks/​Utilities/​ELFHelper.cs Makes the helper partial and removes extracted methods.
src/​Microsoft.Android.Build.Tasks/​Tasks/​CollectJarContentFilesForArchive.cs Migrates the collector and adopts task-scoped path resolution.
src/​Microsoft.Android.Build.Tasks/​Microsoft.Android.Build.Tasks.csproj Links shared helpers and packaging utilities.

Review effort: Balanced

jarFiles = JavaLibraries;

var libraryProjectJars = MonoAndroidHelper.ExpandFiles (LibraryProjectJars)
var libraryProjectJars = MonoAndroidHelper.ExpandFiles (LibraryProjectJars, TaskEnvironment)
@jonathanpeppers

Copy link
Copy Markdown
Member

/review

@github-actions

github-actions Bot commented Nov 18, 2026 •

Copy link
Copy Markdown
Contributor

✅ Android PR Reviewer completed successfully!

Generated by Android PR Reviewer for #13612

@github-actions github-actions Bot 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.

⚠️ Needs Changes

Findings: 0 errors, 1 previously reported warning, 0 new findings. I have not duplicated the existing inline comment.

The task-level regression-test warning remains applicable: the existing helper tests exercise content deduplication and DetermineJavaLibrariesToCompile, but do not invoke the migrated task or ExpandFiles. The packaging tests exercise resource matching, not isolation between different project directories under -mt.

The implementation otherwise looks coherent. File enumeration, hashing, and archive reads use project-rooted paths; wildcard expansion preserves the spelling needed by the reference-JAR filter; and the include/exclude and reserved-SONAME logic is preserved. Both packaging call sites resolve through the updated task registration.

CI: All 39 GitHub checks report success, including the aggregate Azure DevOps check for build 1687672. Independent Azure build/timeline verification was blocked because az devops invoke required authentication. This review was based on source inspection; no local tests were run.

Generated by Android PR Reviewer for #13612 · copilot · gpt61 · 45.6 AIC · ⌖ 7.94 AIC · ⊞ 20.3K
Comment /review to run again

@jonathanpeppers
jonathanpeppers merged commit 32c581f into main Nov 19, 2026
39 checks passed
@jonathanpeppers
jonathanpeppers deleted the simonrozsival-move-collect-jar-content-task branch November 19, 2026 18:56
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