Horje

Android - Jenkins CI setup for Android Projects
Start
  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

  • Log in via **ssh** to your Ubuntu machine:
    ssh username@

    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

  • Once logged in, go to the following path:
    Jenkins > Manage Jenkins > Global Tool Configuration
  • At this location, add `JAVA_HOME` with the following entries:

    Name = JAVA_HOME
    JAVA_HOME = /usr/lib/jvm/java-8-openjdk-amd64

  • Also add the following values to **Git** and save the environment variables:

    Name = Default
    /usr/bin/git

  • Now go to the following path:
    Jenkins > Manage Jenkins > Configuration
  • At this location, add `ANDROID_HOME` to the "global properties":

    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

  • Click on **New Item** in the Jenkins home screen.
  • Add a **Project Name** and **Description**.
  • In the **General** tab, select **Advanced**. Then select **Use custom workspace**:
    Directory /home/user/Code/ProjectFolder
  • In the source code management select **Git**. I am using **Bitbucket** for the purpose of this example:
    Repository URL = [https://username:[email protected]/project/projectname.git](https://username:[email protected]/project/projectname.git)
  • Select additional behaviors for your repository:

    Clean Before Checkout
    Checkout to a sub-directory. Local subdirectory for repo /home/user/Code/ProjectFolder

  • Select a branch you want to build:
    */master
  • In the **Build** tab, select **Execute Shell** in **Add build step**.
  • In the **Execute shell**, add the following command:
    cd /home/user/Code/ProjectFolder && gradle clean assemble --no-daemon
  • If you want to run Lint on the project, then add another build step into the **Execute shell**:
    /home/user/gradle/gradle-2.14.1/bin/gradle lint
  • Repository URL = https://username:[email protected]/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


  • Read Article
    https://develop.horje.com/learn/1434/reference