"FBSDKPackage" undefined with React Native Facebook SDK on Android

I am trying to get a fast Android app for Android React. He will have to log in with Facebook, so I follow this guide for this purpose.

https://developers.facebook.com/docs/react-native/getting-started-android/

Unfortunately, this looks deprecated because it ReactActivity.javadoes not expose the method getPackages. Also missing FBSDKPackage. I am using React Native version 0.29.

package com.myapplication;

import android.content.Intent;

import com.facebook.CallbackManager; import com.facebook.react.ReactActivity; import com.facebook.react.ReactPackage; import com.facebook.react.shell.MainReactPackage;

import java.util.Arrays; import java.util.List;

public class MainActivity extends ReactActivity { CallbackManager mCallbackManager;

/**
 * Returns the name of the main component registered from JavaScript.
 * This is used to schedule rendering of the component.
 */
@Override
protected String getMainComponentName() {
    return "MyApplication";
}

@Override
protected List<ReactPackage> getPackages() {
    mCallbackManager = new CallbackManager.Factory().create();
    ReactPackage packages[] = new ReactPackage[]{
            new MainReactPackage(),
            new FBSDKPackage(mCallbackManager), // <-- Cannot resolve symbol 'FBSDKPackage'
    };
    return Arrays.<ReactPackage>asList(packages);
}

@Override
public void onActivityResult(int requestCode, int resultCode, Intent data) {
    super.onActivityResult(requestCode, resultCode, data);
    mCallbackManager.onActivityResult(requestCode, resultCode, data);
}

}

code>

Does anyone have any experience?

Thank!
Chris

+4
source share
3 answers

- response-native-fbsdk ( native 0.47.1) compile project(':react-native-fbsdk'), https://github.com/facebook/react-native-fbsdk Android Studio. , , import com.facebook.reactnative.androidsdk.FBSDKPackage;

+1

, . FBSDKPackage, .

, rnpm ( ), build.gradle(Module: app)

compile "com.facebook.android:facebook-android-sdk:[4,5)"

MainApplication.java( MainActivity), .

MainApplication.java

public class MainApplication extends Application implements ReactApplication { 

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

  protected static CallbackManager getCallbackManager() {
    return mCallbackManager;
  }

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

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

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

  @Override
  public void onCreate() {
      super.onCreate();
      // Initialize the SDK before executing any other operations,
      FacebookSdk.sdkInitialize(getApplicationContext());
      AppEventsLogger.activateApp(this);
  }
}

MainActivity.java onActivityResult , MainApplication onActivity.

MainActivity.java

@Override
public void onActivityResult(int requestCode, int resultCode, Intent data) {
   super.onActivityResult(requestCode, resultCode, data);
   MainApplication.getCallbackManager().onActivityResult(requestCode, resultCode, data);
}
0

Got this flaw in FBSDKPackage and just solved the problem by adding this line to the import section of MainApplication.java:

import com.facebook.reactnative.androidsdk.FBSDKPackage;

Found this from the github documentation:

https://github.com/facebook/react-native-fbsdk/blob/master/README.md

0
source

All Articles