• After 15+ years, we've made a big change: Android Forums is now Early Bird Club. Learn more here.

Apps Setup a local Jenkins for your Android project

Was this post helpful?

  • Yes

    Votes: 1 100.0%
  • No

    Votes: 0 0.0%

  • Total voters
    1
Original Source can be found here: https://xamoom.com/en/2016/05/setup-a-local-jenkins-for-your-android-project/

Install Jenkins
You can install jenkins via their installer (https://jenkins.io/) or homebrew(http://brew.sh/). If you want to have a mac app in your dock like me, here is a github project with a bundled Jenkins App. (https://github.com/stisti/jenkins-app)

After installing and starting Jenkins you should be able to open your browser and go to jenkins normally with the urlhttp://localhost:8080/.

Install Plugins
Before we can start with building and testing we need some plugins.

  1. Click “Manage Jenkins”
  2. Click “Manage Plugins”
  3. Under the tab “Available” you can search for plugins
Jenkins-1-Step.jpg


Install the following plugins:

  • Git plugin
  • Android Emulator Plugin
  • Gradle plugin
You may need to restart your jenkins.

Setup ANDROID_HOME variable
  1. Click “Manage Jenkins”
  2. Click “Configure System”
  3. Scroll to “Global properties”
  4. Add a key-value pair with name “ANDROID_HOME” and the path to your Android SDK as value
Configure_System__Jenkins_.png


Setup Gradle
  1. Click “Manage Jenkins”
  2. Click “Configure System”
  3. Scroll to “Gradle”
  4. Fill in the form as follows:
    • name – “Gradle”
    • GRADLE_HOME – the path to your gradle
(My path is “/Applications/Android Studio.app/Contents/gradle/gradle-2.10”)

Create the Jenkins job
Back at the main site of Jenkins we now create a new Jenkins job for our project.

  1. Click “New Item”
  2. Insert your Item Name
  3. Choose Freestyle Project
  4. Click “Ok”
New_Item__Jenkins_.png




You will be redirected to the configuration page of your Jenkins job.

Here we will configure everything we need to build our project and test it.

Jenkins Job Configuration
First we will configure our connection to github.

Repository URL Copy here the git repository url from your project
Credentials Reuse or create new credentials for your git
Branches to build Insert your branch you want to build
AndroidJenkinsTut_Config__Jenkins_.png


Now we define when Jenkins will get new builds from github.
Here we use “H/15 * * * *“ to check every 15 minutes.



Jenkins7.png


Now we configure an Android emulator, that will get started to run our tests.


Android OS Version Numeric Android version
Screen density Density e.g. 160, mdpi, hdpi
Screen resolution Resolution to test on e.g. 480×800, WVGA
Device locale Language region pair existing on the device
SD card size Size of emulator sd card
Target ABI Android system
Emulator name suffix Optional suffix
AndroidJenkinsTut_Config__Jenkins_-2.png


Under build we add now “Invoke Gradle script”


AndroidJenkinsTut_Config__Jenkins_-3.png


We select “Use Gradle Wrapper” and check “Make gradlew executeable” and “From Root Build Script Dir”.

In the field “Tasks” we insert:

Tasks clean test connectedCheck build
Click save and we are finished!

First run
Now push a new commit to your git and wait for Jenkins to finish the build.

If the build fails, look at the
AndroidJenkinsTut__2_Console__Jenkins_.png
. You will find there why the build failed and can fix your problem.

If your build passes. Yipieh
1f389.png
1f389.png
1f389.png




Dashboard__Jenkins_.png


Conclusion
Now you should have a working Jenkins job for you Android project. You can use it for unittests, integration tests and UI-Tests.

You can also extends Jenkins to:

  • Generate a *.apk
  • Send Email or Slack notifications
  • Calculate Code Coverage
  • and a lot more …
If you want to create the same for iOS you can check out: How to setup a local Jenkins for your iOS
 
Last edited:
Back
Top Bottom