Status Bar

Jenkins is by far one of my favorite continuous integration systems of all time. I’ve used it since I was working on development back in the seventh and eighth grade, and it’s always been an easy way to assemble, test, and deploy any applications. I’ve continued using it as my go to continuous integration system for my Android projects as well.

However, when building Android applications, there is a caveat to note when deploying a Jenkins build environment for your project. As Android applications depend on the Android SDK to build the actual project, the Jenkins environment must have access to the SDK or the build will fail. This might be easy to do if your Jenkins deployment and development environment are on the same machine, but becomes difficult if your Jenkins installation is on a remote server or simply just stored inside of a Docker container.

Gradle will attempt to automatically download the SDK, but there is an important reason why this generally fails: the license has not been accepted. The Android SDK installation has a folder called licenses that contains a file titled android-sdk-license with a random string inside. This seemingly random string is Android Studio’s way of indicating that the licensing terms for an SDK package have been accepted and that it’s ready for downloading. Since we can’t guess the download string, we’ll have to copy an existing licenses folder from our development environment into the container.

To set this environment up properly, add an environment variable in the Jenkins configuration called ANDROID_HOME which points to the directory where you want to store your SDK. Create that folder, and under that folder, paste your licenses folder from your existing SDK setup. Once this is done, you can run any Gradle steps necessary for the compilation of your application, with Gradle automatically taking care of downloading any necessary SDK dependencies.


Categories: Random Tech Tips

Leave a Reply