Problem with running android tests on emulator


I am trying to run android test with Espresso and getting this error " Error performing ‘single click’ on view ‘with id: …’.
Everything works locally on Android emulator, real device and genymotion. Trying to find solution I also implemented code to wakeup, unlock device and remove tutorial message:

private void prepareDevice() {
    try {
    } catch (RemoteException e) {

    try {
        new UiObject(new UiSelector().className("android.widget.Button").text("OK")
    } catch (UiObjectNotFoundException e) {

    int dHeight = device.getDisplayHeight();
    int dWidth = device.getDisplayWidth(); / 2, dHeight / 2);

This didn’t help so I implemented code to get device screenshot but the same problem - it works only locally and doesn’t work on emulator:

 - wget
 - chmod a+x
 - adb shell screencap -p | sed 's/\r$//' > alua.png
 - ./ alua.png

It seems I spent about several days to run android tests on circle without success. Please help! :wink:

P. S. My circle.yml:

        GRADLE_OPTS: '-Dorg.gradle.jvmargs="-Xmx2048m -XX:+HeapDumpOnOutOfMemoryError"'
        PATH: "~/$CIRCLE_PROJECT_REPONAME/gradle-2.9/bin:$PATH"
        TERM: "dumb"
        version: oraclejdk7

      - master

    - wget ""; unzip
    - echo y | android update sdk --no-ui --all --filter tool,extra-android-m2repository,extra-android-support,extra-google-google_play_services,extra-google-m2repository,android-23
    - echo y | android update sdk --no-ui --all --filter build-tools-23.0.2

         - emulator -avd circleci-android22 -no-audio -no-window:
             background: true
             parallel: true
         - circle-android wait-for-boot
         - sleep 70
         - adb shell input keyevent 82

         - wget
         - chmod a+x
         - adb shell screencap -p | sed 's/\r$//' > alua.png
         - ./ alua.png

         - sleep 5
         - fb-adb shell input touchscreen swipe 370 735 371 735
         - sleep 5

         - ./gradlew connectedAndroidTest -PdisablePreDex --stacktrace

         - ./gradlew assembleRelease -PdisablePreDex --stacktrace
         - ./gradlew testDevReleaseUnitTest --continue --stacktrace
         - ./gradlew testStageReleaseUnitTest --continue --stacktrace

         - cp -r app/build/reports $CIRCLE_ARTIFACTS
         - cp -r app/build/outputs $CIRCLE_ARTIFACTS
         - cp -r app/build/outputs/androidTest-results/* $CIRCLE_TEST_REPORTS
         - mkdir $CIRCLE_TEST_REPORTS/junit
         - find */build/test-results -name "*.xml" -exec cp {} $CIRCLE_TEST_REPORTS/junit/ \;


Have you tried to re-run your test suite with VNC enabled? If not, here are the docs to VNC into a builder.

From the little Android development I’ve done, I know the emulators can be flakey, and are sensitive to events like an alert window popping up, which can cause a test suite to freeze up. Hopefully, re-running your tests from VNC might show you something funny that the Android emulator is doing.

Let us know if that helps!


I connected with VNC, created screenshot, but I couldn’t copy it - “Permission denied”. Also I tried like several hours to push screenshot on image server without success. Now I have no ideas how to do it.


Where was the screenshot created, and how did you attempt to copy it?


I used scp command, screenshot was created in project folder and I got permission denied alert.


Does your app require Google Play services? The circleci-android22 avd does not have it installed.


It doesn’t require.