How to use react-native link and CocoaPods

How to cache CocoaPods

Issue #196

CocoaPods vs Carthage

CocoaPods will build and compile our frameworks every time whenever you are doing the clean build or run pod install or pod update for the project.

Cache Carthage

Cache CocoaPods

It will compile the source code of pods during the pod install process, and make CocoaPods use them. Which pod should be compiled is controlled by the flag in Podfile.

Xcode 10 new build system

Understanding framework

How to fix MethodError - undefined method `real_path` with CocoaPods?

Issue #170

abc

I’m using cocoapods 1.6.0.beta.2 in a React Native apps and it has been working fine. The pods that I need is Firebase and FacebookSDK. Today after pod install, I got error

1
NoMethodError - undefined method `real_path' for nil:NilClass

I then tried running pod deintegrate to start from scratch, but that command fails as well.

My next try is with cocoapods 1.6.0 and cocoapods 1.6.1 but the problem still persists.

undefined method in Ruby means that we are calling a method on an object that is nil. I like to track down problems via reading code, but this error is very vague.

Looking thorough at the log, I see CocoaPods has done fetching dependencies, but fails at the integration step, so it must be something wrong with my project file.

Then I trace back commits to project.pbxproj to see if there’s anything wrong. It turns out that there was a commit that accidentally removes Pods-MyApp Staging.release.xcconfig from project. That also comes with removal of

1
baseConfigurationReference = B7FC69316CC27F11022F8A82 /* Pods-MyApp Staging.release.xcconfig */;

CocoaPods uses xcconfig

As you know, CocoaPods uses xcconfig files to declare pod related information like FRAMEWORK_SEARCH_PATHS, OTHER_LDFLAGS and other variables like

1
2
3
4
PODS_BUILD_DIR = ${BUILD_DIR}
PODS_CONFIGURATION_BUILD_DIR = ${PODS_BUILD_DIR}/$(CONFIGURATION)$(EFFECTIVE_PLATFORM_NAME)
PODS_PODFILE_DIR_PATH = ${SRCROOT}/.
PODS_ROOT = ${SRCROOT}/Pods

And for a normal pod install, CocoaPods adds some xcconfig files to your project, and the path is Pods/Target Support Files/Pods-DeepDiffDemo. There will always be debug.xcconfig and release.xcconfig for each of your project target.

xcconfig

If your project MyApp has a production target called MyApp Production and MyApp Staging, then you should have these files

1
2
3
4
Pods-MyApp Staging.debug.xcconfig
Pods-MyApp Staging.release.xcconfig
Pods-MyApp Production.debug.xcconfig
Pods-MyApp Production.release.xcconfig

These are added to projects but not checked to any targets. Just like plist, you don’t need to add xcconfig files to target.

If you go to project Info page, you will see that these xcconfig files are selected

project

Missing xcconfig

In my case, Pods-MyApp Staging.release.xcconfig was somehow missing from project, hence all pod commands fail.

The fix is to re-add that file and select that xcconfig in project Info page

Dealing with updated pod in BuddyBuild

Issue #149

We’re using BuddyBuild as our CI. Today one of our dependencies gets a sweat update https://github.com/hyperoslo/BarcodeScanner/releases/tag/4.1.1. So we pod update BarcodeScanner in one of our projects that depends on it. All is fine when running locally. So I make a Pull Request and wait for the build to kick off in BuddyBuild.

For some reason, BuddyBuild can’t pick up the right version of Cocoapods, hence can’t update the new pods.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
[!] The version of CocoaPods used to generate the lockfile (1.3.1) is higher than the version of the current executable (1.1.1). Incompatibility issues may arise.

=== CocoaPods ===
104
Switching CocoaPods version to 1.1.1
105
Using Command Line: gem cleanup "cocoapods"
106
Using Command Line: gem uninstall "cocoapods" --all --executables --force
107
Using Command Line: gem install "cocoapods" --no-rdoc --no-ri --version "1.1.1"
108
Unpacking caches - cocoapods pod specs
109
Using Command Line: pod install --no-repo-update
110
Analyzing dependencies
111
Pre-downloading: `Tailor` from `https://github.com/zenangst/Tailor`, tag `3.0.0`
112
[!] Unable to satisfy the following requirements:
113
- `BarcodeScanner (~> 4.0)` required by `Podfile`
114
- `BarcodeScanner (~> 4.0)` required by `Podfile`
115
- `BarcodeScanner (~> 4.0)` required by `Podfile`
116
- `BarcodeScanner (~> 4.0)` required by `Podfile`
117
- `BarcodeScanner (~> 4.0)` required by `Podfile`
118
- `BarcodeScanner (~> 4.0)` required by `Podfile`
119
- `BarcodeScanner (= 4.1.1)` required by `Podfile.lock`
120
None of your spec sources contain a spec satisfying the dependencies: `BarcodeScanner (~> 4.0), BarcodeScanner (= 4.1.1)`.
121
You have either:
122
* out-of-date source repos which you can update with `pod repo update`.
123
* mistyped the name or version.
124
* not added the source repo that hosts the Podspec to your Podfile.
125
Note: as of CocoaPods 1.0, `pod repo update` does not happen on `pod install` by default.

Trying script

So I thought I could run some custom script to force BuddyBuild to update the pods. Start with https://docs.buddybuild.com/builds/custom_build_steps.html

I commit the file buddybuild_postclone.sh with

1
2
3
4
#!/usr/bin/env bash

pod repo update
pod update BarcodeScanner

Didn’t work. I then update the script with

1
2
3
4
5
#!/usr/bin/env bash

pod repo remove master
pod setup
pod install

Didn’t work. Taking a closer look at the log. I see

1
Switching CocoaPods version to 1.1.1

It seems BuddyBuild is using cocoapods 1.1.1. Mine is 1.4.0.

Specifying cocoapods version

So I need to specify the correct cocoapods version to make sure I and BuddyBuild are on the same page

1
2
gem install bundler
bundler init

And in my Gemfile

1
2
3
4
5
6
7
# frozen_string_literal: true

source "https://rubygems.org"

git_source(:github) {|repo_name| "https://github.com/#{repo_name}" }

gem "cocoapods", '~> 1.0'

Then run

1
bundler install

And check Gemfile.lock to make sure everything is OK

Finally

Commit the changes, and now BuddyBuild is picking up the right cocoapods version, hence using the new pods

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15


=== CocoaPods ===
45
Switching CocoaPods version to 1.4.0
46
Using Command Line: gem cleanup "cocoapods"
47
Using Command Line: gem uninstall "cocoapods" --all --executables --force
48
Using Command Line: gem install "cocoapods" --no-rdoc --no-ri --version "1.4.0"
49
Unpacking caches - cocoapods pod specs
50
Using Command Line: pod install --no-repo-update