Repository navigation
[Xamarin.Android.Build.Tasks] Skip unchanged AAB installs - #13446
Conversation
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
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
There was a problem hiding this comment.
🟡 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
|
/review |
|
✅ Android PR Reviewer completed successfully!
|
There was a problem hiding this comment.
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.
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]>
|
@dalexsoto review |
dalexsoto
left a comment
There was a problem hiding this comment.
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.
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]>
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.

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
_DeployAppBundletarget ran<InstallApkSet/>on everyInstall, before_Uploadcould decide whether anything changed.@(_UploadInputs)also included$(ApkFileSigned), which AAB builds never produce, so_Uploadran every time too._DeployAppBundlenow hasInputs="$(_ApkSetIntermediate)"andOutputs="$(_AndroidAppBundleInstallFlag)".upload.flagis missing: the app was uninstalled, or the deployment configuration changed.@(_UploadInputs)uses the.apksfile and the install flag instead of$(ApkFileSigned).$(AndroidPackageFormat),$(AndroidDeviceUserId)and@(AndroidInstallModules)._BuildApkSetalso depends onappbundle-device.cache, which stores$(AdbTarget)after device detection (-s <serial>). The APK set is device-specific, andadb.propsis 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
.apksfile 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 packagesquery fails, the next unchangedInstallis skipped.Trimmable typemap
_GenerateTrimmableTypeMapranAfterTargets="CoreCompile", before XamlC rewrote the intermediate assembly. Every no-op build then logged:It now runs
AfterTargets="Compile", so it sees the final assembly.Tests
IncrementalFastDeploymentcompared 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 newInstallApkSetCommandcases.Validation
macOS arm64, Release SDK, API 29 arm64-v8a emulator:
Negative checks: with
AfterTargets="CoreCompile"restored, the post-compile rewrite test fails. WithInputs/Outputsremoved from_DeployAppBundle,IncrementalFastDeployment("aab")fails.Windows, Debug SDK, after the
$(AdbTarget)cleanup:Not tested locally: two devices, a secondary Android user, and NativeAOT deployment.