在Travis CI中缓存Android SDK

菜鸟

我没有几个可以在其中设置Travis CI的开源库。它们运行正常,除了需要25分钟以上的时间来检查构建。大多数时间都浪费在下载依赖项和Android SDK平台上。

我的.travis.yml中目前包含以下内容

language: android
jdk:
  - oraclejdk8
before_install:
- chmod +x gradlew
env:
  global:
   - ANDROID_API_LEVEL=24
   - EMULATOR_API_LEVEL=21
   - ANDROID_BUILD_TOOLS_VERSION=24.0.1
   - ANDROID_ABI=google_apis/armeabi-v7a
   - ADB_INSTALL_TIMEOUT=20 # minutes (2 minutes by default)

android:
  components:
    - tools
    - tools
    - platform-tools
    - build-tools-$ANDROID_BUILD_TOOLS_VERSION
    - android-$ANDROID_API_LEVEL
    - android-$EMULATOR_API_LEVEL
    - extra
    - add-on
    - extra-google-m2repository
    - extra-android-m2repository
    # Google Play Services
    - extra-google-google_play_services
    # Support library
    - extra-android-support

    - addon-google_apis-google-$ANDROID_API_LEVEL
    - addon-google_apis-google-$EMULATOR_API_LEVEL

    - sys-img-armeabi-v7a-addon-google_apis-google-$ANDROID_API_LEVEL
    - sys-img-armeabi-v7a-addon-google_apis-google-$EMULATOR_API_LEVEL

before_cache:
  - rm -f $HOME/.gradle/caches/modules-2/modules-2.lock
cache:
  directories:
    - $HOME/.gradle/wrapper
    - $HOME/.gradle/native
    - $HOME/.gradle/daemon
    - $HOME/.gradle/caches/jars-1
    - $HOME/.gradle/caches/2.3

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 &

script:
  - gradle clean check

如您所见,我已经缓存了一些gradle目录,但是仍然没有缓存Android SDK平台。我确定我缺少一些仍需要缓存的目录。

有什么办法可以通过缓存那些SDK平台和依赖项来加快构建速度?

阿尔贝德鲁

不建议您缓存SDK工具,但是有可能,我以前做过,我将搜索一个示例

同时,请删除这些不必要的行以加快速度并告诉我是否可行。

    - extra
    - add-on
    # Google Play Services
    - extra-google-google_play_services
    # Support library
    - extra-android-support
    - addon-google_apis-google-$ANDROID_API_LEVEL
    - sys-img-armeabi-v7a-addon-google_apis-google-$ANDROID_API_LEVEL

您只需要安装存储库,一个仿真器和特定组件,而不需要像这样的列表:

- add-on
- extra


Installing Archives:
  Preparing to install archives
  Downloading GPU Debugging tools, revision 1.0.3
  Installing GPU Debugging tools, revision 1.0.3
    Installed GPU Debugging tools, revision 1.0.3
  Downloading Android Support Repository, revision 29
  Installing Android Support Repository, revision 29
    Installed Android Support Repository, revision 29
  Downloading Android Support Library, revision 23.2.1
  Installing Android Support Library, revision 23.2.1
    Installed Android Support Library, revision 23.2.1
  Downloading Google AdMob Ads SDK, revision 11 (Obsolete)
  Installing Google AdMob Ads SDK, revision 11 (Obsolete)
    Installed Google AdMob Ads SDK, revision 11 (Obsolete)
  Downloading Google Analytics App Tracking SDK, revision 3 (Obsolete)
  Installing Google Analytics App Tracking SDK, revision 3 (Obsolete)
    Installed Google Analytics App Tracking SDK, revision 3 (Obsolete)
  Downloading Android Auto Desktop Head Unit emulator, revision 1.1
  Installing Android Auto Desktop Head Unit emulator, revision 1.1
    Installed Android Auto Desktop Head Unit emulator, revision 1.1
  Downloading Google Cloud Messaging for Android Library, revision 3 (Obsolete)
  Installing Google Cloud Messaging for Android Library, revision 3 (Obsolete)
    Installed Google Cloud Messaging for Android Library, revision 3 (Obsolete)
  Downloading Google Play services for Froyo, revision 12 (Obsolete)
  Installing Google Play services for Froyo, revision 12 (Obsolete)
    Installed Google Play services for Froyo, revision 12 (Obsolete)
  Downloading Google Play services, revision 29
  Installing Google Play services, revision 29
    Installed Google Play services, revision 29
  Downloading Google Repository, revision 25
  Installing Google Repository, revision 25
    Installed Google Repository, revision 25
  Downloading Google Play APK Expansion library, revision 1
  Installing Google Play APK Expansion library, revision 1
    Installed Google Play APK Expansion library, revision 1
  Downloading Google Play Licensing Library, revision 1
  Installing Google Play Licensing Library, revision 1
    Installed Google Play Licensing Library, revision 1
  Downloading Google Play Billing Library, revision 5
  Installing Google Play Billing Library, revision 5
    Installed Google Play Billing Library, revision 5
  Downloading Android Auto API Simulators, revision 1
  Installing Android Auto API Simulators, revision 1
    Installed Android Auto API Simulators, revision 1
  Downloading Google Web Driver, revision 2
  Installing Google Web Driver, revision 2
    Installed Google Web Driver, revision 2
  Done. 15 packages installed.

November 19, 2013
Do you accept the license 'google-gdk-license-35dc2951' [y/n]: y
Installing Archives:
  Preparing to install archives
  Downloading Google APIs, Android API 23, revision 1
  Installing Google APIs, Android API 23, revision 1
    Installed Google APIs, Android API 23, revision 1
  Downloading Google APIs, Android API 21, revision 1
  Installing Google APIs, Android API 21, revision 1
    Installed Google APIs, Android API 21, revision 1
  Downloading Google APIs (x86 System Image), Android API 19, revision 18
  Installing Google APIs (x86 System Image), Android API 19, revision 18
    Installed Google APIs (x86 System Image), Android API 19, revision 18
  Downloading Google APIs, Android API 19, revision 18
  Installing Google APIs, Android API 19, revision 18
    Installed Google APIs, Android API 19, revision 18
  Downloading Glass Development Kit Preview, Android API 19, revision 11
  Installing Glass Development Kit Preview, Android API 19, revision 11
    Installed Glass Development Kit Preview, Android API 19, revision 11
  Downloading Google APIs, Android API 18, revision 4
  Installing Google APIs, Android API 18, revision 4
    Installed Google APIs, Android API 18, revision 4
  Downloading Google APIs, Android API 17, revision 4
  Installing Google APIs, Android API 17, revision 4
    Installed Google APIs, Android API 17, revision 4
  Downloading Google APIs, Android API 16, revision 4
  Installing Google APIs, Android API 16, revision 4
    Installed Google APIs, Android API 16, revision 4
  Downloading Google APIs, Android API 15, revision 3
  Installing Google APIs, Android API 15, revision 3
    Installed Google APIs, Android API 15, revision 3
  Downloading Google APIs, Android API 10, revision 2 (Obsolete)
  Installing Google APIs, Android API 10, revision 2 (Obsolete)
    Installed Google APIs, Android API 10, revision 2 (Obsolete)

更新:我找到了这个构建,其中使用如下自定义路径来缓存SDK工具的额外内容:

cache:
  apt: true
  directories:
    - ${TRAVIS_BUILD_DIR}/gradle/caches/
    - ${TRAVIS_BUILD_DIR}/gradle/wrapper/dists/
    - ${TRAVIS_BUILD_DIR}/android-sdk/extras/

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:
  - echo "WARNING delete this when fixed"; export OLD_SDK=/usr/local/android-sdk-23.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 || echo "CP ERROR"

您无需这样做,直接将存储库所在的默认路径保存到缓存中:

/usr/local/android-sdk/extras

不想保存完整的sdk工具来缓存包括所有系统映像。

缓存的目的是使安装特定于语言的依赖关系变得轻松快捷,因此与工具(如Bundler,pip,Composer,npm,Gradle,Maven)相关的所有内容都应放入缓存中。

快速安装但下载缓慢的大型文件无法从缓存中受益,因为它们从缓存中下载所需的时间与从原始源中下载所需的时间一样长:

  • Android SDK
  • Debian软件包
  • JDK套件
  • 编译的二进制文件

默认环境变量

TRAVIS_BUILD_DIR:已在工作服务器上复制了要构建存储库的目录的绝对路径。

本文收集自互联网,转载请注明来源。

如有侵权,请联系 [email protected] 删除。

编辑于
0

我来说两句

0 条评论
登录 后参与评论

相关文章