android / codelab-android-performance

Apache License 2.0
21 stars 8 forks source link

StaleObjectException #15

Open janaltenhof opened 1 year ago

janaltenhof commented 1 year ago

Hi, when I want to run the Baseline Profile Generator in step 7 of the codelab I'm getting this error. I don't know what to do? Can you help me?

com.google.baselineprofile.BaselineProfileGenerator > generate[pixel6Api31] FAILED 
    androidx.test.uiautomator.StaleObjectException
        at androidx.test.uiautomator.UiObject2.getAccessibilityNodeInfo(UiObject2.java:647)
keyboardsurfer commented 8 months ago

I could not reproduce this locally. Sometimes this happens when the screen turns off during benchmarking. Make sure the display time out is set long enough.

gerardoeg commented 8 months ago

Please @keyboardsurfer, reactivate this issue, since I'm getting this error over the following run configuration. Android Studio Iguana | 2023.2.1 Canary 7 AGP = 8.0.0 androidx-baselineprofile = "1.2.0-alpha13" profileinstaller = "1.3.0"

running task ./gradlew :app:generateReleaseBaselineProfile -Pandroid.testInstrumentationRunnerArguments.androidx.benchmark.enabledRules=BaselineProfile --info

SEVERE: Execute com.google.baselineprofile.BaselineProfileGenerator.generate: FAILED
androidx.test.uiautomator.StaleObjectException
        at androidx.test.uiautomator.UiObject2.getAccessibilityNodeInfo(UiObject2.java: androidx.test.uiautomator.StaleObjectException
        at androidx.test.uiautomator.UiObject2.getAccessibilityNodeInfo(UiObject2.java:647)
        at androidx.test.uiautomator.UiObject2.getVisibleBounds(UiObject2.java:213)
        at androidx.test.uiautomator.UiObject2.getVisibleCenter(UiObject2.java:264)
        at androidx.test.uiautomator.UiObject2.click(UiObject2.java:356)
        at com.google.baselineprofile.BaselineProfileGeneratorKt.goToSnackDetailJourney(BaselineProfileGenerator.kt:87)
        at com.google.baselineprofile.BaselineProfileGenerator$generate$1.invoke(BaselineProfileGenerator.kt:58)
        at com.google.baselineprofile.BaselineProfileGenerator$generate$1.invoke(BaselineProfileGenerator.kt:42)
        at androidx.benchmark.macro.BaselineProfilesKt$collectBaselineProfile$1$1.invoke(BaselineProfiles.kt:68)
        at androidx.benchmark.macro.BaselineProfilesKt$collectBaselineProfile$1$1.invoke(BaselineProfiles.kt:62)
        at androidx.benchmark.macro.CompilationMode$Partial.compileImpl$benchmark_macro_release(CompilationMode.kt:319)
        at androidx.benchmark.macro.CompilationMode.resetAndCompile$benchmark_macro_release(CompilationMode.kt:115)
        at androidx.benchmark.macro.BaselineProfilesKt.collectBaselineProfile(BaselineProfiles.kt:62)
        at androidx.benchmark.macro.junit4.BaselineProfileRule.collectBaselineProfile(BaselineProfileRule.kt:131)
        at androidx.benchmark.macro.junit4.BaselineProfileRule.collectBaselineProfile$default(BaselineProfileRule.kt:123)
        at com.google.baselineprofile.BaselineProfileGenerator.generate(BaselineProfileGenerator.kt:42)
androidx.test.uiautomator.StaleObjectException
        at androidx.test.uiautomator.UiObject2.getAccessibilityNodeInfo(UiObject2.java:647)
        at androidx.test.uiautomator.UiObject2.getVisibleBounds(UiObject2.java:213)
        at androidx.test.uiautomator.UiObject2.getVisibleCenter(UiObject2.java:264)
        at androidx.test.uiautomator.UiObject2.click(UiObject2.java:356)
        at com.google.baselineprofile.BaselineProfileGeneratorKt.goToSnackDetailJourney(BaselineProfileGenerator.kt:87)
        at com.google.baselineprofile.BaselineProfileGenerator$generate$1.invoke(BaselineProfileGenerator.kt:58)
        at com.google.baselineprofile.BaselineProfileGenerator$generate$1.invoke(BaselineProfileGenerator.kt:42)
        at androidx.benchmark.macro.BaselineProfilesKt$collectBaselineProfile$1$1.invoke(BaselineProfiles.kt:68)
        at androidx.benchmark.macro.BaselineProfilesKt$collectBaselineProfile$1$1.invoke(BaselineProfiles.kt:62)
        at androidx.benchmark.macro.CompilationMode$Partial.compileImpl$benchmark_macro_release(CompilationMode.kt:319)
        at androidx.benchmark.macro.CompilationMode.resetAndCompile$benchmark_macro_release(CompilationMode.kt:115)
        at androidx.benchmark.macro.BaselineProfilesKt.collectBaselineProfile(BaselineProfiles.kt:62)
        at androidx.benchmark.macro.junit4.BaselineProfileRule.collectBaselineProfile(BaselineProfileRule.kt:131)
        at androidx.benchmark.macro.junit4.BaselineProfileRule.collectBaselineProfile$default(BaselineProfileRule.kt:123)
        at com.google.baselineprofile.BaselineProfileGenerator.generate(BaselineProfileGenerator.kt:42)
gerardoeg commented 8 months ago

Update @janaltenhof: By updating the following configuration I made it work.


    testOptions.managedDevices.devices {
        create<ManagedVirtualDevice>("pixel6Api30") {
            device = "Pixel 6"
            apiLevel = 30 // CHANGED FROM 31 TO 30, (32 DIDN'T WORK)
            systemImageSource = "aosp"
        }
    }

Additional note, the following configuration, testing on a physical device using API 34 (Android 14), didn't work. baselineProfile { // managedDevices += "pixel6Api30" useConnectedDevices = true }

keyboardsurfer commented 7 months ago

We're working on addressing this within the Macrobenchmark library itself. In the meantime we recommend running the tests again in case they fail with a StaleObjectException.