Skip to content

[Xamarin.Android.Build.Tasks] Skip unchanged AAB installs - #13446

Merged
jonathanpeppers merged 6 commits into
mainfrom
simonrozsival-ci-incremental-install-timing
Nov 17, 2026
Merged

jonathanpeppers merged 6 commits into
mainfrom
simonrozsival-ci-incremental-install-timing

Conversation

@simonrozsival

@simonrozsival simonrozsival commented Nov 10, 2026 •

Copy link
Copy Markdown
Member

Context: #13429
Context: https://dev.azure.com/dnceng-public/public/_build/results?buildId=1677859

IncrementalFastDeployment("aab") kept failing because an unchanged install was slower than an incremental install. The cause was real work on every install, not timing noise.

AAB deployment

The _DeployAppBundle target ran <InstallApkSet/> on every Install, before _Upload could decide whether anything changed. @(_UploadInputs) also included $(ApkFileSigned), which AAB builds never produce, so _Upload ran every time too.

  • _DeployAppBundle now has Inputs="$(_ApkSetIntermediate)" and Outputs="$(_AndroidAppBundleInstallFlag)".
  • The install flag is deleted whenever upload.flag is missing: the app was uninstalled, or the deployment configuration changed.
  • For AAB, @(_UploadInputs) uses the .apks file and the install flag instead of $(ApkFileSigned).
  • The deployment configuration key now includes $(AndroidPackageFormat), $(AndroidDeviceUserId) and @(AndroidInstallModules).
  • _BuildApkSet also depends on appbundle-device.cache, which stores $(AdbTarget) after device detection (-s <serial>). The APK set is device-specific, and adb.props is written before detection, so it does not record the real device when $(AdbTarget) is empty or -e/-d.

Managed-only changes still use Fast Deployment without reinstalling the APK set. Changes to resources or native libraries change the .apks file and reinstall it.

<InstallApkSet/> passed --modules "base","feature" with the quotes inside the value. It now passes a plain comma-separated list.

Known limitations, the same as for APK deployment today: if another build replaces the app with the same package name, or if the pm list packages query fails, the next unchanged Install is skipped.

Trimmable typemap

_GenerateTrimmableTypeMap ran AfterTargets="CoreCompile", before XamlC rewrote the intermediate assembly. Every no-op build then logged:

Input file "obj/Debug/UnnamedProject.dll" is newer than output file "obj/Debug/typemap/_GenerateTrimmableTypeMap.stamp".

It now runs AfterTargets="Compile", so it sees the final assembly.

Tests

IncrementalFastDeployment compared elapsed times, which include restore, evaluation and project-reference builds. It now checks that an unchanged install skips compile, XamlC, typemap, dex, packaging, APK-set and upload targets, and reads the binlog to confirm those tasks did not run in any project. Elapsed times are still printed.

New tests: AppBundleDeploymentInvalidation (device), PackageUploadInputs, DeploymentConfigurationInvalidation, Build_WithTrimmableTypeMap_PostCompileRewriteKeepsNoOpBuildIncremental, and new InstallApkSetCommand cases.

Validation

macOS arm64, Release SDK, API 29 arm64-v8a emulator:

./dotnet-local.sh test bin/TestRelease/net11.0/Xamarin.Android.Build.Tests.dll \
  --filter 'FullyQualifiedName~DebuggingTasksTests|Name~Build_WithTrimmableTypeMap_PostCompileRewriteKeepsNoOpBuildIncremental|Name~Build_WithTrimmableTypeMap_IncrementalBuild|Name~Build_WithTrimmableTypeMap_MissingJavaListPreservesGeneratedJava|Name~InstallApkSetCommand'
# 52 passed, 1 Windows-only skip

./dotnet-local.sh test bin/TestRelease/net11.0/Xamarin.Android.Build.Tests.dll \
  --filter 'Name~DesignTimeBuildSignAndroidPackage|Name~Build_TrimmableTypeMap_UsesMonoAndroidImplementationMetadata|Name~Build_WithTrimmableTypeMap_IncrementalBuild|Name~Build_WithTrimmableTypeMap_PublishTrimmed_|Name~RetainedTypeMapRulesDriveR8|Name~BuildOutsideVisualStudio|Name~ReleaseProjectReferenceDoesNotRebuildWithoutChanges'
# 17 passed

./dotnet-local.sh test bin/TestRelease/MSBuildDeviceIntegration/net11.0/MSBuildDeviceIntegration.dll \
  --filter 'Name~IncrementalFastDeployment|Name~ReInstallIfUserUninstalled|Name~SwitchConfigurationsShouldRedeploy|Name~AppBundleDeploymentInvalidation|Name~AdbTargetChangesAppBundle|Name~InstallAppBundleWithoutWarnings'
# 11 passed

Negative checks: with AfterTargets="CoreCompile" restored, the post-compile rewrite test fails. With Inputs/Outputs removed from _DeployAppBundle, IncrementalFastDeployment("aab") fails.

Windows, Debug SDK, after the $(AdbTarget) cleanup:

dotnet-local.cmd test bin\TestDebug\net11.0\Xamarin.Android.Build.Tests.dll --filter "Name~PackageUploadInputs|Name~DeploymentConfigurationInvalidation|Name~InstallApkSetCommand"
# 11 passed

Not tested locally: two devices, a secondary Android user, and NativeAOT deployment.

simonrozsival and others added 4 commits November 10, 2026 03:17
Unchanged AAB installs invoked bundletool before _Upload could check
whether deployment was needed.  The upload inputs also named a signed
APK that AAB builds never produce, invalidating every warm upload.

Track successful APK-set installation separately from managed uploads.
Use real package inputs and wait for app detection before reusing install
state.  Preserve external uninstall recovery and invalidate deployment
for package, module, device, user, and configuration changes.  Track the
resolved device so connected-device APK sets cannot survive a device
switch hidden by an unchanged ADB selector.

Add host and device regressions for skipped and changed deployment work.
Correct module argument quoting exposed by the module-selection case.
Keep the existing elapsed-time assertions: local validation still shows
an independent whole-build ordering failure dominated by type-map task
time, even though unchanged deployment work is correctly skipped.

Related to #13429.

Co-authored-by: Copilot App <[email protected]>
Copilot-Session: eafcdf7f-9105-497f-abe5-d186da0dd560
…emental-install-timing

Resolve conflicts with main's adb runner/Exec changes in
DetectIfAppWasUninstalled and _DeployAppBundle, and move the
parameterized InstallApkSetCommand cases to BundleToolTaskTests.

Co-authored-by: Copilot App <[email protected]>
_GenerateTrimmableTypeMap ran AfterTargets="CoreCompile", before
post-compile steps in $(CompileDependsOn) such as XamlC rewrite the
intermediate assembly.  The rewritten assembly was then newer than the
typemap stamp, so the next unchanged build regenerated the typemap.

In CI, this made unchanged IncrementalFastDeployment("aab") builds
regenerate the typemap after both the initial and incremental installs.
Combined with the redundant APK-set installation, unchanged builds were
no faster than incremental ones.

Run the target after Compile so it observes the final assembly and
remains up to date.  Add a host regression with a synthetic
post-compile rewriter and assert on device that unchanged installs skip
typemap generation.

Related to #13429.

Co-authored-by: Copilot App <[email protected]>
Copilot-Session: eafcdf7f-9105-497f-abe5-d186da0dd560
Merging main changed the second install to `-s {serial}`, while the
unchanged third install still used `-e {serial}`.  Changing $(AdbTarget)
rewrites adb.props, so rebuilding and reinstalling the APK set was the
correct behavior.  Reuse the second install's selector so the test
checks an unchanged deployment.

Co-authored-by: Copilot App <[email protected]>
Copilot-Session: eafcdf7f-9105-497f-abe5-d186da0dd560
@simonrozsival simonrozsival changed the title [Xamarin.Android.Build.Tasks] Skip unchanged AAB installs [Xamarin.Android.Build.Tasks] Avoid redundant work in unchanged AAB installs Nov 13, 2026
IncrementalFastDeployment measures Build,Install, including restore,
evaluation, and project-reference builds. Even with package installation
and type-map generation correctly skipped, those unrelated phases can
make an unchanged or changed operation slower than the initial one.
Local repetitions reproduced both APK and AAB elapsed-order failures
while all deployment checks passed.

Replace that timing proxy with explicit zero-work budgets. Unchanged
installs must skip compilation, XamlC, dexing, packaging, APK-set
installation, and managed upload. Inspect executed tasks in the binlog
as well so a skip in one referenced project cannot hide execution in
another. Managed-only changes must not dex, repackage, or reinstall;
the changed-versus-unchanged assembly copy checks remain in place.

Keep elapsed times in test output as diagnostics. Reintroducing
unconditional APK-set installation in the local SDK makes the AAB case
fail; restoring the fix passes both formats and the device-target test.
No test is disabled and no elapsed threshold is increased.

Related to #13429.

Co-authored-by: Copilot App <[email protected]>
Copilot-Session: eafcdf7f-9105-497f-abe5-d186da0dd560
@simonrozsival
simonrozsival marked this pull request as ready for review November 13, 2026 09:50
Copilot AI balanced review requested due to automatic review settings November 13, 2026 09:50

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

A critical deployment flaw can preserve stale installation flags after an external uninstall and failed package query, causing Install to report success without restoring the app.

1 open issue
What changed in this PR

Improves incremental AAB deployment in .NET for Android, addressing redundant work behind the unchanged-install failures tracked in #13429.

Changes:

  • Tracks APK-set installation separately from managed uploads, with device and deployment-configuration invalidation.
  • Moves type-map generation after post-compile assembly rewriting.
  • Replaces elapsed-time assertions with explicit no-work checks and expands deployment regression coverage.
File Description
tests/​MSBuildDeviceIntegration/​Tests/​InstallTests.cs Adds no-work and AAB invalidation checks; fixes selector reuse.
src/​Xamarin.Android.Build.Tasks/​Xamarin.Android.Common.targets Makes APK-set generation device-aware and installation incremental.
src/​Xamarin.Android.Build.Tasks/​Tests/​Xamarin.Android.Build.Tests/​TrimmableTypeMapBuildTests.cs Tests unchanged builds after post-compile assembly rewriting.
src/​Xamarin.Android.Build.Tasks/​Tests/​Xamarin.Android.Build.Tests/​Tasks/​BundleToolTaskTests.cs Covers default, single, and multiple module arguments.
src/​Xamarin.Android.Build.Tasks/​Tests/​Xamarin.Android.Build.Tests/​DebuggingTasksTests.cs Tests upload inputs and deployment-configuration invalidation.
src/​Xamarin.Android.Build.Tasks/​Tasks/​InstallApkSet.cs Corrects module-list argument quoting.
src/​Xamarin.Android.Build.Tasks/​Microsoft.Android.Sdk/​targets/​Microsoft.Android.Sdk.TypeMap.Trimmable.targets Runs type-map generation after Compile.
src/​Xamarin.Android.Build.Tasks/​Microsoft.Android.Sdk/​targets/​Microsoft.Android.Sdk.TypeMap.Trimmable.NativeAOT.targets Updates comments explaining type-map generation ordering.
src/​Xamarin.Android.Build.Debugging.Tasks/​Xamarin.Android.Common.Debugging.targets Coordinates detection, installation flags, upload inputs, and cache cleanup.
src/​Xamarin.Android.Build.Debugging.Tasks/​Tasks/​DetectIfAppWasUninstalled.cs Exposes the resolved device serial for cache invalidation.
Documentation/​guides/​app-bundles.md Documents incremental AAB deployment and invalidation behavior.

Review effort: Balanced

@simonrozsival

Copy link
Copy Markdown
Member Author

/review

@github-actions

github-actions Bot commented Nov 13, 2026 •

Copy link
Copy Markdown
Contributor

✅ Android PR Reviewer completed successfully!

Generated by Android PR Reviewer for #13446

@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.

Code assessment: no blocking findings. Reviewed all 11 changed files in full and traced the deployment dependencies, app-detection waiter, configuration invalidation, and typemap consumers. 0 errors · 0 warnings · 1 optional suggestion, posted inline for resolved-device-switch coverage.

The separate installation sentinel and real AAB upload inputs address the redundant deployment paths without forcing package installation for managed-only updates. Moving typemap generation after Compile accounts for post-compile rewriters, and checking actual task executions across project instances is a stronger regression assertion than elapsed-time ordering.

⚠️ CI verification incomplete: all 41 head check runs report success, including the aggregate dotnet-android check for Azure build 1679343. The standalone Azure build query was blocked by the CLI's login requirement, so I could not independently confirm the Azure build result or inspect non-gating test outcomes; this is not an assertion that CI is failing. Assessment is based on source review and the available check results, not a local rerun.

Generated by Android PR Reviewer for #13446 · copilot · gpt61 · 73.3 AIC · ⌖ 4.64 AIC · ⊞ 20.2K
Comment /review to run again

…t device cache

`DetectIfAppWasUninstalled` already sets `$(AdbTarget)` to `-s <serial>`,
and `_CheckForConfigurationChange` already includes `$(AdbTarget)`. Remove
the duplicate `DeviceSerial` output and `$(_AndroidDeploymentDeviceSerial)`;
write `$(AdbTarget)` to `appbundle-device.cache` instead.

Define `$(_AndroidAppBundleInstallFlag)` and `$(_AndroidApkSetDeviceCache)`
next to `$(_UploadFlag)`, so `_CleanDebuggingCaches` and tests use the
properties instead of repeating the paths.

Co-authored-by: Copilot App <[email protected]>
@jonathanpeppers jonathanpeppers added the ready-to-review This PR is ready to review/merge, I think any CI failures are just flaky (ignorable). label Nov 17, 2026
@jonathanpeppers

Copy link
Copy Markdown
Member

@dalexsoto review

@jonathanpeppers jonathanpeppers changed the title [Xamarin.Android.Build.Tasks] Avoid redundant work in unchanged AAB installs [Xamarin.Android.Build.Tasks] Skip unchanged AAB installs Nov 17, 2026
@jonathanpeppers
jonathanpeppers enabled auto-merge (squash) November 17, 2026 14:58

@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 AAB install/upload-state invalidation, resolved-device/user/module handling and FastDeploy integration, typemap generation/consumer ordering, documentation, and changed tests. The documented external-replacement/package-query limitations remain accepted. The post-supplement final pass found no blocking issue.

@jonathanpeppers
jonathanpeppers merged commit 5f53a70 into main Nov 17, 2026
38 checks passed
@jonathanpeppers
jonathanpeppers deleted the simonrozsival-ci-incremental-install-timing branch November 17, 2026 16:02
simonrozsival added a commit that referenced this pull request Nov 21, 2026
Context: #13646, #13636, #13641, #13446

Remove Build_XAML_Change and IncrementalFastDeployment instead of disabling them. Build-performance measurement will be handled separately from the general integration suite. IncrementalFastDeployment already uses zero-work assertions rather than elapsed-time comparisons; its removal is intentional.

Remove the orphaned XAML timing budgets and structured-logger import. Preserve the remaining PerformanceTest fixture and separate functional deployment tests.

Validation: MSBuildDeviceIntegration compilation passed with no warnings or errors, test discovery passed with the removed cases absent, and git diff --check passed.

Co-authored-by: Copilot App <[email protected]>
simonrozsival added a commit that referenced this pull request Nov 23, 2026
Fixes: #13636
Fixes: #13641

Context: #13429
Context: #13646
Context: #13446

### Problem

`MSBuildDeviceIntegration` contained a timing-based performance fixture and a flaky incremental deployment test:

  * `PerformanceTest` compared wall-clock build, install, and design-time-build durations with hard-coded budgets in `tests/msbuild-times-reference/MSBuildDeviceIntegration.csv`.
  * `InstallTests.IncrementalFastDeployment` used a Xamarin.Forms XAML scenario and was flaky in CI (#13641). Its elapsed-time comparisons had already been replaced with no-work assertions in #13446.

Measuring performance inside functional test runs is unreliable. These tests run on shared CI agents and emulators where CPU contention, disk and emulator I/O, cold caches, and the previous test's state can change timings by more than the regressions they are meant to catch. Loose budgets can miss regressions, while tighter budgets cause flaky failures (for example `Build_XAML_Change`, #13636). The results are often ignored and cannot reliably surface performance regressions at the PR level. #13646 explored disabling the flaky cases; this change replaces that approach.

### Changes

**Remove the timing tests.** Delete the whole `PerformanceTest` fixture rather than marking cases `[Ignore]`:

  * `Build_No_Changes`, `Build_CSharp_Change`, `Build_AndroidResource_Change`, `Build_AndroidAsset_Change`, `Build_AndroidManifest_Change`, `Build_XAML_Change`
  * `Install_CSharp_Change`, `Install_CSharp_FromClean`
  * `DesignTimeBuild_CSharp_From_Clean`

Its budget file, `tests/msbuild-times-reference/MSBuildDeviceIntegration.csv`, is deleted too; nothing else reads it. Separate, more robust build-time and runtime benchmarks will replace this performance coverage as part of the .NET 12 work.

**Keep `IncrementalFastDeployment` functional and timing-independent.** The test is kept for APK and AAB packaging and verifies incremental fast deployment correctness and skipped work without build-speed assertions. #13446 had already removed its elapsed-time comparisons; this change also removes the Xamarin.Forms dependency and its XAML scenario. It uses a plain Android app that logs values from two project-reference libraries, `Library1` (an Android library) and `Library2` (`netstandard2.0`):

 1. Build and install the app, run it, and verify that logcat contains `INCREMENTAL_FAST_DEPLOY:500:40`.
 2. Install again with no changes. Verify selected build and deployment work is skipped:
    * Skipped targets: `CoreCompile`, `_CompileToDalvik`, `_BuildApkFastDev`, `_Upload` (AAB: `_BuildApkSet`, `_DeployAppBundle`). `_GenerateTrimmableTypeMap` may be skipped or absent.
    * The install binlog runs none of these tasks: `Csc`, `GenerateTrimmableTypeMap`, `D8`, `R8`, `BuildApk`, `BuildAppBundle`, `BuildApkSet`, `InstallApkSet`, `FastDeploy`.
 3. Change `Library1.Class1.GetValue ()` from `500` to `501`. The test verifies that the assembly contents change but its size does not. This guards against change detection based only on file size. Explicitly rebuild that library, because `Xamarin.ProjectTools` builds with `BuildingInsideVisualStudio=true`, which does not rebuild project references automatically; verify that `Csc` ran.
 4. Install the app again. Verify:
    * `FastDeploy` runs, but `_CompileToDalvik` and `_BuildApkFastDev` are skipped (AAB: `_BuildApkSet` and `_DeployAppBundle` are also skipped). The binlog runs none of `Csc`, `D8`, `R8`, `BuildApk`, `BuildAppBundle`, `BuildApkSet`, or `InstallApkSet`.
    * The unchanged `Library2.dll` is not uploaded again (`NotifySync SkipCopyFile`), and no redundant files are removed (`Remove redundant file`).
    * The running app logs `INCREMENTAL_FAST_DEPLOY:501:40`, proving the updated assembly was deployed and loaded.
 5. Repeat the no-change install checks from step 2, then uninstall the app.

No step asserts build or install duration. The only time limit is a timeout while waiting for the app's logcat output, so the test fails instead of hanging if the app never starts.

The other functional deployment tests (`AppBundleDeploymentInvalidation`, `AdbTargetChangesAppBundle`, `ReInstallIfUserUninstalled`) are unchanged. There are no product code changes.
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.

4 participants