Travis CI — A beginner tutorial
Published in
3 min readMar 20, 2018
If you have ever contributed to open source , You must have seen few things.
- Build passes
- 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!
- sudo requirement is added because a license needs to be manually added later.
- In line 2 & 3 , we’re specifying that project will be built in the Android environment & use jdk8.
- In line 6–10 , it is the list of Android SDK components to be installed.
- In line 11–12 , executable permission is provided to
gradlew
- In line 13–14, it is the
gradle build
command along withstacktrace
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 addconnectedCheck
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 ❤