9

I found out that each time Travis CI build the project, it has to download again all the SDK packages like the platform-tools, the support library, the current SDK, etc.

Is it possible to avoid it and make Travis reuse what it downloaded the first time ?

I probably made some mistakes in my .travis.yml file, here is a copy of it

language: android
android:
  components:
    # Uncomment the lines below if you want to
    # use the latest revision of Android SDK Tools
    - platform-tools
    - tools

    # The BuildTools version used by your project
    - build-tools-23.0.2

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

    # Additional components
    - extra-android-support
    - extra-google-google_play_services
    - extra-google-m2repository
    - extra-android-m2repository
    - addon-google_apis-google-19

    # Specify at least one system image,
    # if you need to run emulator(s) during your tests
    # - sys-img-armeabi-v7a-android-19
    # - sys-img-x86-android-17

script:
  - ./gradlew check
  - ./gradlew test --continue
  # - ./gradlew build connectedCheck
Antoine
  • 583
  • 2
  • 6
  • 21

1 Answers1

0

Why do Travis CI download everything each time it builds?

We talk about this here, Travis-ci downloads the cache from S3, so there is not a significant speed improvement caching big files like Android SDK.

How to include Android SDK in Travis-ci cache? (not recommended)

The relevant bits are here, you can add to the cache any file you like and know his path:

cache:
  directories:
    - ${TRAVIS_BUILD_DIR}/gradle/caches/
    - ${TRAVIS_BUILD_DIR}/gradle/wrapper/dists/
    - ${TRAVIS_BUILD_DIR}/android-sdk/extras/ # please don't include sys-images

I did it time ago, you can see the code in the link shared by @nicolas-f:

language: android
jdk: oraclejdk8
env:
  global:
    - GRADLE_USER_HOME=${TRAVIS_BUILD_DIR}/gradle
    - ANDROID_HOME=${TRAVIS_BUILD_DIR}/android-sdk
    - SDK=${TRAVIS_BUILD_DIR}/android-sdk
    - PATH=${GRADLE_USER_HOME}/bin/:${SDK}/:${SDK}/tools/:${SDK}/platform-tools/:${PATH}
before_install:
  - export OLD_SDK=/usr/local/android-sdk-24.0.2;
                                           mkdir -p ${SDK};
                                           cp -u -R ${OLD_SDK}/platforms ${SDK}/platforms;
                                           cp -u -R ${OLD_SDK}/system-images ${SDK}/system-images;
                                           cp -u -R ${OLD_SDK}/tools ${SDK}/tools

cache:
  apt: true
  directories:
    - ${TRAVIS_BUILD_DIR}/gradle/caches/
    - ${TRAVIS_BUILD_DIR}/gradle/wrapper/dists/
    - ${TRAVIS_BUILD_DIR}/android-sdk/extras/
android:
  components:
     # Update Android SDK Tools
    - tools
    - platform-tools
    - build-tools-23.0.2
    - android-23    
    - add-on
    - extra

script:
   - ./gradlew check

Use ls to confirm that the SDK path has not changed another time.

It's not currently necessary to move the SDK, and you need to update other things, perhaps add another tools after platform-tools, this code is outdated.

Community
  • 1
  • 1
albodelu
  • 7,931
  • 7
  • 41
  • 84
  • Thanks for the answer. Can you please explain more? So from your code it seems that `/usr/local/android-sdk-24.0.2` or the absolute path to SDK with always exists. And you are copying form there to the SDK position for which travis ci looks for? However you say that it is now not necessary to copy the SDK. So, how can we prevent travis ci from downloading the SDK again? Also I read on the issue that each time it starts a fresh new docker container, that's why it needs to re-download everything. So is there a way around it? Thanks! – Shobhit Puri May 04 '17 at 22:45
  • Ignore the outdated example, The relevant bits are here, you can add to the cache any file you like and know his path: `cache:` `directories:` `- /usr/local/android-sdk-24.0.2;` like [here](https://github.com/connectbot/connectbot/blob/master/.travis.yml#L13) but it's not recommended because adding system images to the cache is overkill. – albodelu May 05 '17 at 00:05