Skip to content

[Xamarin.Android.Build.Tasks] Keep AAR libraries on deploy - #13833

Merged
jonathanpeppers merged 1 commit into
mainfrom
jonathanpeppers-test-androidlibrary-dotnet-run
Dec 1, 2026
Merged

jonathanpeppers merged 1 commit into
mainfrom
jonathanpeppers-test-androidlibrary-dotnet-run

Conversation

@jonathanpeppers

Copy link
Copy Markdown
Member

Agent assessment

Self-reported assessment, not an independent review.

Assessed revision: 5c9398beec89c8d91a77adbb412fa533620452c1

Dimension Assessment Rationale
Change confidence 8/10 ↑ Test assembly build passed.
↑ Device regression test passed before final device-selection cleanup.
↓ Device test not rerun after cleanup.
Diagnosis confidence 9/10 ↑ Reproduced the missing library after dotnet run --no-build and traced it to skipped categorization during deploy.
Evidence fit 9/10 ↑ The issue and device reproduction show the same AAR native library missing after deployment.

Fixes: #13821

dotnet run can remove native libraries from app-owned @(AndroidLibrary) AARs during deploy after a referenced project rebuild. The deploy build reruns _ResolveLibraryProjectImports without first categorizing those items.

Add _CategorizeAndroidLibraries to $(CoreResolveReferencesDependsOn) before _ResolveAars. The regression test checks that dotnet run --no-build keeps the AAR's native library in the APK.

Validation: dotnet-local.cmd build tests\MSBuildDeviceIntegration\MSBuildDeviceIntegration.csproj -c Debug --no-restore -p:EnableSourceLink=false -p:EnableSourceControlManagerQueries=false -v minimal passed with 0 warnings and 0 errors; git diff --check passed. The focused device test passed before the final device-selection cleanup. It was not rerun afterward because four devices are attached and the test now uses normal dotnet run device selection.

During dotnet run, DeployToDevice may rerun _ResolveLibraryProjectImports after a project reference builds.  It skips _CategorizeAndroidLibraries, so app-owned @(AndroidLibrary) AARs are absent and native libraries can be removed from the APK.

Run _CategorizeAndroidLibraries in CoreResolveReferencesDependsOn before _ResolveAars.  Add a device test for dotnet run --no-build.

Fixes: #13821

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Copilot AI balanced review requested due to automatic review settings November 30, 2026 18:36

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 test does not pass the harness-selected device to dotnet.Run(), so multiple attached devices can trigger interactive selection or failure before AAR retention is checked.

1 open issue
What changed in this PR

Addresses #13821 by preserving native libraries from app-owned AARs when .NET for Android reruns library import resolution during deployment.

Changes:

  • Runs _CategorizeAndroidLibraries before _ResolveAars during reference resolution.
  • Adds a device regression test that forces import resolution to rerun and checks that dotnet run --no-build preserves the native library in the APK.
File Description
tests/​MSBuildDeviceIntegration/​Tests/​InstallAndRunTests.cs Adds the AAR native-library retention regression test.
src/​Xamarin.Android.Build.Tasks/​Microsoft.Android.Sdk/​targets/​Microsoft.Android.Sdk.BuildOrder.targets Adds library categorization to the reference-resolution dependency chain.

Review effort: Balanced

@jonathanpeppers

Copy link
Copy Markdown
Member Author

/azp run Xamarin.Android-PR

@azure-pipelines

Copy link
Copy Markdown
No pipelines are associated with this pull request.

@jonathanpeppers

Copy link
Copy Markdown
Member Author

Internal Xamarin.Android-PR build 16171123 failed. I reviewed the failures, and none of them appear to be caused by this PR. They can be ignored:

Failure Why it can be ignored
Task: PoliCheck English / Run PoliCheck Post Analysis Fails on every main build. #13838 fixes it.
Task: Windows > Build & Smoke Test / Ensure no modified/untracked files Untracked .sarif file left by the Guardian tools. Fails on every main build.
Test: NuGetPackageVersionFinderTests.ShortTaskNameResolvesWithNuGetMetadataInFullMSBuild Fails on every main build.

The public CI (dnceng-public) is offline, so this internal build is the only CI result.

@jonathanpeppers jonathanpeppers added the ready-to-review This PR is ready to review/merge, I think any CI failures are just flaky (ignorable). label Dec 1, 2026
@jonathanpeppers

Copy link
Copy Markdown
Member Author

@dalexsoto review

@dalexsoto dalexsoto left a comment

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.

Reviewed the AAR categorization ordering and its build, deploy, design-time, and per-RID consumers, plus the new native-library deployment test and embedded fixture. The change preserves the AAR native-library imports for DeployToDevice and dotnet run --no-build. No blocking issues found.

Static source review only; no builds or tests executed.

@jonathanpeppers
jonathanpeppers merged commit 2381cca into main Dec 1, 2026
2 of 3 checks passed
@jonathanpeppers
jonathanpeppers deleted the jonathanpeppers-test-androidlibrary-dotnet-run branch December 1, 2026 20:08
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

ready-to-review This PR is ready to review/merge, I think any CI failures are just flaky (ignorable).

Projects

None yet

Development

Successfully merging this pull request may close these issues.

dotnet run: DeployToDevice skips _CategorizeAndroidLibraries, so app AndroidLibrary .aar native libs (e.g. onnxruntime) are removed from the APK

3 participants