Travis CI

If your project's repository is hosted on GitHub, you can use Travis CI for your automated builds. Travis CI (https://travis-ci.org) is an open source hosted continuous integration system, and is free to use for public repositories. There is a paid plan for private repositories, but in this book we will only look at the free option.

Travis detects when a new commit is pushed to the repository and starts a new build automatically. By default, Travis builds all branches, not just the master branch. It also builds pull requests automatically; a useful feature for open source projects.

Because of how Travis works internally, you cannot configure the build server itself. Instead, you need to create a configuration file that contains all the information that Travis needs to build your app or library.

Configuring the build

If you want to enable Travis builds for your project, you first need to log in to Travis CI and connect your account to GitHub. Once that is done, you need to enable the project you want to build in the settings.

In order to configure the build process, Travis requires you to create a file called .travis.yml that contains the entire setup. To configure an Android project, you need to define the language and add a few Android-specific properties:

language: android
android:
  components:
    # The build tools version used by your project
    - build-tools-22.0.1

    # The SDK version used to compile your project
    - android-22

    # Additional components
    - extra-android-m2repository

The language setting specifies which kind of build process you want to run. In this case, you are building an Android app. The Android-specific properties include the version of the build tools and the Android SDK version that need to be used. Travis will download those prior to running the build tasks. If you make use of the support library or Google Play Services, you need to specify that explicitly because Travis needs to download the repositories for those dependencies as well.

Note

It is not mandatory to configure the build tools and SDK version, but you will encounter fewer issues if you make sure the version aligns with what you have specified in the build.gradle file.

If you create an Android project on Microsoft Windows, the Gradle Wrapper file is known to have issues with permissions. Therefore, it is a good idea to fix the permission before running the actual build script. You can add a prebuild step like this:

before_script:
  # Change Gradle wrapper permissions
  - chmod +x gradlew

To start the build itself, add this line to the Travis configuration file:

# Let's build
script: ./gradlew clean build

This command will run the Gradle Wrapper, just like you would on a developer machine, and execute the clean and build tasks.

When you are done configuring the Travis build, you can commit and push the file to the project's GitHub repository. If everything is set up correctly, Travis will start the build process, which you can follow on the Travis website. This is what it looks like when a project is successfully built:

Configuring the build

Travis also sends an e-mail report after every build. This can be especially useful if you are the maintainer of an open source library that regularly gets pull requests. The report e-mail from Travis looks like this when a build is successful:

Configuring the build

You will quickly notice that Travis has a big downside, and that is speed. Travis does not give you one specific machine, but boots up a vanilla virtual machine for every build you trigger. This means for every new build, Travis has to download and install the Android SDK and build tools, before it can start building your app or library.

On the upside, Travis is free and public, which makes it perfect for open source projects. Travis also builds pull requests automatically, which can give you peace of mind when someone submits a patch to your code.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
18.191.62.122