How to Cache Gradle and CocoaPods in CI
Cache ~/.gradle/caches keyed on Gradle files and the Pods directory keyed on Podfile.lock to cut cold-build time.
Use actions/cache with keys derived from *.gradle* and Podfile.lock. A stable key means unchanged dependencies restore instantly instead of downloading again.
Steps
- Cache
~/.gradle/cachesand~/.gradle/wrapperkeyed on Gradle files. - Cache the
ios/Podsdirectory keyed onPodfile.lock. - Add
restore-keysso a near-miss still gives a partial hit.
Workflow
.github/workflows/ci.yml
- uses: actions/cache@v4
with:
path: |
~/.gradle/caches
~/.gradle/wrapper
key: gradle-${{ hashFiles('**/*.gradle*', '**/gradle-wrapper.properties') }}
restore-keys: gradle-
- uses: actions/cache@v4
with:
path: ios/Pods
key: pods-${{ hashFiles('ios/Podfile.lock') }}
restore-keys: pods-Gotchas
- Cache the resolved Pods, but still run
pod installso the workspace references are correct. - Do not cache build outputs you need fresh; cache only the dependency stores.
Related guides
How to Build an Android APK or AAB in CIBuild a release Android APK or app bundle in CI by running gradlew assembleRelease or bundleRelease on a JDK-…
How to Build a React Native App in CI (Android and iOS)Build a bare React Native app in CI for Android and iOS by installing npm dependencies and CocoaPods, then ru…