Skip to content

[Build.Tasks] Replace Dalvik collection with MSBuild items - #13387

Merged
simonrozsival merged 3 commits into
mainfrom
simonrozsival-replace-dalvik-collection-task
Nov 4, 2026
Merged

simonrozsival merged 3 commits into
mainfrom
simonrozsival-replace-dalvik-collection-task

Conversation

@simonrozsival

Copy link
Copy Markdown
Member

CollectDalvikFilesForArchive only constructs archive items from dex files. Replace its two packaging invocations with MSBuild item construction and remove the task implementation and registration, avoiding a custom task invocation for this transformation.

Preserve input paths, ordering and duplicates, nonblank ApkName overrides, whitespace fallback, and the case-insensitive AAB dex/ prefix. Update metadata on a temporary copy before appending with KeepMetadata="ArchivePath": computing metadata during Include groups non-adjacent duplicates through batching, while copying all input metadata could incorrectly send dex files down the archive writer's JavaArchiveEntry path. Clear the temporary items after use and reset the prefix for each collection.

The removed task type is no longer available to custom targets that invoke it directly. PackageFileListBuilder remains unchanged. Existing tests and documentation are unchanged; no new tests are added.

Validation:

  • make prepare — passed.
  • make all — solution build completed, but local workload configuration failed with MSB4018 because extra API-level 37.1 reference assemblies were not built by this target.
  • make leeroy — passed, including extra API levels and local workload configuration.
  • ./dotnet-local.sh build src/Xamarin.Android.Build.Tasks/Tests/Xamarin.Android.Build.Tests/Xamarin.Android.Build.Tests.csproj --no-restore -v:quiet — passed.
  • ./dotnet-local.sh test bin/TestDebug/net10.0/Xamarin.Android.Build.Tests.dll --filter 'Name~CheckClassesDexIsIncluded' --logger 'console;verbosity=normal' — passed, 2 tests (CoreCLR and NativeAOT).
  • git diff --check — passed.

simonrozsival and others added 3 commits November 3, 2026 16:12
Preserve source paths, archive naming, metadata isolation, duplicate ordering, and APK/AAB behavior in both packaging targets. Add target-level regression coverage and expand dex packaging checks to incremental APK/AAB builds.

Co-authored-by: Copilot App <[email protected]>
Remove the new target fixture and packaging test expansion as requested. Existing packaging tests do not reference the removed task and need no migration.

Co-authored-by: Copilot App <[email protected]>
Keep the general MSBuild guide unchanged; the target comment explains the relevant batching constraint.

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

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 existing test only checks that classes.dex exists, leaving duplicate ordering, ApkName overrides, whitespace fallback, and metadata stripping without targeted regression coverage across packaging branches and APK/AAB prefixes.

1 open issue
What changed in this PR

Replaces the Dalvik archive-item collection task with MSBuild item construction in the .NET for Android packaging pipeline, removing two custom task invocations.

Changes:

  • Constructs archive items in both packaging paths, preserving ordering, duplicates, ApkName overrides, and APK/AAB naming behavior.
  • Copies only ArchivePath metadata and clears temporary items after use.
  • Removes the task implementation and registration; custom targets invoking it directly must migrate.
File Description
src/​Xamarin.Android.Build.Tasks/​Xamarin.Android.Common.targets Replaces both collection calls with item construction and removes task registration.
src/​Xamarin.Android.Build.Tasks/​Tasks/​CollectDalvikFilesForArchive.cs Deletes the superseded collection task.

Review effort: Balanced

Comment on lines +2049 to +2053
<_AndroidDalvikFiles>
<ArchivePath>$(_AndroidDalvikArchivePrefix)$([System.IO.Path]::GetFileName(`%(_AndroidDalvikFiles.Identity)`))</ArchivePath>
<ArchivePath Condition=" !$([System.String]::IsNullOrWhiteSpace(`%(_AndroidDalvikFiles.ApkName)`)) ">$(_AndroidDalvikArchivePrefix)%(_AndroidDalvikFiles.ApkName)</ArchivePath>
</_AndroidDalvikFiles>
<FilesToAddToArchive Include="@(_AndroidDalvikFiles)" KeepMetadata="ArchivePath" />
@simonrozsival
simonrozsival enabled auto-merge (squash) November 4, 2026 09:18
@simonrozsival
simonrozsival merged commit 9535641 into main Nov 4, 2026
42 checks passed
@simonrozsival
simonrozsival deleted the simonrozsival-replace-dalvik-collection-task branch November 4, 2026 09:53
@jonathanpeppers

Copy link
Copy Markdown
Member

/backport to release/11.0.1xx

@github-actions

Copy link
Copy Markdown
Contributor

Started backporting to release/11.0.1xx (link to workflow run)

@github-actions

Copy link
Copy Markdown
Contributor

@jonathanpeppers backporting to release/11.0.1xx failed, the patch most likely resulted in conflicts. Please backport manually!

git am output
$ git cherry-pick 9535641694aacb72fd8bb48fb241150af9e3416a

Auto-merging src/Xamarin.Android.Build.Tasks/Xamarin.Android.Common.targets
CONFLICT (content): Merge conflict in src/Xamarin.Android.Build.Tasks/Xamarin.Android.Common.targets
error: could not apply 953564169... [Build.Tasks] Replace Dalvik collection with MSBuild items (#13387)
hint: After resolving the conflicts, mark them with
hint: "git add/rm <pathspec>", then run
hint: "git cherry-pick --continue".
hint: You can instead skip this commit with "git cherry-pick --skip".
hint: To abort and get back to the state before "git cherry-pick",
hint: run "git cherry-pick --abort".
hint: Disable this message with "git config set advice.mergeConflict false"


$ git am --3way --empty=keep --ignore-whitespace --keep-non-patch changes.patch

Applying: [build] Replace Dalvik archive collection task with item construction
Using index info to reconstruct a base tree...
M	Documentation/guides/MSBuildBestPractices.md
M	src/Xamarin.Android.Build.Tasks/Tests/Xamarin.Android.Build.Tests/PackagingTest.cs
M	src/Xamarin.Android.Build.Tasks/Xamarin.Android.Common.targets
Falling back to patching base and 3-way merge...
Auto-merging Documentation/guides/MSBuildBestPractices.md
CONFLICT (content): Merge conflict in Documentation/guides/MSBuildBestPractices.md
Auto-merging src/Xamarin.Android.Build.Tasks/Tests/Xamarin.Android.Build.Tests/PackagingTest.cs
Auto-merging src/Xamarin.Android.Build.Tasks/Xamarin.Android.Common.targets
CONFLICT (content): Merge conflict in src/Xamarin.Android.Build.Tasks/Xamarin.Android.Common.targets
error: Failed to merge in the changes.
hint: Use 'git am --show-current-patch=diff' to see the failed patch
hint: When you have resolved this problem, run "git am --continue".
hint: If you prefer to skip this patch, run "git am --skip" instead.
hint: To restore the original branch and stop patching, run "git am --abort".
hint: Disable this message with "git config set advice.mergeConflict false"
Patch failed at 0001 [build] Replace Dalvik archive collection task with item construction
Error: The process '/usr/bin/git' failed with exit code 128

Link to workflow output

jonathanpeppers added a commit that referenced this pull request Nov 20, 2026
…) (#13690)

Backport of #13387.

Replace the two Dalvik collection task calls with MSBuild items and remove the unused task. This avoids a custom task call for a simple item transformation. Preserve file order, duplicate inputs, `ApkName` overrides, whitespace fallback, and the case-insensitive AAB `dex/` prefix.

The conflict was in the `<UsingTask>` registrations. Keep the release branch's `Xamarin.Android.Tasks.CollectAssemblyFilesToCompress` registration and remove only `CollectDalvikFilesForArchive`. All release-only packaging content stays unchanged. The release `BuildArchive` consumer reads `ArchivePath` and `JavaArchiveEntry` in the same way as main; `KeepMetadata="ArchivePath"` prevents unrelated metadata from reaching it. No multithreaded task infrastructure is included.

(cherry picked from commit 9535641)

Co-authored-by: Šimon Rozsíval <[email protected]>
Co-authored-by: Copilot App <[email protected]>
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