Travis CI — A beginner tutorial

Anamika Tripathi
MindOrks
Published in
3 min readMar 20, 2018

If you have ever contributed to open source , You must have seen few things.

  1. Build passes
  2. Travis failed

Have you ever tried to know the reason behind these messages ? If answer is NO , you’re definitely reading the right post!

Understanding the Travis.yml file

Let’s take it step by step!

  1. sudo requirement is added because a license needs to be manually added later.
  2. In line 2 & 3 , we’re specifying that project will be built in the Android environment & use jdk8.
  3. In line 6–10 , it is the list of Android SDK components to be installed.
  4. In line 11–12 , executable permission is provided to gradlew
  5. In line 13–14, it is the gradle buildcommand along with stacktrace
Yayyy!

Some more detailed configuration

  • To avoid uploading the cache after every build, travis.yml might contain these lines :
before_cache:
- rm -f $HOME/.gradle/caches/modules-2/modules-2.lock
- rm -fr $HOME/.gradle/caches/*/plugin-resolution/
cache:
directories:
- $HOME/.gradle/caches/
- $HOME/.gradle/wrapper/
- $HOME/.android/build-cache
  • Creating an android emulator :
before_script:
- echo no | android create avd --force -n test -t android-21 --abi armeabi-v7a
- emulator -avd test -no-skin -no-audio -no-window &
- android-wait-for-emulator
- adb shell input keyevent 82 &
  • To run instrumentation tests (src/androidTests), we can add connectedCheck in script block.

Understanding the common build error

  • There is always good probability that your PR changes are not valid & gradle build actually fails. To solve it , Re-build your application & then check whether gradle builds successfully.
  • Some organisation might have enabled the travis integration but yml file might be absent & it can give you error.
  • Travis might be overdoing the work & timeout may occur.
  • Include these lines in your gradle file :
lintOptions {
abortOnError false
}

If it’s not present then the build will fail if there is a lint error in the project.

That’s all! Please do clap, comment(reviews or doubts) and Share it :)

May the Code be with you all ❤

--

--

Anamika Tripathi
MindOrks

Android Developer @Zomato | Google Udacity Scholar | GSoC19 Mentor @Mifos | GSoC18 student @systers_org | GCI Mentor | Tech speaker