androidandroid-emulatoradbmonkeyrunner

problems taking screenshot only when some specific apps are running


I have problem taking screenshot in emulator with some specific apps: Taking screenshots (via monkeyrunner or adb) works ok if the app is not running (e.g. on home screen) but crashes to NullPointerException on monkeyrunner or returns 0 sized file when taking the screenshot via adb. I have verified the behavior by taking screenshot when different apps are running, so the process of taking screenshots is fine. The problem persists when using different renderer, e.g. with -gpu swiftshader_indirect or -gpu guest the behavior is the same, so it's not renderer related. Also, I have checked the behavior using multiple different AVD profiles, e.g. Pixel, Pixel 2, Nexus 5X, and multiple API versions (25, 27, 28). Using Android emulator version 28.0.22.0 (build_id 5194135) on Ubuntu 18.04.

No error in adb shell, just zero sized file:

generic_x86:/ $ screencap -p /sdcard/screen.png
generic_x86:/ $ ls -la /sdcard/screen.png
-rw-rw---- 1 root sdcard_rw 0 2019-02-18 15:29 /sdcard/screen.png

Monkeyrunner output looks like this: https://kajala.com/monkeyrunner-output.txt

Any ideas?


Solution

  • One thing that blocks screenshots/screencasts — at least in part — is FLAG_SECURE. If the app in question is using FLAG_SECURE, I would expect symptoms reminiscent of what you're seeing.