3

I have errors with Xcode cloud testing while archiving.

Issues are all related to CocoaPods dependencies:

unable to open file (in target "Alamofire" in project "Pods")

missing module map file: '/Volumes/workspace/repository/Pods/Target Support Files/Alamofire/Alamofire.modulemap

Looks like pods are not being installed on archiving.

It works well locally.

Best,

xGoPox
  • 674
  • 8
  • 23

3 Answers3

7

Xcode Cloud temporary build environment doesn't include third party tools like CocoaPods. But you can include them using post clone script. Here are the steps if you are using CocoaPods.

  1. Create a directory ci_scripts at the root of your project.

  2. Add a file ci_post_clone.sh and save it in the ci_scripts directory.

  3. Open Terminal and make your script executable be running chmod +x ci_post_clone.sh in ci_scripts directory.

  4. Edit the ci_post_clone.sh in any text editor and copy the following.

     # !/bin/sh
    
     # Install CocoaPods using Homebrew.
     brew install cocoapods
    
     # Install dependencies you manage with CocoaPods.
     pod install
    
  5. Commit and push ci_post_clone.sh.

Bilal
  • 18,478
  • 8
  • 57
  • 72
  • brew is not installed on their cloud machines ... – Yaroslav Dukal Mar 03 '22 at 09:29
  • 1
    brew is available, I tried it and it works. – Bilal Mar 03 '22 at 12:05
  • @YaroslavDukal Yeah it stoped working from couple of weeks. It was working earlier and even brew commands are mentioned in the apple docs here https://developer.apple.com/documentation/xcode/making-dependencies-available-to-xcode-cloud#Use-a-Custom-Build-Script-to-Install-a-Third-Party-Dependency-or-Tool . As it's still in beta so there might be some changes or bug – Bilal Mar 04 '22 at 05:44
  • It worked.. but I am disappointed, build takes forever with all this post install things... My mac book pro compiles it way faster and does not have to install 3rd party dependencies each build .. Not recommended to use that. – Yaroslav Dukal Mar 06 '22 at 10:02
0

The documentation suggested way of setting this up is terrible - it has no versioning, and it takes a lot of time to install through brew. The best way is having a Gemfile that declares the dependencies at the root of your repo, ie:

source 'https://rubygems.org'

gem 'cocoapods'
gem 'fastlane'

Then bundle install it to lock the versions of the tools on a Gemfile.lock (you should version both files in your repo).

On your ci_scripts/ci_post_clone.sh file:

#!/bin/sh

#1 - You can't install gems to the system gem path without sudo, so create a local one
echo ">>> SETUP LOCAL GEM PATH"
echo 'export GEM_HOME=$HOME/gems' >>~/.bash_profile
echo 'export PATH=$HOME/gems/bin:$PATH' >>~/.bash_profile
export GEM_HOME=$HOME/gems
export PATH="$GEM_HOME/bin:$PATH"

#2 - Install the actual bundler version you bundled locally with, so you don't have any surprises
echo ">>> INSTALL REQUIRED BUNDLER VERSION"
gem install bundler -v "$(grep -A 1 "BUNDLED WITH" ../Gemfile.lock | tail -n 1)" --install-dir $GEM_HOME

#3 - Let bundler download the locked version of cocoapods, fastlane, and whatever other tools you need
echo ">>> INSTALL DEPENDENCIES"
bundle install

#4 - Finally you can run the bundled pod binary to install your dependencies
echo ">>> INSTALL PODS"
bundle exec pod install

Also, consider commiting your Pods folder to avoid the need to run cocoapods at all. Or at least gitignore only large binaries (i.e Twilio, WebRTC, etc). This also protects you from deleted repos or offline services providers

Rafael Nobre
  • 5,062
  • 40
  • 40