loading...

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

onmyway133 profile image Khoa Pham ・2 min read

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

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

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

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

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

Original post https://github.com/onmyway133/blog/issues/170

Posted on by:

onmyway133 profile

Khoa Pham

@onmyway133

My apps https://onmyway133.com/apps/

Discussion

pic
Editor guide