version: 2
jobs:
  build:
    working_directory: ~/code
    docker:
      - image: circleci/android:api-27-alpha
        environment:
          TZ: Asia/Tokyo
    environment:
      JVM_OPTS: -Xmx3200m
    steps:
      - checkout
      - restore_cache:
          key: jars-{{ checksum "build.gradle" }}-{{ checksum  "android/app/build.gradle" }}
      - run:
          name: Print Android home
          command: echo $ANDROID_HOME
      - run:
          name: Accept licenses
          command: yes | sdkmanager --licenses || true
      - run:
          name: Download Dependencies
          command: cd android && ./gradlew androidDependencies
      - save_cache:
          paths:
            - ~/.gradle
          key: jars-{{ checksum "build.gradle" }}-{{ checksum  "android/app/build.gradle" }}
      - run:
          name: Run Tests
          command: cd android && ./gradlew lint test
      - run:
          name: Create jacoco report
          command: cd android && ./gradlew jacocoTestReport 
      - run:
          name: Publish to codecov
          command: cd android && bash <(curl -s https://codecov.io/bash)
      - store_artifacts:
          path: android/app/build/reports
          destination: reports
      - store_test_results:
          path: android/app/build/test-results


version: 2
jobs:
  build:
    working_directory: ~/code
    docker:
      - image: circleci/android:api-27-alpha
        environment:
          TZ: Asia/Tokyo
    environment:
      JVM_OPTS: -Xmx3200m
    steps:
      - checkout
      - restore_cache:
          key: jars-{{ checksum "build.gradle" }}-{{ checksum  "android/app/build.gradle" }}
      - run:
          name: Print Android home
          command: echo $ANDROID_HOME
      - run:
          name: Accept licenses
          command: yes | sdkmanager --licenses || true
      - run:
          name: Download Dependencies
          command: cd android && ./gradlew androidDependencies
      - run:
          name: Run Tests
          command: cd android && ./gradlew lint test
      - run:
          name: Create jacoco report
          command: cd android && ./gradlew jacocoTestReport 
      - run:
          name: Publish to codecov
          command: cd android && bash <(curl -s https://codecov.io/bash)
      - store_artifacts:
          path: android/app/build/reports
          destination: reports
      - store_test_results:
          path: android/app/build/test-results
      - save_cache:
          paths:
            - ~/.gradle
          key: jars-{{ checksum "build.gradle" }}-{{ checksum  "android/app/build.gradle" }}


Move save cache to the end of the flow
CircleCI: Move save cache to the end of the flow
