Repository navigation
[Xamarin.Android.Build.Tasks] Move <CollectJarContentFilesForArchive/> to MABT - #13612
Conversation
…> 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]>
There was a problem hiding this comment.
🟡 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
MultithreadedAndroidTaskand resolves paths throughTaskEnvironment. - 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) |
|
/review |
|
✅ Android PR Reviewer completed successfully!
|
There was a problem hiding this comment.
⚠️ 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

Context: 5d51368
<CollectJarContentFilesForArchive/>runs on every APK and AAB package build (_BuildApkEmbedand_BuildApkFastDev). It opens and hashes every Java library to collect the extra JAR resources that go into the archive. Today it derives fromAndroidTask, 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.TasksasMicrosoft.Android.Tasks.CollectJarContentFilesForArchive, derive it fromMultithreadedAndroidTask, mark it[MSBuildMultiThreadableTask], and resolve every file path throughTaskEnvironment. Register it for Core and Full MSBuild like the other .NET tasks (Runtime="NET", plusTaskHostFactoryon Full). The task's parameters, outputs, include and exclude matching, andXA4330handling are unchanged. Delete the legacy task rather than maintain two implementations.Shared helpers
The JAR helpers the task needs move from
MonoAndroidHelper.csinto a new partial,MonoAndroidHelper.JavaLibraries.cs, which both task assemblies compile. They areSizeAndContentFileComparer,ExpandFiles(), theTaskEnvironmentoverloads ofDistinctFilesByContent(), andIsEmbeddedReferenceJar().<DetermineJavaLibrariesToCompile/>and<CheckDuplicateJavaLibraries/>already use these helpers, so they can move later without duplicating code.ExpandFiles()now takes aTaskEnvironment. It still returns paths that use the item's original directory spelling, so__reference__JARs are still filtered as before. TheDistinctFilesByContent()overloads without aTaskEnvironmentno longer have callers and are removed.ELFHelper.StreamHasBinaryBlobSoname()and its private helpers move intoELFHelper.Shared.cs, which is also linked intoMicrosoft.Android.Build.Tasks. The rest ofELFHelperdepends onELFInfoandMonoAndroidHelper.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.Analyzerreports 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.CheckExcludedFilesAreMissing,CheckExcludedFilesCanBeModified,CheckIncludedFilesArePresent) could not run locally: the local workload setup fails withNETSDK1147(missingwasm-tools) before the task runs. CI provides this coverage.