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
go to an android-SDK directory
Perform below command for setup android SDK.
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
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 https://dl.google.com/android/repository/sdk-tools-linux-3859397.zip -o android-sdk.zip
# install unzip command
sudo apt-get install unzip
# unzip into this folder
sudo unzip android-sdk.zip -d .
# remove the zip file
sudo rm android-sdk.zip
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 git@github.com:{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
Start the Build
From the job dashboard, click Build Now and you will see job run.
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.