LGN
LGN

Reputation: 41

React Native fb-sdk cannot find symbol CallbackManager

React Native and fbsdk versions:

"react": "16.6.3",
"react-native": "0.58.5",
"react-native-fbsdk": "^0.8.0"

I got the following error:

> Task :app:compileDebugJavaWithJavac FAILED
C:\Users\xxxx\Desktop\project\android\app\src\main\java\com\project\MainApplication.java:22: error: cannot find symbol
  private static CallBackManager mCallbackManager = CallbackManager.Factory.create();
                 ^
  symbol:   class CallBackManager
  location: class MainApplication
C:\Users\xxxx\Desktop\project\android\app\src\main\java\com\project\MainApplication.java:24: error: cannot find symbol
  protected static CallBackManager getCallbackManager() {
                   ^
  symbol:   class CallBackManager
  location: class MainApplication
2 errors

FAILURE: Build failed with an exception.

* What went wrong:
Execution failed for task ':app:compileDebugJavaWithJavac'.
> Compilation failed; see the compiler error output for details.

The issue seems to be related to this part of the code, but I can't quite figure out what's wrong. I followed exactly the instructions provided in their official repository.

public class MainApplication extends Application implements ReactApplication {

  private static CallBackManager mCallbackManager = CallbackManager.Factory.create();

  protected static CallBackManager getCallbackManager() {
    return mCallbackManager;
  }

  // ...

  @Override
  protected List<ReactPackage> getPackages() {
    return Arrays.<ReactPackage>asList(
      new MainReactPackage(),
      new FBSDKPackage(mCallbackManager)
    );
  }

  // ...

}

I also manually added the following imports to MainActivity.java:

import com.facebook.CallbackManager;
import com.facebook.FacebookSdk;
import com.facebook.reactnative.androidsdk.FBSDKPackage;

Added these lines to app/build.gradle:

implementation project(':react-native-fbsdk')
implementation 'com.facebook.android:facebook-android-sdk:4.34.0'

and these to settings.gradle:

include ':react-native-fbsdk'
project(':react-native-fbsdk').projectDir = new File(rootProject.projectDir, '../node_modules/react-native-fbsdk/android')

Upvotes: 2

Views: 2504

Answers (1)

LGN
LGN

Reputation: 41

If someone happens to stumble across the very same issue, this is related to npm not linking fb-sdk to the project properly. I tried using npm install and npm link, but had no success, despite npm not throwing any errors. However, installing the sdk using react-native resolved the issue:

react-native install react-native-fbsdk
react-native link react-native-fbsdk

Should you run into a MODULE_NOT_FOUND error while attempting to link, open the command line on the project root folder and run:

cd android
gradlew clean

Additionally, while their official GitHub repository does contain instructions regarding the installation process, I recommend following the facebook developers page instead, as it is a lot better in terms of readability and details.

Upvotes: 2

Related Questions