Skip to content

fix: resolve baseline profile generation failures#2102

Open
vibhor-kulshrestha wants to merge 4 commits intoandroid:mainfrom
vibhor-kulshrestha:fix/baseline-profile-instrumentation-runner
Open

fix: resolve baseline profile generation failures#2102
vibhor-kulshrestha wants to merge 4 commits intoandroid:mainfrom
vibhor-kulshrestha:fix/baseline-profile-instrumentation-runner

Conversation

@vibhor-kulshrestha
Copy link
Copy Markdown

Fixes #1965

Problem

Two build errors occur when running generateProdReleaseBaselineProfile:

Error 1 — Instrumentation runner not found:
benchmarks/build.gradle.kts was missing testInstrumentationRunnerArguments with enabledRules=BaselineProfile. Without this, the managed device test runner executed macrobenchmarks alongside baseline profile generators, putting the app in an incorrect state and causing all profile generators to fail with NullPointerException and AssertionError.

Error 2 — Gradle 9 implicit task dependency:
Gradle 9 strict validation detected that :app:createProdNonMinifiedReleaseApkListingFileRedirect consumed output from :benchmarks:packageProdNonMinifiedRelease without declaring an explicit dependency, causing non-deterministic build failures.

Fix

  • Added testInstrumentationRunnerArguments["androidx.benchmark.enabledRules"] = "BaselineProfile" to benchmarks/build.gradle.kts
  • Added explicit dependsOn task ordering in app/build.gradle.kts to satisfy Gradle 9 strict validation

Testing

  • Reproduced both errors on unmodified repo
  • Verified task ordering via --dry-run
  • Verified merged manifest shows correct AndroidJUnitRunner with self-instrumenting targetPackage
  • Full bundleProdRelease succeeds with zero implicit dependency warnings
  • baseline.prof (10KB) and baseline.profm confirmed embedded in AAB
  • BookmarksBaselineProfile now passes (was failing before fix)
  • Debug build and testDemoDebug unaffected

Copy link
Copy Markdown

@gemini-code-assist gemini-code-assist Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request modifies the Gradle build configuration to establish a dependency between the app's APK listing task and the benchmark packaging tasks, while also setting the default benchmark rules to BaselineProfile. The review identifies an inefficiency in the task configuration logic that could impact build performance and highlights a potential issue where the global benchmark rule setting might restrict other benchmarks in the module.

Comment thread app/build.gradle.kts Outdated
Comment thread benchmarks/build.gradle.kts
@josphatmwania
Copy link
Copy Markdown

Looks solid to me.

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.

[Bug]: BaselineProfile automaticGenerationDuringBuild fails with instrumentation error on release build

2 participants