How to cache cocoapods

I am trying to use my cached cocoapods in my config so that I don’t have to install them each time. This is the relevant part of my code:

- restore_cache:
          key: 1-pods-{{ checksum "Podfile.lock" }}
      - run:
          name: Install CocoaPods
          command: pod install
      - save_cache:
          key: 1-pods-{{ checksum "Podfile.lock" }}
          paths:
            - ./Pods

However, there are two problems:

  1. The key 1-pods-{{ checksum "Podfile.lock" }} from restore_cache is always different to the key from save_cache.
  2. Even if I specific the key manually so that they definitely match up, it retrieves the cache, and then just redownloads all the pods anyway. Can I specify a path from where it can retrieve the Pods from?

Thanks!

1 Like

Hello, we strongly recommend you checking your pods into your repo instead of caching as this will be much faster https://guides.cocoapods.org/using/using-cocoapods.html#should-i-check-the-pods-directory-into-source-control

I would but I have a lot of pods so I can’t really afford to do that because of space issues

@drazisil, checking-in pods increase git repo size by a lot. That results in a longer repo clone time and just wasted space on hard drive.

Can you suggest a solution if user chooses to keep pods not checked in?

Thanks!

Hi Ugis. The above suggestion came from one of the Cocapods maintainers.

If you were to cache them, that would still be a download and upload, which would also result in longer times, and expose you to possible network issues.

Here is an example post from Scoop on one way you can cache your pods using S3: https://blog.takescoop.com/improve-ios-ci-build-time-with-cocoapods-caching-4a049ee45e63

Thanks, @drazisil! Will look into this method

1 Like

when you made the pod install that command could change the Podfile.lock because you are not using the same version of Xcode.

https://circleci.com/docs/2.0/testing-ios/#supported-xcode-versions