14
Genymotion with Jenkins Using genymotion device as emulator for Jenkins test

Genymotion with Jenkins

Embed Size (px)

Citation preview

Page 1: Genymotion with Jenkins

Genymotion with Jenkins

Using genymotion device as emulator for Jenkins test

Page 2: Genymotion with Jenkins

Contents

• Quick intro to Genymotion

• Genymotion in Headless mode

– Implementation steps

– Challenges faced

– Workarounds

• Overview of final implementation

• Repository URL for working script

Page 3: Genymotion with Jenkins

Quick intro to Genymotion

• Genymotion is a fast and easy-to-use

Android emulator to run and test Android

apps

• Based on Oracle VirtualBox, can be

operated using Vbox commands as well

Page 4: Genymotion with Jenkins

Genymotion

& Jenkins

Page 5: Genymotion with Jenkins

Implementation steps

1) Run Genymotion devices in a headless

mode

2) Retrieve IP addresses of GM devices

3) Connect adb to IP of device

4) Logic for selection of free/available

genymotion device for multiple build devices

5) Ensure test apk is installed on correct

devices even for multiple/concurrent builds

Page 6: Genymotion with Jenkins

Starting genymotion in

headless mode

[Problem]

Using genymotion built-in player command throws Open-GL errors when used with X-Forwarding

eglMakeCurrent failed FrameBuffer::post

eglMakeCurrent failed

zsh: segmentation fault

http://blog.genymobile.com/genymotion-jenkins-android-testing/

http://stackoverflow.com/questions/28871412/genymotion-device-boots-up-and-disappears-after-showing-a-black-screen

[Workaround]

Use VBoxManage startvm <VM-UUID> --type headless command

Page 7: Genymotion with Jenkins

Identifying IP address

[Problem]

• IP address of genymotion devices is required to connect adb to device

• However, genymotion virtual device IP address does not show up in usual system commands like “arp”

[Workaround]VBoxManage guestproperty get $VM_SELECTED androvm_ip_management

This command shows the IP only when device is running

Page 8: Genymotion with Jenkins

ADB port connection

[Problem]

• Adb start-server usually starts ADB server on default port of 5037

• However for concurrent build if all servers start on same port adb installation for test apk fails

[Workaround]

• set env variable ANDROID_ADB_SERVER_PORT

• this changes the default adb server port to desired value for that particular shell session

Page 9: Genymotion with Jenkins

Setting default genymotion device

[Problem]

• Setting ADB server port is not enough since gradle connectedCheck internally starts adb in default port 5037

• As a result, gradle does not find connected genymotion devices when running tests. Installation of test apk fails with “No connected devices”

[Workaround]

• Set env variable ANDRIOD_SERIAL to specify which genymotion device to be used as default as test

• This was introduced as feature in android Gradle plugin 0.14.0 (AS 1.0)

https://code.google.com/p/android/issues/detail?id=59894

https://code.google.com/p/android/issues/detail?id=75407

https://android-review.googlesource.com/#/c/108985/1/build-system/builder/src/main/java/com/android/builder/testing/ConnectedDeviceProvider.java

Page 10: Genymotion with Jenkins

Making builds thread safe (locking)

[Problem]

• For concurrent builds, the logic to select Genymotion device must be thread safe

• Else more than one build would select the same device and gradle tests would fail

[Workaround]

• Create temporary lock directory using mkdir command

• Name of lock directory same as that of genymotion device

• mkdir being atomic in operation mkdir would fail for concurrent build in case directory already exists

Page 11: Genymotion with Jenkins

Handling build abort scenarios

[Problem]

• In case build is aborted in between using Jenkins interfaces, its important to delete all lock directories. Else, build would never run on those geny motion devices

[Workaround]

• A simple workaround was to catch INT, TERM trap signals in shell script and delete all temp files

Page 12: Genymotion with Jenkins

Overview of Final Implementation

1) Start genymotion devices in headless mode

2) Select random ADB server port

3) Select free genymotion device with thread safe logic (in case of concurrent Jenkins build jobs)

4) Set env variable ANDROID_ADB_SERVER_PORT to set the default ADB server port selected in Step (2)

5) Set env variable ANDROID_SERIAL to desired target genymotion device for gradle test

6) Run gradle tests

Note: genymotion devices are kept running in the background. Alternatively they can be booted up and shutdown in the build script using Vbox commands

Page 13: Genymotion with Jenkins

Repository URL for working script

https://github.com/vishyrich/GenymotionJenkinsBuild.git

Page 14: Genymotion with Jenkins

THANK YOU!!