Build an Android Project
This guide covers build environment and configuration topics specific to Android projects. Please make sure to read our Onboarding and General Build configuration guides first.
Android builds are not available on the macOS environment.
CI Environment for Android Projects #
Overview #
Android builds are officially supported only on our Trusty Build environment at this time; hence, you’ll need to explicitly specify
dist: trusty
in your .travis.yml file.
Travis CI environment provides a large set of build tools for JVM languages with multiple JDKs, Ant, Gradle, Maven, sbt and Leiningen.
By setting
in your .travis.yml
file, your project will be built in the Android environment which provides Android SDK Tools 25.2.3.
Here is an example .travis.yml
for an Android project:
Install Android SDK Components #
In your .travis.yml
, you can define the list of SDK components to be installed, as illustrated in the following example:
The exact component names must be specified (filter aliases like add-on
or extra
are also accepted). To get a list of available exact component names and descriptions run the command sdkmanager --list
(preferably in your local development machine).
Deal with Licenses #
By default, Travis CI will accept all the requested licenses, but it is also possible to define a white list of licenses to be accepted, as shown in the following example:
For more flexibility, the licenses can also be referenced with regular expressions (using Tcl syntax as expect
command is used to automatically respond to the interactive prompts).
Pre-installed Components #
While the following components are preinstalled, the exact list may change without prior notice. To ensure the stability of your build environment, we recommend that you explicitly specify the required components for your project.
- tools
- platform-tools
- build-tools-25.0.2
- android-25
- extra-google-google_play_services
- extra-google-m2repository
- extra-android-m2repository
Create and Start an Emulator #
Warning: At the moment, these steps are not fully supported by Travis CI Android builder.
If you feel adventurous, you may use the script /usr/local/bin/android-wait-for-emulator
and adapt your .travis.yml
to make this emulator available for your tests. For example:
Dependency Management #
Travis CI Android builder assumes that your project is built with a JVM build tool like Maven or Gradle that will automatically pull down project dependencies before running tests without any effort on your side.
If your project is built with Ant or any other build tool that does not automatically handle dependencies, you need to specify the exact command to run using install:
key in your .travis.yml
, for example:
Default Test Command for Maven #
If your project has pom.xml
file in the repository root but no build.gradle
, Maven 3 will be used to build it. By default it will use
to run your test suite. This can be overridden as described in the general build configuration guide.
Default Test Command for Gradle #
If your project has build.gradle
file in the repository root, Gradle will be used to build it. By default it will use
to run your test suite. If your project also includes the gradlew
wrapper script in the repository root, Travis Android builder will try to use it instead. The default command will become:
This can be overridden as described in the general build configuration guide.
Caching #
A peculiarity of dependency caching in Gradle means that to avoid uploading the cache after every build you need to add the following lines to your .travis.yml
:
Default Test Command #
If Travis CI cannot detect Maven or Gradle files, Travis CI Android builder will try to use Ant to build your project. By default, it will use
to run your test suite. This can be overridden as described in the general build configuration guide.
Test against Multiple JDKs #
As for any JVM language, it is also possible to test against multiple JDKs.
Build Matrix #
For Android projects, env
and jdk
can be given as arrays to construct a build matrix.
Build Android projects on new build environments #
The dist: trusty
build environment is the only supported build environment for Android but if you would like to build on newer build environments e.g. dist: jammy
, you can exercise your access to the Travis CI build environments and install required packages and tools. An example .travis.yml config can be reviewed below:
Examples #
- roboguice/roboguice (Google Guide on Android)
- ruboto/ruboto (A platform for developing apps using JRuby on Android)
- RxJava in Android Example Project
- Gradle Example Project
- Maven Example Project
- Ionic Cordova Example Project
Build Config Reference #
You can find more information on the build config format for Android in our Travis CI Build Config Reference.