react-native: In a CocoaPod build, "Optional.h" will refer to folly/Optional.h unexpectedly
Description
The CocoaPods setup works, but there are issues integrating it into larger projects. In particular, header files from folly (and maybe elsewhere?) pollute the user header filespace, and I don’t know why.
Reproduction Steps and Sample Code
- check out https://github.com/mhorowitz/native-navigation-boilerplate and apply this:
diff --git a/ios/Podfile b/ios/Podfile
index 3474dc5..556aa68 100644
--- a/ios/Podfile
+++ b/ios/Podfile
@@ -26,6 +26,8 @@ target 'ReactNativeStarter' do
'DevSupport'
]
+ pod 'KSCrash'
+
# Add any other dependencies here, including any 3rd party native libraries that you depend on for
# React Native.
end
- To run pod and open in Xcode:
cd ios
pod install
open ReactNativeStarter.xcworkspace
- Build it in Xcode. it will fail, probably in KSCrash’s Demangle.cpp with an error about llvm::Optional. If you dig into this, you will eventually figure out that it is including folly/Optional.h instead. Xcode is generating a header map like
.../DerivedData/ReactNativeStarter-bzdrkfxifzuvmgduxsjbskaldaxw/Build/Intermediates/Pods.build/Debug-iphonesimulator/KSCrash.build/KSCrash-project-headers.hmap
which mapsoptional.h
toPods/Folly/folly/Optional.h
, instead of the one inside KSCrash.
Solution
I have no idea. I am hoping someone who knows CocoaPods better than I can figure this out.
Additional Information
- React Native version: 844a18fb25b94ad568e5e715d328bea9d63fe592
- Platform: iOS
- Development Operating System: MacOS Sierra
- Dev tools: Xcode 8.2.1, cocoapods 1.2.0
About this issue
- Original URL
- State: closed
- Created 7 years ago
- Reactions: 6
- Comments: 35 (15 by maintainers)
Commits related to this issue
- BREAKING - Update podspecs to support and default to the C++ bridge Summary: This will require people who use CocoaPods to update their Podfiles. You can see an example of a Podfile set up to use th... — committed to facebook/react-native by mhorowitz 7 years ago
- Work around the broken way CocoaPods/Xcode deals with header maps Summary: See https://github.com/facebook/react-native/issues/14326 for the bug this fixes. This is a pretty ugly hack to work around... — committed to facebook/react-native by mhorowitz 7 years ago
Thanks @mhorowitz! Followed your above-mentioned steps but still getting
limits not found in Math.h
in RCTFBSDK.This is my podfile:
`react_native_path = ‘…/node_modules/react-native’
platform :ios, ‘8.0’
target ‘MemoriesApp’ do
source ‘https://github.com/CocoaPods/Specs.git’ pod ‘React’, :path => react_native_path, :subspecs => [ ‘Core’, ‘RCTText’, ‘RCTNetwork’, ‘RCTImage’, ‘RCTAnimation’, ‘RCTWebSocket’, ‘ART’, ‘CxxBridge’, ‘DevSupport’ ]
pod ‘DoubleConversion’, :podspec => react_native_path + ‘/third-party-podspecs/DoubleConversion.podspec’ pod ‘GLog’, :podspec => react_native_path + ‘/third-party-podspecs/GLog.podspec’ pod ‘Folly’, :podspec => react_native_path + ‘/third-party-podspecs/Folly.podspec’
pod ‘Yoga’, :path => ‘…/node_modules/react-native/ReactCommon/yoga’ pod ‘lottie-react-native’, :path => ‘…/node_modules/lottie-react-native’ pod ‘RNAudioStreaming’, :path => ‘…/node_modules/react-native-audio-streaming’ pod ‘CodePush’, :path => ‘…/node_modules/react-native-code-push’
pod ‘FBSDKCoreKit’ pod ‘FBSDKShareKit’ pod ‘FBSDKLoginKit’ pod ‘RSKImageCropper’ pod ‘QBImagePickerController’ pod ‘GooglePlaces’ pod ‘GoogleMaps’ pod ‘GooglePlacePicker’ pod ‘Fabric’ pod ‘Crashlytics’ end
`
Thanks in advance!
@ragnorc Thanks for all of the helpful comments here. I’m having a very similar issue (upgrading from 0.44 -> 0.48). I tried using the
CxxBridge
and now am attempting to revert back to theBatchedBridge
. Could you describe the steps you took to revert? Did you remove the 3 dependencies from your Podfile as well (Folly, Glog, DoubleConversion)? Any help would be awesome, thanks!@mhorowitz Yes, I am now using BatchedBridge as a temporary solution. Thank you very much for your efforts!
When I update from react-native 0.44.3 to 0.45.1, I got a build issue in iOS.
Please help me to resolve this build error. Thanks in Advance.
@mhorowitz I am building against
0.47.0-rc.1
.My pod output doesn’t seem to differ from yours except that I upgrade the FBSDK pods, which didn’t remove the error, unfortunately. https://gist.github.com/ragnorc/c20f36ec79496180049b7255b2854348
Still getting the error:
In file included from /Users/ragnor/Desktop/devSpace/memories/node_modules/react-native-fbsdk/ios/RCTFBSDK/share/RCTFBSDKShareDialog.m:23: In file included from /Users/ragnor/Desktop/devSpace/memories/node_modules/react-native-fbsdk/ios/RCTFBSDK/share/RCTConvert+FBSDKSharingContent.h:19: In file included from /Users/ragnor/Desktop/devSpace/memories/ios/build/Build/Products/Debug-iphonesimulator/include/React/RCTConvert.h:19: In file included from /Users/ragnor/Desktop/devSpace/memories/ios/build/Build/Products/Debug-iphonesimulator/include/yoga/Yoga.h:13: ../../../ios/Pods/Folly/folly/math.h:26:10: fatal error: 'limits' file not found #include <limits> ^ 1 error generated.
@mhorowitz @sivakumar-cf @ohtangza
I submitted a bug report to Facebook and they now managed to find a fix. Just follow these steps: https://developers.facebook.com/bugs/111079162900447/
@ragnorc Two of us met today to look into this repro to try to understand what’s happening here. We are still working on it.
In the meantime, is switching to BatchedBridge not a viable workaround until we’ve fixed this? We are keeping it around precisely for that purpose, until we’ve shaken out all the CxxBridge issues.
Ok, this is all helpful, thanks. I have a couple more questions.
And now I have a theory. Both of your ( @ragnorc and @sivakumar-cf ) error messages include header files in
.../ios/build/Build/Products/Debug-iphonesimulator/include
. The entire contents of theios/build
directory is created by Xcode. Xcode is notorious for being sloppy with the way it handles using and cleaning files in this directory. I delete myios/build
directory regularly, and I do not have theios/build/Build/Products/Debug-iphonesimulator/include
subdirectory at all. I speculate that this directory contains files left behind from previous builds, and these files are being used by Xcode unintentionally, interfering with the current build. There may be other old files lying around causing trouble.So, the fix if this theory is correct is to clean up after Xcode manually. Remove this directory:
rm -r ios/build
. Then try building your app again.A little more detail: the path
../../../ios/Pods/Folly/folly/math.h
is suspicious. The file does exist, but the case is incorrect, and the pods which are failing should not be able to see it. I believe this path is coming from a.hmap
file which is generated by Xcode. The changes in f3f44eee59e8991e197c854e5fee719105c045cd and 26f01faf1b3f801501f77d47b00e05fb8a8b3b32 should result in the folly headers no longer being included in any.hmap
files but if there are old files left behind in the build directory, this fix may not work correctly.I’ve ran into this error when ejecting from create-react-native-app into ExpoKit mode. I added the additional pod specs per this.
And I’m now stuck here.
I think I have something related to this. I’m using react-native-fbsdk and when using
CxxBridge
the project doesn’t compile and shows a warning ‘non portable path to file Math.h’ and an error and doesn’t find thelimits
import (limits file not found). When using theBatchedBridge
everything compiles.