4

我们正在尝试为我们的 Androidbuild作业缓存所有 Gradle 依赖项。

这是当前失败的方法:

- restore_cache:
    key: android-build-{{ checksum "android/build.gradle" }}-{{ checksum  "android/app/build.gradle" }}
- save_cache:
    paths:
      - ~/.gradle
    key: android-build-{{ checksum "android/build.gradle" }}-{{ checksum  "android/app/build.gradle" }}
4

2 回答 2

1

restore_cache在和之间放置构建步骤save_cache

如果您的项目是多模块/级散列所有构建脚本并将其用作正确捕获依赖项的关键:

  - run:
      name: Hash dependency info
      command: |
        mkdir -p build
        md5sum gradle.properties settings.gradle build.gradle **/build.gradle >build/deps.md5
  - restore_cache:
      key: gradle-{{ checksum "build/deps.md5" }}
  - run:
      name: Build and deploy
      command: >
        bash ./gradlew
        build artifactoryPublish
  - save_cache:
      key: gradle-{{ checksum "build/deps.md5" }}
      paths:
        - ~/.gradle/caches
        - ~/.gradle/wrapper
于 2018-08-12T06:35:16.570 回答
1

这里有一个由 Circle CI 自己编写的示例 Android 配置以及属性的逐步演练。

version: 2
jobs:
  build:
    working_directory: ~/code
    docker:
      - image: circleci/android:api-25-alpha
    environment:
      JVM_OPTS: -Xmx3200m
    steps:
      - checkout
      - restore_cache:
          key: jars-{{ checksum "build.gradle" }}-{{ checksum  "app/build.gradle" }}
#      - run:
#         name: Chmod permissions #if permission for Gradlew Dependencies fail, use this. 
#         command: sudo chmod +x ./gradlew
      - run:
          name: Download Dependencies
          command: ./gradlew androidDependencies
      - save_cache:
          paths:
            - ~/.gradle
          key: jars-{{ checksum "build.gradle" }}-{{ checksum  "app/build.gradle" }}
      - run:
          name: Run Tests
          command: ./gradlew lint test
      - store_artifacts:
          path: app/build/reports
          destination: reports
      - store_test_results:
          path: app/build/test-results

值得注意的是,由于子模块,我们在使用缓存时遇到了一些问题,但上述内容应该适用于更简单的存储库。

于 2018-03-28T14:39:10.417 回答