Setting up Android SDK on Jenkins

Building Android apps does not work out-of-the-box. Without installing, you will see this error:

* What went wrong:
Could not determine the dependencies of task ':app:compileReleaseJavaWithJavac'.
> SDK location not found. Define location with an ANDROID_SDK_ROOT environment variable or by setting the sdk.dir path in your project's local properties file at '/var/lib/jenkins/workspace/ExampleProject/'.


Visit the Android SDK download page and copy the link to the Linux distro. It’s under ‘Command line tools only’. Hit the item, then the checkbox, then copy the link of the big blue download button.

Continue as the jenkins user, and download it:

cd /media/data/workspace/
mkdir android-sdk
unzip -d android-sdk
export ANDROID_HOME="/media/data/workspace/android-sdk"
export PATH="$ANDROID_HOME/tools:$ANDROID_HOME/platform-tools:$PATH"
android-sdk/tools/bin/sdkmanager --licenses

If you get a ClassDefNotFoundError: XmlSchema - You’re running Open JDK 11. Downgrade to 8 instead:

sudo apt-get remove default-jdk
sudo apt-get autoremove
sudo apt-get install openjdk-8-jre openjdk-8-jdk
sudo update-alternatives --config java