#Rocketmade Jenkins CI Setup Guide for Android
Distributing builds for Android will rely on the Crashlytics framework.
##1. Add the Fabric Maven repo, and the Fabric gradle to the classpath
build.gradle
buildscript {
repositories {
maven { url 'https://maven.fabric.io/public' }
}
dependencies {
classpath 'io.fabric.tools:gradle:1.+'
}
}
##2. Add the Fabric plugin AFTER the com.android.application plugin
build.gradle
apply plugin: 'com.android.application'
apply plugin: 'io.fabric'
##3. Add the Fabric Maven repository below the apply plugin command
build.gradle
repositories {
maven { url 'https://maven.fabric.io/public' }
}
##4. Add the release notes, and the name of the distribution group to buildTypes
or productFlavors
build.gradle
def releaseNotes = 'git log --pretty=format:"%s" --since "yesterday"'.execute([], project.rootDir).text.trim()
android {
buildTypes {
release {
...
}
debug {
...
}
staging {
debuggable false
applicationIdSuffix ".stg"
versionNameSuffix " Stg"
signingConfig signingConfigs.release
ext.betaDistributionReleaseNotes=releaseNotes
ext.betaDistributionGroupAliases="INSERT DISTRIBUTION GROUP NAME HERE"
}
}
}
##5. Add the Crashlytics sdk to the gradle dependencies
build.gradle
compile('com.crashlytics.sdk.android:crashlytics:+@aar') {
transitive = true;
}
##6. Create a Fabric.properties file in the app/ directory, include the info:
fabric.properties
apiSecret=YOUR_BUILD_SECRET
apiKey=YOUR_API_KEY
AndroidManifest.xml ##7. Include the API key in your AndroidManifest.xml
<meta-data
android:name="io.fabric.ApiKey"
android:value="API_KEY"/>
##8. Start Crashlytics in your Application subclass onCreate
MyApplication.java
private void setupFabric() {
// Set up Crashlytics, disabled for debug builds
Crashlytics crashlyticsKit = new Crashlytics.Builder()
.core(new CrashlyticsCore.Builder().disabled(BuildConfig.DEBUG).build())
.build();
// Initialize Fabric with the debug-disabled crashlytics.
Fabric.with(this, crashlyticsKit);
}
##9. Create a new Jenkins project
-
Log in to the CI server, Click "New Item", and enter the Project name with Freestyle project selected
-
On the next page, enter the Project Name and Description
-
Under the Source Code Management section, select git and enter the repository URL. For example,
[email protected]:organization-name/repo-name.git
-
Under branches to build, enter
**dev
-
If you want to be able to trigger builds from the command line, check the box
Trigger builds remotely
and enter an authentication token of your choosing.
##10. Distribute
Enter the following script into the Execute shell
section:
# These might already be set, but set them to your ANDROID_HOME and JAVA_HOME locations if not
export ANDROID_HOME="/Users/ci/Android/android-sdk-macosx"
export JAVA_HOME=$(/usr/libexec/java_home)
./gradlew clean
./gradlew assembleDebug
./gradlew crashlyticsUploadDistributionDebug
##11. Save the Jenkins project
That's it! The CI server now has everything it needs to build the project.
##12. Trigger CI builds from the command line
Create a file name ci.sh
in your project root. Add the following script:
ci.sh
#!/bin/bash
# Usage: run ./ci.sh to trigger a CI Build.
# Get $JENKINS_USERNAME and $JENKINS_API_TOKEN from environment (store in a .env file and use AutoEnv)
JENKINS_URL="JENKINS_URL/job/PROJECT_NAME/build?token=BUILD_TOKEN" # replace with your URL
curl -u $JENKINS_USERNAME:$JENKINS_API_TOKEN $JENKINS_URL
and add the following to a .env
file in the project root:
.env
export JENKINS_USERNAME="YOUR-USERNAME-GOES-HERE"
export JENKINS_API_TOKEN="YOUR-API-TOKEN-GOES-HERE"
To get JENKINS_API_TOKEN, log into Jenkins, click on your name in the top right corner, click configure
on the left, then click Show API Token..
You can now either run source .env
, or use AutoEnv to automatically source your .env
files when you cd
into your project.
Run ./ci.sh
to remotely trigger a CI build.