Continuous Integration using Jenkins for Android

Continuous Integration using Jenkins for Android

Before beginning to this article make sure Jenkins Server is already setup and running. This article covers how to use Jenkins for Build Automation and Deployment over FTP, DropBox for Android projects.

Step 1: Configure Global Variables:

1.1 JAVA : Manage Jenkins → Global Tool Configuration → JDK Installations → Add JDK

1.2 Git : Manage Jenkins → Global Tool Configuration → Git

1.3 Android: Manage Jenkins → Configure System → Global properties → Environment variables -> Add

Step 2: Project Setup and Configurations :

2.1 Jenkins → New Item → Freestyle project

2.2 General

For saving the project repository in different workspace select “use custom workspace” as follows:

This option will be visible after pressing “Advanced” button in General section

2.3 Source Code Management

Add repository URL, select credentials and specify the source branch to pull.

2.4 Build Triggers

2.5 Build

2.5.1 Execute using Gradle script

2.5.2 Execute using shell script

2.6 Post-build Actions

2.6.1 Archive .apk files

2.6.2 Upload .apk to Dropbox folder

2.6.3 Upload .apk to FTP folder

Step 3: Build Progress

Press the Build now button for start the execution of build.

Check the Build progress

Reviewing the console output

Make sure Build is successfully created

Step 4: Troubleshooting

Problem: Execution failed for task ‘:app:mergeDebugResources’.
Solution: disable the build cache for your project, add the following to its gradle.properties file:

android.enableBuildCache=false

Problem: Execution failed for task :app:lintVitalReleaseD:
Solution: Add following lintOptions to build.gradle

android {
buildTypes {
release {
lintOptions {
checkReleaseBuilds false
abortOnError false

}
}
}
}

Problem:
 — Error with gradlew: /usr/bin/env: bash: No such file or directory
 — ./gradlew clean env: bash\r: No such file or directory Build step ‘Execute shell’ marked build as failure

Solution: The problem’s cause was that Git on Windows converted the line endings of gradlew from Unix style (LF) to Windows style (CRLF).
 — https://stackoverflow.com/questions/22301956/error-with-gradlew-usr-bin-env-bash-no-such-file-or-directory
Dwonload: https://sourceforge.net/projects/dos2unix/?source=typ_redirect

In current scenario Jenkins is installed over Mac environment and source is being pushed either from Linux or Windows machine.
Based on development environment convert gradlew.bash using dos2unix utility, push again to git and try executing build again.