Skip to content

Instantly share code, notes, and snippets.

@GeorgiosGoniotakis
Last active April 15, 2018 12:07
Show Gist options
  • Save GeorgiosGoniotakis/e9824b74a985070f77aff65cf1b7552d to your computer and use it in GitHub Desktop.
Save GeorgiosGoniotakis/e9824b74a985070f77aff65cf1b7552d to your computer and use it in GitHub Desktop.
Example of using Travis CI with Codecov in a multi-module Android project
language: android
jdk: oraclejdk8
before_install:
- mkdir "$ANDROID_HOME/licenses" || true
- echo -e "\n8933bad161af4178b1185d1a37fbf41ea5269c55" > "$ANDROID_HOME/licenses/android-sdk-license"
- echo -e "\n84831b9409646a918e30573bab4c9c91346d8abd" > "$ANDROID_HOME/licenses/android-sdk-preview-license"
script:
- ./gradlew check
- ./gradlew jacocoTestReport
after_success:
- bash <(curl -s https://codecov.io/bash)
android:
components:
- tools
- tools
- platform-tools
- build-tools-25.0.3 #Edit this with your buildToolsVersion
- android-25 #Edit this with your targetSdkVersion
licenses:
- android-sdk-license-.+
- '.+'
To get rid of the "Permission denied" error caused by the execution of the gradlew file, use the following code to update its execution permissions.
>> git update-index --chmod=+x gradlew
>> git ls-tree HEAD
>> git update-index --chmod=+x gradlew
>> git commit -m "permission access for travis"
>> git ls-tree HEAD
//Project's build.gradle file
buildscript {
repositories {
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:2.3.3' // Use your own version of tools here
classpath 'com.dicedmelon.gradle:jacoco-android:0.1.2' // Add this line
// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
}
}
allprojects {
repositories {
jcenter()
}
}
task clean(type: Delete) {
delete rootProject.buildDir
}
//Example of using jacoco with a library (use it respectively)
apply plugin: 'com.android.library'
apply plugin: 'jacoco-android' // Add this line
android {
compileSdkVersion 25
buildToolsVersion "25.0.3"
defaultConfig {
minSdkVersion 19
targetSdkVersion 25
versionCode 1
versionName "1.0"
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
}
buildTypes {
debug{ //Add this debug section
testCoverageEnabled true
}
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
}
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
androidTestCompile('com.android.support.test.espresso:espresso-core:2.2.2', {
exclude group: 'com.android.support', module: 'support-annotations'
})
compile 'com.android.support:appcompat-v7:25.2.0'
testCompile 'junit:junit:4.12'
}
// Finally add this block
jacocoAndroidUnitTestReport {
csv.enabled false
html.enabled true
xml.enabled true
}
To build the solution above:
- Open the terminal in Android Studio
- Navigate to the folder which contains the project's build.gradle file (optional)
- Type "gradlew check jacocoTestReport"
As a result, you will find the reports in the folder YOUR_PROJECT_NAME/YOUR_MODULE_NAME/build/reports/jacoco
By using the .travis.yml file above you can be sure that you will find a report at https://codecov.io (on successful Travis CI build)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment