Skip to main content
Redhat Developers  Logo
  • Products

    Featured

    • Red Hat Enterprise Linux
      Red Hat Enterprise Linux Icon
    • Red Hat OpenShift AI
      Red Hat OpenShift AI
    • Red Hat Enterprise Linux AI
      Linux icon inside of a brain
    • Image mode for Red Hat Enterprise Linux
      RHEL image mode
    • Red Hat OpenShift
      Openshift icon
    • Red Hat Ansible Automation Platform
      Ansible icon
    • Red Hat Developer Hub
      Developer Hub
    • View All Red Hat Products
    • Linux

      • Red Hat Enterprise Linux
      • Image mode for Red Hat Enterprise Linux
      • Red Hat Universal Base Images (UBI)
    • Java runtimes & frameworks

      • JBoss Enterprise Application Platform
      • Red Hat build of OpenJDK
    • Kubernetes

      • Red Hat OpenShift
      • Microsoft Azure Red Hat OpenShift
      • Red Hat OpenShift Virtualization
      • Red Hat OpenShift Lightspeed
    • Integration & App Connectivity

      • Red Hat Build of Apache Camel
      • Red Hat Service Interconnect
      • Red Hat Connectivity Link
    • AI/ML

      • Red Hat OpenShift AI
      • Red Hat Enterprise Linux AI
    • Automation

      • Red Hat Ansible Automation Platform
      • Red Hat Ansible Lightspeed
    • Developer tools

      • Red Hat Trusted Software Supply Chain
      • Podman Desktop
      • Red Hat OpenShift Dev Spaces
    • Developer Sandbox

      Developer Sandbox
      Try Red Hat products and technologies without setup or configuration fees for 30 days with this shared Openshift and Kubernetes cluster.
    • Try at no cost
  • Technologies

    Featured

    • AI/ML
      AI/ML Icon
    • Linux
      Linux Icon
    • Kubernetes
      Cloud icon
    • Automation
      Automation Icon showing arrows moving in a circle around a gear
    • View All Technologies
    • Programming Languages & Frameworks

      • Java
      • Python
      • JavaScript
    • System Design & Architecture

      • Red Hat architecture and design patterns
      • Microservices
      • Event-Driven Architecture
      • Databases
    • Developer Productivity

      • Developer productivity
      • Developer Tools
      • GitOps
    • Secure Development & Architectures

      • Security
      • Secure coding
    • Platform Engineering

      • DevOps
      • DevSecOps
      • Ansible automation for applications and services
    • Automated Data Processing

      • AI/ML
      • Data Science
      • Apache Kafka on Kubernetes
      • View All Technologies
    • Start exploring in the Developer Sandbox for free

      sandbox graphic
      Try Red Hat's products and technologies without setup or configuration.
    • Try at no cost
  • Learn

    Featured

    • Kubernetes & Cloud Native
      Openshift icon
    • Linux
      Rhel icon
    • Automation
      Ansible cloud icon
    • Java
      Java icon
    • AI/ML
      AI/ML Icon
    • View All Learning Resources

    E-Books

    • GitOps Cookbook
    • Podman in Action
    • Kubernetes Operators
    • The Path to GitOps
    • View All E-books

    Cheat Sheets

    • Linux Commands
    • Bash Commands
    • Git
    • systemd Commands
    • View All Cheat Sheets

    Documentation

    • API Catalog
    • Product Documentation
    • Legacy Documentation
    • Red Hat Learning

      Learning image
      Boost your technical skills to expert-level with the help of interactive lessons offered by various Red Hat Learning programs.
    • Explore Red Hat Learning
  • Developer Sandbox

    Developer Sandbox

    • Access Red Hat’s products and technologies without setup or configuration, and start developing quicker than ever before with our new, no-cost sandbox environments.
    • Explore Developer Sandbox

    Featured Developer Sandbox activities

    • Get started with your Developer Sandbox
    • OpenShift virtualization and application modernization using the Developer Sandbox
    • Explore all Developer Sandbox activities

    Ready to start developing apps?

    • Try at no cost
  • Blog
  • Events
  • Videos

A step-by-step tutorial for continuous integration with Jenkins on a Red Hat Mobile Native Android application: Part 2

August 11, 2016
Juana Nakfour
Related topics:
Java
Related products:
Red Hat build of Node.js

Share:

    In part one of our series, we established the process around creating an Android application using Red Hat’s Mobile Application Platform and adding unit tests. Now, we’ll walk through how to use Jenkins for continuous integration on this app.

    Pre-requisites for this tutorial

    1. RHMAP Instances
    2. Jenkins installed on Fedora
    3. Android Studio setup on a development machine.

    The following are the topics covered in today’s post:

    1. Setup Jenkins to run Android Unit Test
    2. Install Jenkins plugins
    3. Install Android SDK and Tools
    4. Setup SSH on RHMAP and Jenkins
    5. Create an Android Emulator from command line
    6. Create a Jenkins project to run Android Unit Tests

    Setup Jenkins to run Android Unit Test

    This tutorial assumes Jenkins and git tools are installed on a Fedora machine.

    Install Jenkins plugins

    We need to install all the plugins needed to run Android build. From the Jenkins portal go to Manage Jenkins → Manage plugins→ Available and select the following

    1. Android Emulator Plugin
    2. Git plugin
    3. Gradle Plugin

    Click Install without restart.

    Install Android SDK and Tools

    The first step is to download and install the android sdk and tools. Follow these steps:

    1. cd /opt
    2. wget http://dl.google.com/android/android-sdk_r24.4.1-linux.tgz
    3. tar zxvf android-sdk_r24.4.1-linux.tgz
    4. rm android-sdk_r24.4.1-linux.tgz

    Now that the android sdk installed, we need to setup the environment variables to point to the sdk. In a terminal either enter

    1. export ANDROID_HOME="/opt/android-sdk-linux"
    2. export PATH="$ANDROID_HOME/tools:$ANDROID_HOME/platform-tools:$PATH"

    Or depending on your terminal shell type you can edit /etc/profile.d/android.sh and add in the above commands.

    Next we need to run commands to install different android tools:

    1. Update the android sdk and accept agreements
      1. android update sdk --no-ui
    2. Install the Android SDK build-tools
      1. Find the item number
        1. android list sdk --all
        2. Look for a matching version xx.xx.xx to your build.gradle file
      2. Install the right version build tools

         

        1. android update sdk -u --all --filter <#item number >
    3. Repeat the same process to install the correct Android SDK, by matching the SDK number in gradle.build in compileSdkVersion
    4. Give Jenkins access to the sdk
      1. sudo chmod -R 755 /opt/android-sdk-linux
    5. We also need to setup Jenkins to point to the sdk. From the jenkins web portal Manage Jenkins→ Configure system→ Android sdk root→ type in /opt/android-sdk-linux and select “Automatically install Android components when required”
    6. Add a specific gradle version to Jenkins configuration
        1. Gradle plugin in Jenkins is not enough, you must also go to:
        2. Jenkins→ Manage Jenkins→ Configure Jenkins→ Configure system.
        3. Under “Gradle Installations” type in name (it appears as version in project configuration), check “Install automatically” and select version. Then you can select that “Gradle version” in project configuration.
    7. If your fedora machine is running on a 64 bit machine you need to install 32bit libraries
      1. yum install libstdc++.i686
      2. yum install zlib.i686
    8. Install JDK and set JAVA_HOME
      1. yum install java-1.8.0-openjdk-devel
      2. export JAVA_HOME=/usr/lib/jvm/jre-1.8.0-openjdk-1.8.0.91-0.b14.el7_2.x86_64/

    Setup SSH on RHMAP and Jenkins

    For Jenkins to be able to perform a git clone of our RHMAP application we need to create and upload the SSH public key to RHMAP. In a terminal on your Fedora machine generate a new key using ssh-keygen and when asked enter/var/lib/jenkins/.ssh/<anyname> as the location of the keys. Now that the keys are generated we need to make sure they are owned by Jenkins and not the user we are logged into Fedora.

    Run the following command:

    chown Jenkins /var/lib/jenkins/.ssh/<anyname>.*

    Now that we have keys generated, log into RHMAP instance and go to admin→ users →Create and create a new user ID = jenkins with a valid password an email address. Give user Jenkins the right access to read any projects needed

    Then logout and login as “Jenkins” user and upload the public key in Settings→ SSH Key Management→ Add New Key. At this point we have SSH git access setup on RHMAP portal but we still need to create an SSH profile in Jenkins. From the Jenkins portal go to Jenkins→ Credentials→ Global Credentials→ Add Credential→ Fill in the form as seen below

    Create an Android Emulator from command line

    On your fedora machine we need to create an android emulator that can be used by Jenkins. In a terminal run

    1. List the available targets
      1. android list target
    2. Create an avd for one of the targets, this command choses id=17 for abi armeabi-v7a
      1. android create avd -n android-23-emulator -t 17 --abi default/armeabi-v7a

    Create a Jenkins project to run Android Unit Tests

    Time to create a new Jenkins project that can build and run Android tests. From the Jenkins portal click New Item→ Freestyle project and fill in the fields as shown below

    1. Set Git to use jenkins credentials
    2. Use Gradle Wrapper with Tasks clean, assemble, test, connectedAndroidTest
    3. Install APK file
    4. Archive artifacts
    5. Publish JUnit test result reports for both Android unit test and Instrumented unit tests

    Save configuration and Build Now. If the build succeeds from the Status page you should be able to see your artifacts and test results.

     

     

     

     

    Last updated: October 31, 2023

    Recent Posts

    • Storage considerations for OpenShift Virtualization

    • Upgrade from OpenShift Service Mesh 2.6 to 3.0 with Kiali

    • EE Builder with Ansible Automation Platform on OpenShift

    • How to debug confidential containers securely

    • Announcing self-service access to Red Hat Enterprise Linux for Business Developers

    Red Hat Developers logo LinkedIn YouTube Twitter Facebook

    Products

    • Red Hat Enterprise Linux
    • Red Hat OpenShift
    • Red Hat Ansible Automation Platform

    Build

    • Developer Sandbox
    • Developer Tools
    • Interactive Tutorials
    • API Catalog

    Quicklinks

    • Learning Resources
    • E-books
    • Cheat Sheets
    • Blog
    • Events
    • Newsletter

    Communicate

    • About us
    • Contact sales
    • Find a partner
    • Report a website issue
    • Site Status Dashboard
    • Report a security problem

    RED HAT DEVELOPER

    Build here. Go anywhere.

    We serve the builders. The problem solvers who create careers with code.

    Join us if you’re a developer, software engineer, web designer, front-end designer, UX designer, computer scientist, architect, tester, product manager, project manager or team lead.

    Sign me up

    Red Hat legal and privacy links

    • About Red Hat
    • Jobs
    • Events
    • Locations
    • Contact Red Hat
    • Red Hat Blog
    • Inclusion at Red Hat
    • Cool Stuff Store
    • Red Hat Summit
    © 2025 Red Hat

    Red Hat legal and privacy links

    • Privacy statement
    • Terms of use
    • All policies and guidelines
    • Digital accessibility

    Report a website issue