Travis is a continuous integration service that enables you to run tests against your latest Android builds. You can setup your projects to run both unit and integration tests, which can also include launching an emulator.
Login to Travis CI and sign-in with your GitHub credentials. You will need to grant access to any repositories that will be used. If you are using a private repository and don't intend for the source code to be shared, you will need to signup for a paid subscription plan.
You simply need to create a .travis.yml
file in the root directory. The simplest configuration to install the Build Tools and Android SDK 24. You can launch the Gradle wrapper to build and run emulator tests. Make sure the tools
line is first to ensure that Build Tools (esp for versions above API 24). It also needs to be included twice.
language: android
android:
components:
- tools # to get the new `repository-11.xml`
- tools # see https://github.com/travis-ci/travis-ci/issues/6040#issuecomment-219367943)
- platform-tools
- build-tools-27.0.3
- android-27
before_install:
- yes | sdkmanager "platforms;android-27"
script:
- ./gradlew build connectedCheck
See the docs here for more information. By default, all SDK license agreements are accepted but you can also dictate which ones to accept.
If you are intending to use the new Design Support Library, you will need to make sure to include the Maven repo in your root build.gradle
file:
repositories {
maven {
url 'https://maven.google.com'
}
}
Because of this change announced in Google I/O 2017, the use of extra-android-m2repository
in travis.yml
is no longer needed:
language: android
android:
components:
- extra-android-m2repository
If you intend to use Google Play Services with Travis, make sure you also use the Maven support library.
To add support for lambda expressions, make sure to specify JDK 8 or higher:
jdk:
- oraclejdk8
If you see an error code 137, chances are that the Travis build has ran out of memory trying to load all your dependencies.
com.android.ide.common.process.ProcessException: org.gradle.process.internal.ExecException: Process 'command '/usr/lib/jvm/java-7-oracle/bin/java'' finished with non-zero exit value 137
Here are a few ways to try to resolve:
com.google.android.gms:play-services:8.3.0
. Instead, you can simply specify the libraries explicitly:implementation 'com.google.android.gms:play-services-gcm:8.3.0'
.dex
file. The problem is that this process is more memory intensive and takes longer and provides benefits only when doing incremental builds. See this section for more information.To disable pre-dexing, add this line to your root build.gradle
to detect whether Travis is currently running:
ext {
travisBuild = System.getenv("TRAVIS") == "true"
// allows for -Dpre-dex=false to be set
preDexEnabled = "true".equals(System.getProperty("pre-dex", "true"))
}
Then add this line to your app/build.gradle
:
android {
dexOptions {
// Skip pre-dexing when running on Travis CI or when disabled via -Dpre-dex=false.
preDexLibraries = preDexEnabled && !travisBuild
}
}
sudo: required
after_failure: "cat $TRAVIS_BUILD_DIR/app/build/outputs/lint-results-debug.xml"