6

running this command:

./gradlew :macro-benchmark:pixel2Api31ReleaseAndroidTest -P android.testInstrumentationRunnerArguments.class=com.benchmark.BaselineProfileGenerator -DBUILD_VARIANT=release

and this is the result:

> Task :macro-benchmark:pixel2Api31ReleaseAndroidTest FAILED
Exception thrown during onBeforeAll invocation of plugin com.google.testing.platform.plugin.android.AndroidDevicePlugin.
Failed to install APK: /Users/surajvaishnav/AndroidStudioProjects/MyProject/app/build/outputs/apk/release/app-release-d70a.apk, with option -r,-t
com.google.testing.platform.api.plugin.PluginException: Failed to install APK: /Users/surajvaishnav/AndroidStudioProjects/MyProject/app/build/outputs/apk/release/app-release-d70a.apk, with option -r,-t
        at com.google.testing.platform.plugin.android.AndroidDevicePlugin.beforeAll(AndroidDevicePlugin.kt:109)
        at com.google.testing.platform.plugin.PluginLifecycle$onBeforeAll$1$2$1.invoke(PluginLifecycle.kt:93)
        at com.google.testing.platform.plugin.PluginLifecycle$onBeforeAll$1$2$1.invoke(PluginLifecycle.kt:92)
        at com.google.testing.platform.plugin.PluginLifecycleKt$invokeOrThrow$1.invoke(PluginLifecycle.kt:213)
        at com.google.testing.platform.plugin.PluginLifecycleKt$invokeOrThrow$1.invoke(PluginLifecycle.kt:212)
        at com.google.testing.platform.core.telemetry.common.noop.NoopDiagnosticsScope.recordEvent(NoopDiagnosticsScope.kt:35)
        at com.google.testing.platform.core.telemetry.TelemetryKt.recordEvent(Telemetry.kt:105)
        at com.google.testing.platform.core.telemetry.TelemetryKt.recordEvent$default(Telemetry.kt:98)
        at com.google.testing.platform.plugin.PluginLifecycleKt.invokeOrThrow(PluginLifecycle.kt:212)
        at com.google.testing.platform.plugin.PluginLifecycleKt.invokeOrThrow$default(PluginLifecycle.kt:205)
        at com.google.testing.platform.plugin.PluginLifecycle$onBeforeAll$1.invoke(PluginLifecycle.kt:92)
        at com.google.testing.platform.plugin.PluginLifecycle$onBeforeAll$1.invoke(PluginLifecycle.kt:88)
        at com.google.testing.platform.core.telemetry.common.noop.NoopDiagnosticsScope.recordEvent(NoopDiagnosticsScope.kt:35)
        at com.google.testing.platform.core.telemetry.TelemetryKt.recordEvent(Telemetry.kt:105)
        at com.google.testing.platform.core.telemetry.TelemetryKt.recordEvent$default(Telemetry.kt:98)
        at com.google.testing.platform.plugin.PluginLifecycle.onBeforeAll(PluginLifecycle.kt:88)
        at com.google.testing.platform.executor.SingleDeviceExecutor$execute$4.invoke(SingleDeviceExecutor.kt:86)
        at com.google.testing.platform.executor.SingleDeviceExecutor$execute$4.invoke(SingleDeviceExecutor.kt:86)
        at com.google.testing.platform.executor.SingleDeviceExecutor.runUnlessCancelled(SingleDeviceExecutor.kt:105)
        at com.google.testing.platform.executor.SingleDeviceExecutor.execute(SingleDeviceExecutor.kt:86)
        at com.google.testing.platform.RunnerImpl.run(RunnerImpl.kt:108)
        at com.google.testing.platform.server.strategy.NonInteractiveServerStrategy$run$4.invoke(NonInteractiveServerStrategy.kt:80)
        at com.google.testing.platform.server.strategy.NonInteractiveServerStrategy$run$4.invoke(NonInteractiveServerStrategy.kt:79)
        at com.google.testing.platform.core.telemetry.common.noop.NoopDiagnosticsScope.recordEvent(NoopDiagnosticsScope.kt:35)
        at com.google.testing.platform.core.telemetry.TelemetryKt.recordEvent(Telemetry.kt:66)
        at com.google.testing.platform.server.strategy.NonInteractiveServerStrategy.run(NonInteractiveServerStrategy.kt:79)
        at com.google.testing.platform.main.MainKt$main$4.invokeSuspend(Main.kt:67)
        at kotlin.coroutines.jvm.internal.BaseContinuationImpl.resumeWith(ContinuationImpl.kt:33)
        at kotlinx.coroutines.DispatchedTask.run(DispatchedTask.kt:106)
        at kotlinx.coroutines.EventLoopImplBase.processNextEvent(EventLoop.common.kt:274)
        at kotlinx.coroutines.BlockingCoroutine.joinBlocking(Builders.kt:85)
        at kotlinx.coroutines.BuildersKt__BuildersKt.runBlocking(Builders.kt:59)
        at kotlinx.coroutines.BuildersKt.runBlocking(Unknown Source)
        at kotlinx.coroutines.BuildersKt__BuildersKt.runBlocking$default(Builders.kt:38)
        at kotlinx.coroutines.BuildersKt.runBlocking$default(Unknown Source)
        at com.google.testing.platform.main.MainKt.main(Main.kt:66)
        at com.google.testing.platform.main.MainKt.main$default(Main.kt:34)
        at com.google.testing.platform.main.MainKt.main(Main.kt)
        at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
        at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
        at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
        at java.base/java.lang.reflect.Method.invoke(Method.java:566)
        at com.google.testing.platform.launcher.Launcher.main(Launcher.java:149)

Here is the test file:

@OptIn(ExperimentalBaselineProfilesApi::class)
@RunWith(AndroidJUnit4ClassRunner::class)
class BaselineProfileGenerator {

    @get:Rule
    val rule = BaselineProfileRule()

    @Test
    fun generate() = rule.collectBaselineProfile("com.example.myapp"){
        startActivityAndWait()
    }
}
Suraj Vaishnav
  • 7,777
  • 4
  • 43
  • 46
  • This looks like a problem installing the version of the APK. Do you have debug keystore for your release variant? If not, you can create new build type that would be based on release and use debug keystore. – mlykotom Oct 29 '22 at 03:02
  • @mlykotom I am using the debug keystore already, I think the error is more related to storage, maybe managed device don't have sufficient storage to install the app, I am not sure of this, just saying because similar error I got in emulator and that specified that low storage issue. – Suraj Vaishnav Nov 10 '22 at 12:08
  • It could be prolem with not enough storage. Just to verify -- so you are able to run it in emulator succesfully, but it fails with GMD? – mlykotom Nov 10 '22 at 14:35
  • Yes, It's running on emulator but on managed devices it is giving this error, BTW there is any way to configure the storage for GMD? – Suraj Vaishnav Nov 10 '22 at 15:36
  • Does it work when running from android studio? I faced a similar issue when running on gradle. The project had split abis enabled, so maybe that confuses the gradle task as to which apk should be installed. Looking at your apk name, do you generate multiple apks as well? If so, maybe try disabling it just to test this theory. – Rahul Sainani Mar 07 '23 at 14:52
  • @RahulSainani No, I am not generating multiple APKs, but I had tried an alternate solution, which I have added in the answer, please check if that works for you. – Suraj Vaishnav Mar 08 '23 at 06:23
  • @RahulSainani I'm facing the same issue as I'm generating multiple apks for different abis. Seems like gradle is not able to choose the right apk depending on the architecture. Were you able to get it to work? – Shashank Ks Jul 07 '23 at 22:59

1 Answers1

0

Well, I Still don't have the answer to this question, but there is an alternate way to generate the baseline profile on rooted device, I had tried it on emulator (it can work on real rooted device too):

  1. Enable root access for your emulator:

adb root

Note: adb root will only work with those emulator which don't have play store in it, so create a new emulator if needed (without playstore).

  1. Run this command:

./gradlew :macro-benchmark:connectedBenchmarkAndroidTest -P android.testInstrumentationRunnerArguments.class=com.package.name.BaselineProfileGenerator

here,

connectedBenchmarkAndroidTest will run the instrumentation test for the connected device using Benchmark build type,

com.package.name.benchmarkBaselineProfileGenerator is the name of the test file that will generate the baseline profile.

Suraj Vaishnav
  • 7,777
  • 4
  • 43
  • 46