• Icon: Bug Bug
    • Resolution: Unresolved
    • Icon: Minor Minor
    • None
    • Android Emulator 3.0
      Android build tools 28.0.3

      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?

          [JENKINS-55313] Gradle support for connectedAndroidTest

          Gaurav P added a comment -

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

          Gaurav P added a comment - I am also facing the same issue  have you manage to solve it ?

          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.

          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.

          Gaurav P added a comment -

          ok thanks for update 

          Gaurav P added a comment - ok thanks for update 

          Karl Fritsche added a comment -

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

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

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

              Created:
              Updated: