# Jenkins CI setup for Android Projects
# Step by step approach to set up Jenkins for Android
This is a step by step guide to set up the automated build process using Jenkins CI for your Android projects. The following steps assume that you have new hardware with just any flavor of Linux installed. It is also taken into account that you might have a remote machine.
# PART I: Initial setup on your machine
ssh username@xxx.xxx.xxx
wget [https://dl.google.com/android/android-sdk_r24.4.1-linux.tgz](https://dl.google.com/android/android-sdk_r24.4.1-linux.tgz)
sudo apt-get install tar
tar -xvf android-sdk_r24.4.1-linux.tgz
sudo apt-get install python-software-properties
sudo add-apt-repository ppa:webupd8team/java
sudo apt-get update
apt-get install openjdk-8-jdk
wget -q -O - [https://pkg.jenkins.io/debian/jenkins-ci.org.key](https://pkg.jenkins.io/debian/jenkins-ci.org.key) | sudo apt-key add -
sudo sh -c 'echo deb [http://pkg.jenkins.io/debian-stable](http://pkg.jenkins.io/debian-stable) binary/ > /etc/apt/sources.list.d/jenkins.list'
sudo apt-get update
sudo apt-get install jenkins
wget [https://services.gradle.org/distributions/gradle-2.14.1-all.zip](https://services.gradle.org/distributions/gradle-2.14.1-all.zip)
unzip gradle-2.14.1-all.zip
cd android-sdk-linux/tools **// lists available SDK**
android update sdk --no-ui **// Updates SDK version**
android list sdk -a | grep "SDK Build-tools" **// lists available build tools**
android update sdk -a -u -t 4 **// updates build tools version to one listed as 4 by prev. cmd.**
update java
sudo apt-get install git
cat /var/lib/jenkins/secrets/initialAdminPassword
wget https://dl.google.com/android/android-sdk_r24.4.1-linux.tgz (opens new window)
sudo apt-get install python-software-properties
sudo add-apt-repository ppa:webupd8team/java
sudo apt-get update
apt-get install openjdk-8-jdk
wget [https://services.gradle.org/distributions/gradle-2.14.1-all.zip](https://services.gradle.org/distributions/gradle-2.14.1-all.zip)
unzip gradle-2.14.1-all.zip
sudo apt-get install git
# PART II: Set up Jenkins to build Android Jobs
Jenkins > Manage Jenkins > Global Tool Configuration
Name = JAVA_HOME
JAVA_HOME = /usr/lib/jvm/java-8-openjdk-amd64
Name = Default
/usr/bin/git
Jenkins > Manage Jenkins > Configuration
Name = ANDROID_HOME
Value = /home/username/android-sdk-linux
Name = JAVA_HOME
JAVA_HOME = /usr/lib/jvm/java-8-openjdk-amd64
Jenkins > Manage Jenkins > Configuration
# Part III: Create a Jenkins Job for your Android project
Directory /home/user/Code/ProjectFolder
Repository URL = [https://username:password@bitbucket.org/project/projectname.git](https://username:password@bitbucket.org/project/projectname.git)
Clean Before Checkout
Checkout to a sub-directory. Local subdirectory for repo /home/user/Code/ProjectFolder
*/master
cd /home/user/Code/ProjectFolder && gradle clean assemble --no-daemon
/home/user/gradle/gradle-2.14.1/bin/gradle lint
Repository URL = https://username:password@bitbucket.org/project/projectname.git (opens new window)
*/master
/home/user/gradle/gradle-2.14.1/bin/gradle lint
Now your system is finally set up to build Android projects using Jenkins. This setup makes your life so much easier for releasing builds to QA and UAT teams.
PS: Since Jenkins is a different user on your Ubuntu machine, you should give it rights to create folders in your workspace by executing the following command:
chown -R jenkins .git