Published March 11, 2019 by

Generate Android APK from source code in Jenkins

In this tutorial, we will learn step by step how to generate android APK from source code in Jenkins. I assume you have already installed Jenkins.

Setup Android SDK

create directory
 mkdir -p /var/lib/jenkins/android-sdk/ 

go to an android-SDK directory
cd /var/lib/jenkins/android-sdk/  

Perform below command for setup android SDK.
 # download android sdk  
 sudo curl -o  
 # install unzip command  
 sudo apt-get install unzip  
 # unzip into this folder  
 sudo unzip -d .  
 # remove the zip file  
 sudo rm  

Install Plugins

Install Android Emulator and Gradle Plugin.

Open Jenkins: Manage Jenkins >> Mange Plugins >> Available

Configure Jenkins

Open Jenkins: Manage Jenkins >> Configure System >> Global properties >> Environment variables  and add:

ANDROID_HOME : /var/lib/jenkins/android-sdk
JAVA_HOME : /usr/lib/jvm/java-8-oracle

Create Android build job

  • Open Jenkins -> New Item. Enter any job name. Choose Freestyle project. Press OK.
  • Source Code Management -> Check Git and give:
    • Repository URL: Git URL to your repo. Take this URL from Github. It should be a format of{username}/{repo}.git
    • Credentials: Select the one you created before.
    • Branches to build: branch_name
  • Build >> Execute shell
 chmod +x gradlew  
 ./gradlew clean  
 ./gradlew assembleDebug  

  • Post-build Actions -> Archive artifacts: **/*.apk

Press Save.

Start the Build

From the job dashboard, click Build Now and you will see job run.

After successfully build you can see generated an android app in project information.