Vikas Goyal

Five Step Guide to Create Android Project Job in Jenkins

Jenkins and Android

In my previous blog, I have defined how you can configure Jenkins for various platforms. There we configured the Android SDK in Jenkins Server. Now in this blog, I am going to explain how can we create jobs for Android project and build APK for that in just one single click.

As we know the core purpose of Jenkins is to implement continuous integration. In an Agile project, we need to build and test continuously. Therefore, we keep integrating development task in our version control repo after verifying necessary steps and then move to the next phase. In the verification process, Jenkins generates an automated build which also includes the test cases.

So now let’s talk about creating a Job and building APK for Android project in Jenkins Server-

1. Create a Job

On Jenkins server dashboard, you will find a New Item option on the top left like in attached screen.

Create a Job

Click on the NewItem and you will be redirected to a new page. Here you’ll see enter an item name. Enter the job name you want to keep for android project.

After that select a project type for android, it will work with Freestyle project as in provided screenshot.

Freestyle project

If you want to use an existing job configuration, then you can easily search and add it in the Copy From field.

Copy From Field

Hit OK and you will be redirected to job configuration page.

2. Source Code Management

It is the most important section while setting up a job. Here you can define the project version control repository with its credentials. First, you need to select version control repository like CVS or Git(add plugins for others if required). Let’s take an example of Git repository here.

Now you need to provide Repository URL as shown in the example here. After that, select GitHub Credentials or add a new one if not available.

Source Code Management

Once the repository is added, define branch in Branch Specifier or leave it blank if only the master is required.

Advanced checkout behavior can be configured to provide a timeout for checkout operation which defines for how long Jenkins server should keep trying to pull from Git repo. For instance, if code size is huge and relatively default timeout less, build might fail. So it is advisable to define a suitable & large number depending on server network bandwidth and repository size.

Advanced checkout behavior

Advanced clone behavior is same as Advanced checkout behavior and applicable for future clone and fetches behavior.

3. Build

In this section, you can provide configuration related to generating build for the Android Project. The useful actions in build section are defined below.
In Invoke Gradle Script, Use Gradle Wrapper as it will accept ./gradlew commands. Apart from this, check From Root Build Script Dir if you want to start the execution from the root of the project directory.
Tick Make gradlew executable as it is useful on some OS when you face permission issue. I faced this on Ubuntu as the file is not executable. So it throws the permission error. Its better if you keep this option marked.

Invoke Gradle Script

In the above screenshot, as you can see Tasks option is available for providing Gradle commands. For example-
a) For debugging APK, provide clean build.
b) For release APK, provide clean buildRelease.
If ./gradlew is not available in the root of project directory then in Root Build Script you need to provide the ./gradlew location. Like in my case it is available under the zoomvy folder in the root of the project directory.

Dependency Management- As an Android developer, we already know how Gradle works. We don’t need to bother about dependency in an android project as Gradle manages it automatically. For more details on how Gradle works in Android, you can refer here.

4. Post-build Actions

It provides you control to perform actions when your build is created for the project. The most useful option available here is Archive the artifacts. Here you can provide a file which will show on the dashboard of the Android project as an archive. I have marked the generated build file in the current project, you can also put any other file like any log file or something else.

Post Build Actions

Apart from this, if you require performing a further action once the build is succeeded, then you can install the plugins. For example, E-mail Notification is plugin required to send a build over email once it is successful, the tutorial, how to use Email Notification can be found here.

5. Build APK

As the job configuration is finished, now you want to build the job. So click on the job from Jenkins server dashboard and you will see a page like this.

Build APK

In the screen, as you can see Build Now option, click on that and Jenkins will start generating project build. You can also see the progress like this.

Build History

After completion, you can see the build APK file in the archive as we have provided in Post-build Actions. The APK should be available under last successful Artifacts.

Post Build Actions

 

I hope this will be helpful in creating a job for your Android project. In my next blog, I will try to define how you can integrate test suits in Jenkins server and map the code coverage.

If you have any query, please feel free to drop your comments below.

 

Related Articles

#Tech

NHibernate, Linq and Lazy Collections

For the past few months we have been busy building a services framework for one of our clients so that they can build all of their enterprise web services without ever having to worry about the cross cutting concerns and... Read more
#Tech

Page Redirects using Spring.NET

Who is responsible for page redirects in ASPNET MVP – The View or the Presenter None of the above, it is you :) On a serious note, it is the View as one shouldn’t pollute the Presenter with the page navigation... Read more