I am trying to integrate the newly introduced baseline profiles into our app. I am using the following simple snippet to generate a baseline profile.
@RunWith(AndroidJUnit4::class)
class BaseProfileGenerator {
@get:Rule
val baselineProfile = BaselineProfileRule()
@Test
fun appStartup() {
baselineProfile.collectBaselineProfile(packageName = InstrumentationRegistry.getInstrumentation().context.packageName) {
pressHome()
startActivityAndWait()
}
}
}
However, on running the test on a gradle managed device/emulator, I am getting the following exception:
java.lang.ExceptionInInitializerError
at androidx.benchmark.Shell.isSessionRooted(Shell.kt:165)
at androidx.benchmark.macro.BaselineProfilesKt$collectBaselineProfile$killProcessBlock$1.invoke(BaselineProfiles.kt:64)
at androidx.benchmark.macro.BaselineProfilesKt$collectBaselineProfile$killProcessBlock$1.invoke(BaselineProfiles.kt:60)
at androidx.benchmark.macro.BaselineProfilesKt.collectBaselineProfile(BaselineProfiles.kt:69)
at androidx.benchmark.macro.junit4.BaselineProfileRule.collectBaselineProfile(BaselineProfileRule.kt:94)
at androidx.benchmark.macro.junit4.BaselineProfileRule.collectBaselineProfile$default(BaselineProfileRule.kt:88)
at com.package.name.baselineprofile.BaseProfileGenerator.appStartup(BaseProfileGenerator.kt:28)
... 36 trimmed
Caused by: java.io.IOException: Operation not permitted
at java.io.UnixFileSystem.createFileExclusively0(Native Method)
at java.io.UnixFileSystem.createFileExclusively(UnixFileSystem.java:317)
at java.io.File.createTempFile(File.java:2007)
at androidx.benchmark.ShellImpl.createShellScript(Shell.kt:507)
at androidx.benchmark.ShellImpl.<clinit>(Shell.kt:471)
... 44 more
According the the docs, it was stated that we need a userdebug/rooted device in order to generate the profile and I was under the impression gradle managed devices with aosp system image will satisfy that need.
For reference, here's the device in my build.gradle.kts:
managedDevices {
devices {
add(
ManagedVirtualDevice("pixel2Api31").apply {
device = "Pixel 2"
apiLevel = 31
systemImageSource = "aosp"
}
)
}
}
Android Gradle Plugin = v7.3.1 macroBenchmarVersion = v1.2.0-alpha07 profileInstallerVersion = 1.3.0-alpha01
Any idea what might be happening here? I searched around but couldn't find anything relevant.
I tried updating the dependencies to the latest alpha versions since apparently according to the release notes, baseline profiles no longer need rooted devices but even then its failing with the same exception.