Migration from Carthage to Cocoapods – React Native

In the beginning, we originally opted in for Carthage and steered away from Cocoapods. With react native’s upgrade of 0.60 and higher, we had to migrate from Carthage to Cocoapods. Here is how I did it!

1. Open Terminal

2. Install Cocoapods, if you do not have it already installed.

$ brew install cocoapods

3. Create a podfile in the project ios directory

$ cd {project}/ios
$ Pod init

4. The Podfile will contain a default setup where you can add any libraries you choose. In order for us to run the react-native app though, we will need the following in our Podfile:

# The target name is most likely the name of your project.
target 'NumberTileGame' do
# Your 'node_modules' directory is probably in the root of your project,
# but if not, adjust the `:path` accordingly
pod 'React', :path => '../node_modules/react-native/'
pod 'React-Core', :path => '../node_modules/react-native/React'
pod 'React-DevSupport', :path => '../node_modules/react-native/React'
pod 'React-fishhook', :path => '../node_modules/react-native/Libraries/fishhook'
pod 'React-RCTActionSheet', :path => '../node_modules/react-native/Libraries/ActionSheetIOS'
pod 'React-RCTAnimation', :path => '../node_modules/react-native/Libraries/NativeAnimation'
pod 'React-RCTBlob', :path => '../node_modules/react-native/Libraries/Blob'
pod 'React-RCTImage', :path => '../node_modules/react-native/Libraries/Image'
pod 'React-RCTLinking', :path => '../node_modules/react-native/Libraries/LinkingIOS'
pod 'React-RCTNetwork', :path => '../node_modules/react-native/Libraries/Network'
pod 'React-RCTSettings', :path => '../node_modules/react-native/Libraries/Settings'
pod 'React-RCTText', :path => '../node_modules/react-native/Libraries/Text'
pod 'React-RCTVibration', :path => '../node_modules/react-native/Libraries/Vibration'
pod 'React-RCTWebSocket', :path => '../node_modules/react-native/Libraries/WebSockepod 'React-cxxreact', :path => '../node_modules/react-native/ReactCommon/cxxreact'
pod 'React-jsi', :path => '../node_modules/react-native/ReactCommon/jsi'
pod 'React-jsiexecutor', :path => '../node_modules/react-native/ReactCommon/jsiexecutor'
pod 'React-jsinspector', :path => '../node_modules/react-native/ReactCommon/jsinspector'
pod 'yoga', :path => '../node_modules/react-native/ReactCommon/yoga'
pod 'DoubleConversion', :podspec => '../node_modules/react-native/third-party-podspecs/DoubleConversion.podspec'
pod 'glog', :podspec => '../node_modules/react-native/third-party-podspecs/glog.podspec'
pod 'Folly', :podspec => '../node_modules/react-native/third-party-podspecs/Folly.podspec'
end

The following is retrieved from the react native docs.

5. Depending if you had added these frameworks manually or linked using react-native link , make sure that you unlink by running react-native unlink in your terminal and removing any of the frameworks or libraries in your xcode project folders. Make sure you also remove in Link Binary with Libraries in your Build Phases section of your Target Project.Screen Shot 2019-09-27 at 6.55.51 PM.png

6. This step is dependent on what you currently have in your Carthage File. Most dependencies have a Cocoapod alternative, so you can easily transfer those dependencies. Each library will have a set of instructions on how to install.

7. Once you have migrated your Carthage dependencies, I would remove everywhere Carthage is mentioned. Do a quick search in both your Javascript code and iOS code and remove any instances of Carthage.

8. Make sure that you have added your libPods.{projectname}.a to your Frameworks by adding it to Link Binary with Libraries in your Build Phases of you project

Screen Shot 2019-09-27 at 7.03.19 PM.png

9. Once you finish setting Cocoapods up and removing all your Carthage files, you can now run the following your terminal. Make sure to run this in your ios folder to build and install cocoapods.

$  pod install

That’s about it! Your project should be up and running!

Depending on how your Carthage file was previously configured, you may receive the following error:

    1. No podspec found for `React-fishhook` in `../node_modules/react-native/Libraries/fishhook`

Solution: You can easily remove this file.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s