React Native 0.60因自动生成PackageList致FBSDKPackage链接错误
Hey there, let's tackle this FBSDK error you're facing in React Native 0.60. I've dealt with this exact issue when React Native rolled out auto-linking, so let's break down what's happening and fix it step by step.
What's Causing the Error?
Looking at your code and the error message, the problem is clear:
- The auto-generated
PackageListclass is creating anew FBSDKPackage()with no arguments. - But the
FBSDKPackageconstructor requires aCallbackManagerinstance (as seen in your manual initialization:new FBSDKPackage(mCallbackManager)). - On top of that, you're manually adding the FBSDK package again, which would lead to duplicate package registration even if the auto-linked version worked.
Step-by-Step Fix
1. Disable Auto-Linking for React Native FBSDK
Since auto-linking can't handle the custom constructor argument needed for FBSDK, we need to tell React Native to skip auto-linking this package.
Create or update a react-native.config.js file in your project root with this code:
module.exports = { dependencies: { 'react-native-fbsdk': { platforms: { android: null, // Disable Android auto-linking ios: null // Add this if you hit the same issue on iOS } } } };
2. Clean Up Your MainApplication.java
Remove the risk of duplicate packages by keeping only your manual FBSDK initialization (the one with CallbackManager). Update your getPackages() method like this:
@Override protected List<ReactPackage> getPackages() { @SuppressWarnings("UnnecessaryLocalVariable") List<ReactPackage> packages = new PackageList(this).getPackages(); // Keep only this manual FBSDKPackage entry (with CallbackManager) packages.add(new FBSDKPackage(mCallbackManager)); // Note: If RNGoogleSigninPackage is already in the auto-generated PackageList, // you can remove the line below to avoid duplicates packages.add(new RNGoogleSigninPackage()); packages.add(new Interactable()); return packages; }
3. Clean and Rebuild Your Project
Old build artifacts might still have the broken auto-linked code, so let's clean and rebuild:
For Android:
cd android ./gradlew clean cd .. react-native run-android
Why This Works
By disabling auto-linking for FBSDK, we stop the invalid FBSDKPackage instance from being created in the auto-generated PackageList. Our manual initialization ensures the package gets the required CallbackManager, matching the constructor's requirements and resolving the error.
内容的提问来源于stack exchange,提问作者Tarun konda

