Jenkins and Android

We use Jenkins to build our Android app. I am converting the build from r12 to r18 (now r20, since Google I/O 2012) which is forcing some config changes, but trying to preserve the old build in case we need to rebuild something old. So I use $ANDROID_HOME, specified in the System config under “Android SDK root”, which each job will specify, to point to the correct SDK. And I define two other vars, ANDROID_HOME_18 and ANDROID_HOME_12 to refer to later.

[EnvInject] - Injecting as environment variables the properties content 
ANDROID_HOME=${ANDROID_HOME_18}
PATH=${ANDROID_HOME_18}/tools:${ANDROID_HOME_18}/platform-tools:${SONAR_RUNNER_HOME}/bin

[EnvInject] - Variables injected successfully.
[locks-and-latches] Checking to see if we really have the locks
[locks-and-latches] Have all the locks, build can start
$ /usr/share/android-sdk-macosx.r18//tools/android list target
/usr/share/android-sdk-macosx.r18//tools/android: line 30: dirname: command not found
/usr/share/android-sdk-macosx.r18//tools/android: line 33: basename: command not found
/usr/share/android-sdk-macosx.r18//tools/android: line 40: dirname: command not found
/usr/share/android-sdk-macosx.r18//tools/android: line 44: dirname: command not found
/usr/share/android-sdk-macosx.r18//tools/android: line 48: basename: command not found
[android] The configured Android platform needs to be installed: android-8
[android] Installing the 'android-8' SDK component(s)...
$ /usr/share/android-sdk-macosx.r18//tools/android update sdk -u -a -t android-8
/usr/share/android-sdk-macosx.r18//tools/android: line 30: dirname: command not found
/usr/share/android-sdk-macosx.r18//tools/android: line 33: basename: command not found
/usr/share/android-sdk-macosx.r18//tools/android: line 40: dirname: command not found
/usr/share/android-sdk-macosx.r18//tools/android: line 44: dirname: command not found
/usr/share/android-sdk-macosx.r18//tools/android: line 48: basename: command not found
: can't find sdkmanager.jar
[android] Using Android SDK: /usr/share/android-sdk-macosx.r18/
[android] Waiting 1 seconds before starting emulator...
$ /usr/share/android-sdk-macosx.r18//platform-tools/adb start-server

Lots of things missing. dirname and basename live in /usr/bin, cannot be found due to bad path. sdkmanager.jar missing. Add /usr/bin:/bin:/usr/sbin:/sbin:/usr/local/bin:/usr/X11/bin to PATH. Better. Still cannot find the android-8 libs. Spent a lot of time, adding debug to the Ant scripts, trying to log the environment. Ready to crack into the source. Sigh.

Read a bit on the Android Emulator Plugin, and it exports ANDROID_HOME. Could it be colliding with mine? I injected a NEW home variable, instead of ANDROID_HOME, and use that to pass in the current SDK location.

[EnvInject] - Injecting as environment variables the properties content 
XXX_ANDROID_HOME=${ANDROID_HOME_18}
PATH=${ANDROID_HOME_18}/tools:${ANDROID_HOME_18}/platform-tools:${SONAR_RUNNER_HOME}/bin:/usr/bin:/bin:/usr/sbin:/sbin:/usr/local/bin:/usr/X11/bin

[EnvInject] - Variables injected successfully.
[locks-and-latches] Checking to see if we really have the locks
[locks-and-latches] Have all the locks, build can start
[android] Using Android SDK: /usr/share/android-sdk-macosx.r18/
[android] Waiting 1 seconds before starting emulator...
$ /usr/share/android-sdk-macosx.r18//platform-tools/adb start-server
[android] Starting Android emulator
[android] Erasing existing emulator data...
$ /usr/share/android-sdk-macosx.r18//tools/emulator -no-boot-anim -ports 58553,58554 -prop persist.sys.language=en -prop

and that seems to work.

Takeaway : don’t define ANDROID_HOME locally, let the plugin define it. It will anyway.

This entry was posted in Computers, Software and tagged , , , , , , , , . Bookmark the permalink.

Leave a Reply