Home > Blockchain >  Native module FBAccessToken tried to override FBAccesTokenModule. Check the getPackages() method in
Native module FBAccessToken tried to override FBAccesTokenModule. Check the getPackages() method in

Time:10-15

So I receive this error message while attempting to integrate Facebook login into my app but am overall unclear on how to address it as I can't seem to figure out what's wrong with my MainActivity.java file. I already installed Facebook SDK using "npm install --save react-native-fbsdk-next" and overall seem to have the necessary and correct dependencies.

The error message

The code in my MainActivity.Java file:

package com.socialapp2;

import android.app.Application;
import android.content.Context;
import com.facebook.react.PackageList;
import com.facebook.react.ReactApplication;
import com.facebook.react.ReactInstanceManager;
import com.facebook.react.ReactNativeHost;
import com.facebook.react.ReactPackage;
import com.facebook.soloader.SoLoader;
import java.lang.reflect.InvocationTargetException;
import java.util.List;

public class MainApplication extends Application implements ReactApplication {

  private final ReactNativeHost mReactNativeHost = new ReactNativeHost(this) {
    @Override
    public boolean getUseDeveloperSupport() {
      return BuildConfig.DEBUG;
    }

    @Override
    protected List<ReactPackage> getPackages() {
      @SuppressWarnings("UnnecessaryLocalVariable")
      List<ReactPackage> packages = new PackageList(this).getPackages();
      // Packages that cannot be autolinked yet can be added manually here, for
      // example:
      // packages.add(new MyReactNativePackage());
      return packages;
    }

    @Override
    protected String getJSMainModuleName() {
      return "index";
    }
  };

  @Override
  public ReactNativeHost getReactNativeHost() {
    return mReactNativeHost;
  }

  @Override
  public void onCreate() {
    super.onCreate();
    SoLoader.init(this, /* native exopackage */ false);
    initializeFlipper(this, getReactNativeHost().getReactInstanceManager());
  }

  /**
   * Loads Flipper in React Native templates. Call this in the onCreate method
   * with something like initializeFlipper(this,
   * getReactNativeHost().getReactInstanceManager());
   *
   * @param context
   * @param reactInstanceManager
   */
  private static void initializeFlipper(Context context, ReactInstanceManager reactInstanceManager) {
    if (BuildConfig.DEBUG) {
      try {
        /*
         * We use reflection here to pick up the class that initializes Flipper, since
         * Flipper library is not available in release mode
         */
        Class<?> aClass = Class.forName("com.socialapp.ReactNativeFlipper");
        aClass.getMethod("initializeFlipper", Context.class, ReactInstanceManager.class).invoke(null, context,
            reactInstanceManager);
      } catch (ClassNotFoundException e) {
        e.printStackTrace();
      } catch (NoSuchMethodException e) {
        e.printStackTrace();
      } catch (IllegalAccessException e) {
        e.printStackTrace();
      } catch (InvocationTargetException e) {
        e.printStackTrace();
      }
    }
  }
}

CodePudding user response:

I solved the issue. See below for resolution:

  • Check your package.json file and make sure you do not have duplicate facebook sdk dependencies. In my case i had "react-native-fbsdk" and "react-native-fbsdk-next" as two separate dependencies which conflicted with each other.

Here are some general troubleshooting steps as well:

  • Make sure that the package name is identical in your MainActivity.java, MainApplication.java, and AndroidManifest.xml file.

  • Make sure that the applicatonId in your app/build.gradle file matches the package name specified in the previous bullet point.

  • Related