Getting this error while running startup baseline benchmarks, according to the error I need to add this dependency in my build.gradle of main android module and it is already added there

implementation("androidx.profileinstaller:profileinstaller:1.3.1")
baselineProfile(project(":baselineprofile"))

Startup Benchmark class:

@RunWith(AndroidJUnit4::class)
@LargeTest
class StartupBenchmarks {

  @get:Rule
  val rule = MacrobenchmarkRule()

  @Test
  fun startupCompilationNone() =
    benchmark(CompilationMode.None())

  @Test
  fun startupCompilationBaselineProfiles() =
    benchmark(CompilationMode.Partial(BaselineProfileMode.Require))

  private fun benchmark(compilationMode: CompilationMode) {
    rule.measureRepeated(
      packageName = "com.example.android",
      metrics = listOf(StartupTimingMetric()),
      compilationMode = compilationMode,
      startupMode = StartupMode.COLD,
      iterations = 10,
      setupBlock = {
        pressHome()
      },
      measureBlock = {
        startActivityAndWait()
      }
    )
  }}

Error received

java.lang.RuntimeException: The baseline profile install broadcast was not received. This most likely means that the profileinstaller library is missing from the target apk.
at androidx.benchmark.macro.CompilationMode$Partial.compileImpl$benchmark_macro_release(CompilationMode.kt:311)
at androidx.benchmark.macro.CompilationMode.resetAndCompile$benchmark_macro_release(CompilationMode.kt:115)
at androidx.benchmark.macro.CompilationMode.resetAndCompile$benchmark_macro_release$default(CompilationMode.kt:77)
at androidx.benchmark.macro.MacrobenchmarkKt.macrobenchmark(Macrobenchmark.kt:186)
at androidx.benchmark.macro.MacrobenchmarkKt.macrobenchmarkWithStartupMode(Macrobenchmark.kt:388)
at androidx.benchmark.macro.junit4.MacrobenchmarkRule.measureRepeated(MacrobenchmarkRule.kt:107)
at com.example.baselineprofile.StartupBenchmarks.benchmark(StartupBenchmarks.kt:49)
at com.example.baselineprofile.StartupBenchmarks.startupCompilationBaselineProfiles(StartupBenchmarks.kt:46)

Any help would be very appreciated, Thanks!

1

There are 1 best solutions below

1
On

Try on another devices, in some devices there are restrictions, for example at most of the Huawei devices there is battery optimisation, So if Battery optimisation is on then it will fail. Try on different devices first and make sure that battery optimisation is off.