paint-brush
Configuring Bundler and Cocoapods for Xcode Cloud - A Quick Guideby@mniagolov
563 reads
563 reads

Configuring Bundler and Cocoapods for Xcode Cloud - A Quick Guide

by Maksim NiagolovJuly 4th, 2023
Read on Terminal Reader
Read this story w/o Javascript
tldt arrow

Too Long; Didn't Read

Bundler is a dependency manager for Ruby that makes it easy to manage dependencies and their versions. It allows developers to specify the exact version of each dependency required by their project. With the help of Bundler, managing dependencies for iOS applications has become much easier. We also highlighted a current issue with Cocoapods’ compatibility with Xcode 14.3.
featured image - Configuring Bundler and Cocoapods for Xcode Cloud - A Quick Guide
Maksim Niagolov HackerNoon profile picture

Xcode Cloud is a CI/CD service provided by Apple that allows developers to easily run tests, build and distribute iOS applications, and edit workflows directly from Xcode. It was first announced as a beta version at WWDC21 and then became generally available at WWDC22 with a paid plan starting in the summer of 2022. With Xcode Cloud, developers can easily automate the building and testing of their iOS applications, saving time and effort.


One of the key features of Xcode Cloud is the ability to resolve dependencies automatically. If you’re using the Swift Package Manager, Xcode Cloud will look at the Package.resolved file to resolve dependencies. However, if you're using other dependency managers like Cocoapods or Carthage, you'll need to install them first. This is where Bundler comes in handy.


Bundler is a dependency manager for Ruby that makes it easy to manage dependencies and their versions. It allows developers to specify the exact version of each dependency required by their project and resolves any conflicts between them. Bundler is a best friend of iOS developers since many iOS projects use Ruby-based tools like Fastlane and Cocoapods.


To use Bundler with Xcode Cloud, you can create a directory named ci_scripts under the project root directory and create a custom script there to execute during workflow execution. Xcode Cloud executes custom scripts at specific points during the workflow. For example, the ci_post_clone.sh script is executed after Xcode Cloud clones a Git repository.


Here is an example ci_post_clone.sh script for resolving dependencies:


#!/bin/sh

cd ..

echo ">>> SETUP ENVIRONMENT"
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"

echo ">>> INSTALL BUNDLER"
gem install bundler --install-dir $GEM_HOME

echo ">>> INSTALL DEPENDENCIES"
bundle install

echo ">>> INSTALL PODS"
bundle exec pod install

In this script, we first set up the environment by adding GEM_HOME and PATH to ~/.bash_profile. Then we install Bundler and run bundle install to install all required gems specified in the Gemfile. Finally, we run bundle exec pod install to install any dependencies managed by Cocoapods.


It’s worth noting that at the time of writing this article, there appears to be an issue with Cocoapods’ compatibility with Xcode 14.3. To resolve this, you may need to use a solution from this thread: https://github.com/CocoaPods/CocoaPods/pull/11828. This involves adding a custom row to the Gemfile to add all changes from the master branch before it was released:


gem 'cocoapods', :git => 'https://github.com/CocoaPods/CocoaPods.git', :branch => 'master'

Conclusion

In this article, we discussed how to configure Bundler and Cocoapods for Xcode Cloud. With the help of Bundler, managing dependencies for iOS applications has become much easier. We also highlighted a current issue with Cocoapods’ compatibility with Xcode 14.3 and provided a solution to resolve it.



Also published here.