问题
Let me start by saying that similar SO questions suggest the problem may be related to not having linked the lib.
I've ran react-native link react-native-fbsdk
again, to confirm it was indeed linked, and confirmed it was
rnpm-install info Platform 'ios' module react-native-fbsdk is already linked
rnpm-install info Platform 'android' module react-native-fbsdk is already linked
Still, I see a couple of red indications in my XCode project for main.jsbundle
, libReact.a
and libRCTFBSDK.a
(which I find especially disturbing to be showing under "Recovered References", and to be pointing to nowhere when I try to locate it in Finder). So, all in all, strong indications that something (or some things) went wrong with my FBSDK setup.
Because these are mentioned in the setup guides, let me go ahead an report that:
- I've downloaded the SDK, which is extracted under my
~/Documents/FacebookSDK
folder - I've dragged the 4 frameworks (
Bolts
,FBSDKCoreKit
,FBSDKLoginKit
,FBSDKShareKit
) into the project, not marking the "Copy" option - My "Build Settings" >> "Framework Search Paths" has
~Documents/FacebookSDK
for value (and just that, nothing else) - My "Build Settings" >> "Other Linker Flags" has
-ObjC -lc++
for value (this was already so, I didn't touch it, just confirmed it hadObjC
, per Facebook's guide) - My "Build Phases" >> "Link Binary With Libraries" has the 4 frameworks, plus several others files, including the two that are in red in the tree (
libReact.a
andlibRCTFBSDK.a
)
While it does seem the problem is rooted in those red files, I'm out of clues or luck in trying to fix them, so any help is appreciated!
回答1:
I have been struggling with that a lot of time. After some investigation and several tries, I solved it this way:
- Remove node_modules and ios/Pods
- Upgraded to react-native 0.60
- npm install
- Added this to Podfile:
pod 'FBSDKCoreKit'
pod 'FBSDKLoginKit'
pod 'FBSDKShareKit'
from ios folder: ```pod install ````
configure AppDelegate and Info.plist as this guide states
I did not have to manually drag the frameworks to the Xcode project as the guide say.
回答2:
As of the moment of this issue, the react-native-fbsdk github indicates this guide should be followed, with the exception of step 2 (Linking the SDK), with the frameworks being dragged into the project instead. That's similar to what's indicated at the "Quick Start" guide you get to from inside FB's Dashboard. Both those guides were the source of the issues I was seeing.
Following this guide instead got it working.
来源:https://stackoverflow.com/questions/54124766/how-to-fix-invariant-violation-requirenativecomponent-rctfbloginbutton-was