How do I optimize build times with caching on Codemagic?

Last updated: June 29, 2026

Context

Build times on Codemagic can be significantly longer than local builds because each build starts on a clean VM that needs to install all dependencies from scratch. A proper caching strategy can help reduce build times by avoiding re-downloading or re-building the same components on every build.

Answer

Caching on Codemagic works by storing files from successful builds for up to 14 days, scoped per workflow. There are size limits of 10 GB per workflow for teams and 3 GB for personal accounts, and symlinks aren't supported.

What to Cache

Cache items that are expensive to fetch or build and don't change often:

  • Flutter/Dart dependencies - pub cache

  • Android builds - Gradle caches and Android SDK path: /usr/local/share/android-sdk

  • iOS builds - CocoaPods caches

  • NDK path for Android native development

Attention:

Caching could cause issues:

  • Items that change frequently

  • Large build outputs that can cause stale or hard-to-debug issues

  • Anything where restoring the cache takes longer than recreating it

Special Considerations

Flutter version caching: While technically possible, caching the Flutter version itself is generally unnecessary since installing Flutter only takes a few minutes.

Build time expectations: You cannot achieve the same build times as your local machine because Codemagic builds start on clean VMs that need setup, whereas your local machine is already configured. This is inherent to the CI/CD process.

Implementation

Caching is enabled per workflow. There are two ways to turn it on, depending on whether you configure builds with codemagic.yaml or the Workflow Editor.

Using codemagic.yaml

Add a cache section to each workflow you want caching enabled for, and list the paths under cache_paths. The section lives inside the workflow alongside environment, scripts, and so on:

workflows:
  my-workflow:
    name: My workflow
    environment:
      flutter: stable
    cache:
      cache_paths:
        - ~/.pub-cache                      # Flutter/Dart dependencies
        - ~/.gradle/caches                  # Gradle caches
        - /usr/local/share/android-sdk      # Android SDK (and NDK under it)
        - $HOME/Library/Caches/CocoaPods    # CocoaPods caches
    scripts:
      - name: Install dependencies
        script: flutter pub get

Include only the paths relevant to your project. After committing the updated file, the cache populates on the next successful build and is restored automatically on subsequent runs.

Using the Workflow Editor (UI)

In your app settings, open the Dependency caching section and check Enable dependency caching (it's off by default). Enter each path you want to cache and click Add. You can remove paths at any time, and you can view the stored cache for each workflow under the Caching tab.

Focus on the most impactful dependencies first. Monitor your build logs to ensure cached items are being restored properly, and adjust your caching strategy based on actual performance improvements.