Skip to content

[tests] Replace GradleFBProj with a local Gradle library test - #13703

Merged
jonathanpeppers merged 8 commits into
mainfrom
simonrozsival-fix-flaky-gradlefbproj-test
Nov 23, 2026
Merged

jonathanpeppers merged 8 commits into
mainfrom
simonrozsival-fix-flaky-gradlefbproj-test

Conversation

@simonrozsival

@simonrozsival simonrozsival commented Nov 21, 2026 •

Copy link
Copy Markdown
Member

Context: #13640
Context: #9270
Context: #9429

@(AndroidGradleProject) was introduced for slim bindings: build a small Java wrapper around a dependency and bind the resulting AAR. GradleFBProj was added to exercise installation and execution of that workflow. Its Facebook SDK, AndroidX, Kotlin, Maven, and NuGet dependency graph has made it vulnerable to feed errors and corrupt downloads, including NU1301 and XA1004 failures.

Drop the Facebook-specific device scenario rather than continue stabilizing its large external dependency graph, and replace it with GradleLibrary. Build a single Android Gradle wrapper against the Gson JAR already embedded in Xamarin.ProjectTools, and supply that unbound Java dependency separately to the application. The wrapper reads an Android resource and calls Gson; the application calls its generated C# binding. Monitor logcat before launch and require a unique per-run result, so a successful Run target alone is no longer treated as proof that the binding executed.

Coverage and limitations

This retains the original slim-binding, build, install, and on-device execution purpose, including a separately packaged Java dependency. It no longer exercises Facebook/AppEvents on-device, @(AndroidMavenLibrary) downloads, or Facebook's NuGet/AndroidX/Kotlin dependency graph. The existing host-side AndroidGradleProjectTests.BindFacebook still builds and binds Facebook, but does not deploy or run it.

Gradle, the Android Gradle Plugin, and aapt2 still need a populated cache or working feeds. CI retries discard the first attempt's build.log, so the device test now includes Gradle and MSBuild error lines in its failure message. The precise error from build 1693177 was lost when its retry passed; a cold Gradle download failure is possible but unproven.

Some failures also reported a missing platforms;android-37.0; this does not change SDK provisioning or conceal product/emulator failures. During development, a two-Android-module fixture exposed shared Gradle output-directory collisions, and a separate @(AndroidLibrary) without Visible triggered MSB4096 in the Gradle target. Those independent SDK defects are not fixed here; the fixture uses one Android module and @(AndroidJavaLibrary) for the unbound JAR.

Validation

  • make prepare CONFIGURATION=Release && make leeroy CONFIGURATION=Release — passed.
  • ./dotnet-local.sh build tests/MSBuildDeviceIntegration/MSBuildDeviceIntegration.csproj -c Release --no-restore -v:minimal — passed.
  • ADB_TARGET='-s emulator-5558' RUNNINGONCI=true ./dotnet-local.sh test bin/TestRelease/MSBuildDeviceIntegration/net11.0/MSBuildDeviceIntegration.dll --filter 'FullyQualifiedName~InstallAndRunTests.GradleFBProj' (before the rename) --logger 'console;verbosity=normal' — passed 3/3 in three consecutive runs (Debug CoreCLR, Release CoreCLR, Release NativeAOT; 9/9 total) on a dedicated arm64 emulator.
  • project="$PWD/bin/TestRelease/temp/gradle/GradleFBProjFalse CoreCLR"; ANDROID_HOME="$HOME/Library/Android/sdk" RUNNINGONCI=true "$project/gradlew" --offline --no-daemon --console=plain -p "$project" :Library:assembleRelease — passed with a warm tooling cache. The AAR contains the wrapper but not Gson; the installed APK contains Gson and emitted the expected result.
  • Cold GRADLE_USER_HOME build of GradleFBProj(False, CoreCLR) (temporary local device-check bypass, reverted) — Gradle and app build passed in 13m42s; it could not reproduce the CI failure.
  • Rebuilt the test assembly after the diagnostics change — passed.
  • git diff --check — passed.
  • Stress run after the rename (f0bbb1ef): repeated ./dotnet-local.sh test bin/TestRelease/MSBuildDeviceIntegration/net11.0/MSBuildDeviceIntegration.dll --filter 'FullyQualifiedName~InstallAndRunTests.GlobalLayoutEvent_ShouldRegisterAndFire_OnActivityLaunch|FullyQualifiedName~InstallAndRunTests.GradleLibrary' for 990s on a dedicated API 35 arm64 emulator, with AdbTarget/ADB_TARGET set to that device, randomized test order, and an isolated GRADLE_USER_HOME seeded once and then run offline — 9 rounds, 54/54 first attempts passed (each of the 3 variants of both tests 9/9), no dependency downloads. Install/run logs confirmed every round targeted only that emulator. Warm/offline runs cannot rule out cold-cache download failures.

simonrozsival and others added 2 commits November 21, 2026 00:37
Fixes: #13640

`InstallAndRunTests.GradleFBProj` failed intermittently on CI because it
pulled the Facebook SDK's Maven dependency graph, two
`@(AndroidMavenLibrary)` artifacts and six NuGet packages from remote
feeds. Most failures were feed timeouts, HTTP errors or corrupted
downloads in the shared caches.

Replace the Facebook SDK with two self-contained Gradle modules:

  * `Library`, a bound `@(AndroidGradleProject)` renamed through a
    Metadata transform, which calls into
  * `Dependency`, supplied by a second `@(AndroidGradleProject)` with
    `Bind=false`, which reads an Android string resource.

The app calls the binding at startup, and the test now asserts that the
expected logcat message appears, rather than only checking that the
`Run` target succeeded.

AGP and aapt2 still come from the configured Maven feed. Host-side
`AndroidGradleProjectTests.BindFacebook` still covers building and
binding the Facebook SDK.

Co-authored-by: Copilot App <[email protected]>
Two Android Gradle modules share the SDK output directory, so their tasks collide. Use the Gson JAR already embedded in Xamarin.ProjectTools as the wrapper library’s separately packaged, unbound Java dependency instead. Keep a single Android module, target the selected device, and start logcat monitoring before launching the app with a unique success marker.

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

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.

🔵 Needs a closer look

Reported arm64 and warm-cache runs do not establish flake stabilization across public macOS pipelines, and the intentional deployment-coverage reduction still needs maintainer acceptance.

No open issues 🎉

What changed in this PR

Stabilizes the Gradle slim-binding deployment test by replacing Facebook’s remote dependency graph with an embedded Gson JAR, while preserving coverage of binding generation, installation, and on-device execution.

Changes:

  • Builds a single Gradle wrapper that reads an Android resource and calls Gson, with the unbound JAR packaged separately by the application.
  • Starts logcat monitoring before launch and requires a unique per-run result to confirm the generated binding executed.
  • Removes Facebook-specific dependencies and manifest configuration; host-side Facebook binding coverage remains unchanged.
File Description
tests/​MSBuildDeviceIntegration/​Tests/​InstallAndRunTests.cs Replaces the Facebook fixture with a local Gson-backed wrapper and verifies execution through a unique logcat marker.

Review effort: Balanced

simonrozsival and others added 5 commits November 21, 2026 16:32
AzDO build 1693177 failed GradleFBProj((False, CoreCLR)) on its first
attempt with only a generic FailedBuildException; the automatic retry
passed. RunSlicedTests drops the failed attempt's TRX entry (and its
build.log attachment) and the job uploads no results on success, so the
underlying error was lost.

The MSBuild+Emulator stage, unlike the build and Build.Tests jobs, never
used cache-gradle.yaml, so every device agent downloaded the Gradle
distribution and Android Gradle Plugin cold for the first Gradle test.
Add the cache, and report Gradle/MSBuild error lines in the GradleFBProj
failure message so future failures are attributable.

Co-authored-by: Copilot App <[email protected]>
The macOS build job saves `caches/modules-2` under the shared key first,
so the emulator job always got an exact hit and Cache@2 never saved the
AGP and aapt2 artifacts that its Gradle tests download. Key the emulator
job's dependency cache on the file pinning the test AGP version; it still
restores the build job's cache via `restoreKeys` and then saves its own.

Co-authored-by: Copilot App <[email protected]>
The emulator job runs parallel slices, and slices without Gradle tests can
save the shared cache before those that download AGP. Include the slice and
test sources in the dependency key so each slice can save its own inputs and
test changes invalidate stale slice assignments.

Co-authored-by: Copilot App <[email protected]>
The public and internal pipelines define msbuilddevice_tests inline, so
the cache step added to stage-msbuild-emulator-tests.yaml never ran in
PR builds.

Co-authored-by: Copilot App <[email protected]>
@simonrozsival simonrozsival changed the title [tests] Stabilize Gradle slim binding deployment coverage [tests] Replace GradleFBProj with a local Gradle library test Nov 22, 2026
@simonrozsival

Copy link
Copy Markdown
Member Author

/review

@github-actions

github-actions Bot commented Nov 23, 2026 •

Copy link
Copy Markdown
Contributor

✅ Android PR Reviewer completed successfully!

Generated by Android PR Reviewer for #13703

@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 merge-blocking findings. Reviewed all five changed files in full at f0bbb1ef, the generated Gradle project/module helpers, project-file persistence, Gradle targets, logcat monitoring, and sliced-test/cache integration. Findings: 0 ❌ errors, 0 ⚠️ warnings, 1 💡 suggestion posted inline about retaining diagnostics for failures without Gradle/MSBuild error markers.

The local Gson fixture keeps the slim-binding workflow meaningful: the generated binding calls Java that reads an AAR resource and uses a separately supplied, unbound JAR. The unique per-run logcat result is a substantial improvement over asserting only that the Run target succeeded. Cache integration covers both inline public/internal emulator stages and the shared stage template. The reduced Facebook/Maven/NuGet coverage is explicitly documented; this does not establish that cold-cache tooling failures are eliminated.

CI evidence: all 38/38 GitHub checks report success for this head, including the overall dotnet-android check and all 11 emulator slices, linked to Azure build 1693908. Independent Azure build/timeline verification remains incomplete: the standalone CLI requests failed during initialization/authentication. Consequently, this review does not independently confirm Azure retry history or cache restore/save behavior. No local build or device tests were run during this read-only review.

Generated by Android PR Reviewer for #13703 · copilot · gpt61 · 52.5 AIC · ⌖ 8.08 AIC · ⊞ 20.3K
Comment /review to run again

summary.Add (line);
}
}
return string.Join (Environment.NewLine, summary.Distinct ().Take (50));

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.

🤖 💡 Error handling — Consider preserving a bounded tail of the build output when no lines match these filters. Builder.BuildInternal can return false after a process timeout and appends Build Timed Out! to the log; that line matches neither FAILURE: nor : error . A wrapper/JVM failure before Gradle initializes can also lack both markers. In those cases this helper returns an empty string, leaving only “Build should have succeeded:” in the retry-preserved failure message. Including the timeout/exit-status lines, or the last few lines when the filtered summary is empty, would retain useful evidence without attaching an enormous log.

{Rule: Actionable failure diagnostics}

@simonrozsival simonrozsival added the ready-to-review This PR is ready to review/merge, I think any CI failures are just flaky (ignorable). label Nov 23, 2026
Keep the device test change separate from pipeline caching.

Co-authored-by: Copilot App <[email protected]>
@jonathanpeppers
jonathanpeppers merged commit 136d291 into main Nov 23, 2026
38 checks passed
@jonathanpeppers
jonathanpeppers deleted the simonrozsival-fix-flaky-gradlefbproj-test branch November 23, 2026 21:39
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

flaky-tests 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.

3 participants