Uploaded image for project: 'Jenkins'
  1. Jenkins
  2. JENKINS-55313

Gradle support for connectedAndroidTest

    XMLWordPrintable

    Details

    • Type: Bug
    • Status: Open (View Workflow)
    • Priority: Minor
    • Resolution: Unresolved
    • Labels:
      None
    • Environment:
      Android Emulator 3.0
      Android build tools 28.0.3
    • Similar Issues:

      Description

      Currently I struggle to get the android emulator running in combination with gradle connectedAndroidTest 

      The tests are working if I start the emulator manually.

      Also in the log I see the emulator starts correctly, but I always get 

      Execution failed for task ':app:connectedDebugAndroidTest'.
      > com.android.builder.testing.api.DeviceException: No connected devices!

      After a while of digging around I found out that the reason is that gradle uses the standard port of the adb to check for emulators and not the newly started from the android emulator plugin.

      I checked using bash if ANDROID_SERIAL is correctly set (emulator-XXXX) and it is, but it seems connectedAndroidTest doesn't pickup the value and checks for that emulator.

      I wonder if anybody has a hint what to check or how other people using this plugin starting the
      connectedAndroidTests?

        Attachments

          Activity

          Hide
          gauravdroid Gaurav P added a comment -

          I am also facing the same issue 
          have you manage to solve it ?

          Show
          gauravdroid Gaurav P added a comment - I am also facing the same issue  have you manage to solve it ?
          Hide
          attrib Karl Fritsche added a comment - - edited

          My current workaround is not using the plugin.
          I use a shell script with the following content:

          # doing android emulator stuff manual
          $ANDROID_HOME/platform-tools/adb start-server
          $ANDROID_HOME/emulator/emulator -prop persist.sys.language=de -prop persist.sys.country=DE -avd $AVD_IMAGE -no-window -no-audio &
          EMULATOR_PID=$!
          
          # Wait for Android to finish booting
          WAIT_CMD="$ANDROID_HOME/platform-tools/adb wait-for-device shell getprop init.svc.bootanim"
          until $WAIT_CMD | grep -m 1 stopped; do
            echo "Waiting..."
            sleep 1
          done
          
          [ -d build ] || mkdir build
          $ANDROID_HOME/platform-tools/adb shell logcat -v time > build/logcat.log &
          LOGCAT_PID=$!
          $ANDROID_HOME/platform-tools/adb shell wm dismiss-keyguard
          $ANDROID_HOME/platform-tools/adb shell input keyevent 4
          
          # run tests
          ./gradlew --continue test lint connectedAndroidTest || echo "failed"
          
          # Stop the background processes
          kill $LOGCAT_PID
          kill $EMULATOR_PID
          

          Its not super stable and sometimes it fails and if I just rerun it, it works. Didn't figured out if it is because of the setup or because of a bad test on our side.

          ANDROID_HOME is a global envoirment variable and I have a second job which force updates all images, each week.

          yes | $ANDROID_HOME/tools/bin/sdkmanager --update
          $ANDROID_HOME/tools/bin/avdmanager delete avd -n pixel_23 || true
          $ANDROID_HOME/tools/bin/avdmanager create avd -n pixel_23 -d pixel -k "system-images;android-23;default;x86" --force
          $ANDROID_HOME/tools/bin/avdmanager delete avd -n pixel_24 || true
          $ANDROID_HOME/tools/bin/avdmanager create avd -n pixel_24 -d pixel -k "system-images;android-24;default;x86" --force
          $ANDROID_HOME/tools/bin/avdmanager delete avd -n pixel_26 || true
          $ANDROID_HOME/tools/bin/avdmanager create avd -n pixel_26 -d pixel -k "system-images;android-26;default;x86_64" --force
          $ANDROID_HOME/tools/bin/avdmanager delete avd -n pixel_28 || true
          $ANDROID_HOME/tools/bin/avdmanager create avd -n pixel_28 -d pixel -k "system-images;android-28;default;x86" --force
          $ANDROID_HOME/tools/bin/avdmanager delete avd -n nexus10_28 || true
          $ANDROID_HOME/tools/bin/avdmanager create avd -n nexus10_28 -d "Nexus 10" -k "system-images;android-28;default;x86_64" --force
          

          AVD_IMAGE is a select parameter for this job. I have a third job (matrix job), which then calls this job with all images.

          Show
          attrib Karl Fritsche added a comment - - edited My current workaround is not using the plugin. I use a shell script with the following content: # doing android emulator stuff manual $ANDROID_HOME/platform-tools/adb start-server $ANDROID_HOME/emulator/emulator -prop persist.sys.language=de -prop persist.sys.country=DE -avd $AVD_IMAGE -no-window -no-audio & EMULATOR_PID=$! # Wait for Android to finish booting WAIT_CMD= "$ANDROID_HOME/platform-tools/adb wait- for -device shell getprop init.svc.bootanim" until $WAIT_CMD | grep -m 1 stopped; do echo "Waiting..." sleep 1 done [ -d build ] || mkdir build $ANDROID_HOME/platform-tools/adb shell logcat -v time > build/logcat.log & LOGCAT_PID=$! $ANDROID_HOME/platform-tools/adb shell wm dismiss-keyguard $ANDROID_HOME/platform-tools/adb shell input keyevent 4 # run tests ./gradlew -- continue test lint connectedAndroidTest || echo "failed" # Stop the background processes kill $LOGCAT_PID kill $EMULATOR_PID Its not super stable and sometimes it fails and if I just rerun it, it works. Didn't figured out if it is because of the setup or because of a bad test on our side. ANDROID_HOME is a global envoirment variable and I have a second job which force updates all images, each week. yes | $ANDROID_HOME/tools/bin/sdkmanager --update $ANDROID_HOME/tools/bin/avdmanager delete avd -n pixel_23 || true $ANDROID_HOME/tools/bin/avdmanager create avd -n pixel_23 -d pixel -k "system-images;android-23; default ;x86" --force $ANDROID_HOME/tools/bin/avdmanager delete avd -n pixel_24 || true $ANDROID_HOME/tools/bin/avdmanager create avd -n pixel_24 -d pixel -k "system-images;android-24; default ;x86" --force $ANDROID_HOME/tools/bin/avdmanager delete avd -n pixel_26 || true $ANDROID_HOME/tools/bin/avdmanager create avd -n pixel_26 -d pixel -k "system-images;android-26; default ;x86_64" --force $ANDROID_HOME/tools/bin/avdmanager delete avd -n pixel_28 || true $ANDROID_HOME/tools/bin/avdmanager create avd -n pixel_28 -d pixel -k "system-images;android-28; default ;x86" --force $ANDROID_HOME/tools/bin/avdmanager delete avd -n nexus10_28 || true $ANDROID_HOME/tools/bin/avdmanager create avd -n nexus10_28 -d "Nexus 10" -k "system-images;android-28; default ;x86_64" --force AVD_IMAGE is a select parameter for this job. I have a third job (matrix job), which then calls this job with all images.
          Hide
          gauravdroid Gaurav P added a comment -

          ok thanks for update 

          Show
          gauravdroid Gaurav P added a comment - ok thanks for update 
          Hide
          attrib Karl Fritsche added a comment -

          If you find a better solution, feel free to update here

          Show
          attrib Karl Fritsche added a comment - If you find a better solution, feel free to update here

            People

            Assignee:
            Unassigned Unassigned
            Reporter:
            attrib Karl Fritsche
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

              Dates

              Created:
              Updated: