Skip to content

Instantly share code, notes, and snippets.

@BoD
Last active October 27, 2020 13:25
Show Gist options
  • Star 7 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save BoD/17ddffed2c66548014a7a4897c9bbfa5 to your computer and use it in GitHub Desktop.
Save BoD/17ddffed2c66548014a7a4897c9bbfa5 to your computer and use it in GitHub Desktop.
Travis build file for Android: the whole file
language: java
dist: trusty
jdk: oraclejdk8
before_cache:
# Do not cache a few Gradle files/directories (see https://docs.travis-ci.com/user/languages/java/#Caching)
- rm -f $HOME/.gradle/caches/modules-2/modules-2.lock
- rm -fr $HOME/.gradle/caches/*/plugin-resolution/
cache:
directories:
# Android SDK
- $HOME/android-cmdline-tools
- $HOME/android-sdk
# Gradle dependencies
- $HOME/.gradle/caches/
- $HOME/.gradle/wrapper/
# Android build cache (see http://tools.android.com/tech-docs/build-cache)
- $HOME/.android/build-cache
install:
# Download and unzip the Android command line tools (if not already there thanks to the cache mechanism)
# Latest version of this file available here: https://developer.android.com/studio/#command-tools
- if test ! -e $HOME/android-cmdline-tools/cmdline-tools.zip ; then curl https://dl.google.com/android/repository/commandlinetools-linux-6609375_latest.zip > $HOME/android-cmdline-tools/cmdline-tools.zip ; fi
- unzip -qq -n $HOME/android-cmdline-tools/cmdline-tools.zip -d $HOME/android-cmdline-tools
# Install or update Android SDK components (will not do anything if already up to date thanks to the cache mechanism)
- echo y | $HOME/android-cmdline-tools/tools/bin/sdkmanager --sdk_root=$HOME/android-sdk 'platform-tools' > /dev/null
# Latest version of build-tools available here: https://developer.android.com/studio/releases/build-tools.html
- echo y | $HOME/android-cmdline-tools/tools/bin/sdkmanager --sdk_root=$HOME/android-sdk 'build-tools;29.0.3' > /dev/null
- echo y | $HOME/android-cmdline-tools/tools/bin/sdkmanager --sdk_root=$HOME/android-sdk 'platforms;android-29' > /dev/null
env:
- ANDROID_HOME=$HOME/android-sdk
script: ./gradlew --no-daemon --parallel lintDebug testDebug
@jzeferino
Copy link

@BoD Very good approach. I want to know, how do you invalidate/clear the cache, when for example there is a new version of build tools.

@BoD
Copy link
Author

BoD commented Sep 30, 2017

@jzferino Well the build tools are always updated (for each build), line 31. But if you need to invalidate the cache for any reason, there is a UI to do that in the Travis interface (on the upper right, More options / Caches).

@rraallvv
Copy link

@BoD Nice!
It'd be great to have also the NDK included.
Thanks for sharing.

@JSpiner
Copy link

JSpiner commented Dec 11, 2018

Is it possible to run the emulator using this script?

I tried... but it looks can't detect device connect.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment