I am running UI tests on an android API 19 and have been struggling to figure out why the screenshot code fails on bitrise but works locally. After much searching, I have a strong lead but need some help finishing this out.
I use square’s Spoon to run my tests, which has built in screenshot code, althought it does not capture proper screenshots for custom views, so i delegate the screenshot part to UiDevices’s takeScreenshot:
Context c = InstrumentationRegistry.getInstrumentation().getTargetContext().getApplicationContext(); File file = new File(c.getExternalCacheDir(), tag + ".png"); UiDevice.getInstance(InstrumentationRegistry.getInstrumentation()).takeScreenshot(file); Spoon.save(c, file);
This works great locally, but i get an exception when run on bitrise:
“Can’t find any file at: /storage/sdcard/Android/data/com.my.package/cache/screenshot.png”
On another forum i read that CI emulators require the SD card to be created via the avd options in order to get write permissions, so here is the avd creation command with SD card settings: (https://github.com/square/spoon/issues/283)
mksdcard -l e 512M mysdcard.img
echo no | android create avd --force -n $emulator_name -t android-19 --abi armeabi-v7a --sdcard mysdcard.img
and for booting the emaultor i added SD to this command as well:
-no-boot-anim -no-audio -no-window -sdcard mysdcard.img
I check the SD card permission, looks like its got read and write
adb shell ls -l /storage/ drwxrwx--x root sdcard_r 2017-02-01 23:09 sdcard
And yes, both the app apk and test apk have the android.permission.WRITE_EXTERNAL_STORAGE and android.permission.READ_EXTERNAL_STORAGE permissions.
Any help much appreciated! Am i setting the SD card correctly?