-
Notifications
You must be signed in to change notification settings - Fork 6.3k
Setting up Travis CI
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:
-
If you are using Google Play Services, try to be more selective about the modules you import. In prior versions before 6.5, you had to include all packages which often caused the 65K method limit to be reached. If you only wish to use the Google Cloud Messaging package and not Google Fitness or Google Wear, you do not need to import
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'
-
If you are still having issues, you will likely need to disable predexing, which compiles each dependency individually into Android bytecode and turns each module into a
.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 } }
-
Disable container-based builds, which currently only have a maximum of 4GB of memory, whereas standard versions have a max of 7.5GB of memory (according to this doc):
sudo: required
-
If you want to print any lint error issues, add this line:
after_failure: "cat $TRAVIS_BUILD_DIR/app/build/outputs/lint-results-debug.xml"
Created by CodePath with much help from the community. Contributed content licensed under cc-wiki with attribution required. You are free to remix and reuse, as long as you attribute and use a similar license.
Finding these guides helpful?
We need help from the broader community to improve these guides, add new topics and keep the topics up-to-date. See our contribution guidelines here and our topic issues list for great ways to help out.
Check these same guides through our standalone viewer for a better browsing experience and an improved search. Follow us on twitter @codepath for access to more useful Android development resources.