Reputation: 1652
I'm attempting to get a quick React Native Android app off the ground. It'll need signing in with Facebook, so I'm following this guide to that end.
https://developers.facebook.com/docs/react-native/getting-started-android/
Unfortunately, this looks to be out of date, as ReactActivity.java
doesn't expose a getPackages
method. Additionally, the FBSDKPackage
is also missing. I'm 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);
}
}
Anyone have any experience with this?
Thanks!
Chris
Upvotes: 4
Views: 5170
Reputation: 1196
In my case, i need to edit manually in app/build.gradle by adding react-native-fbsdk
as dependencies
dependencies {
...
implementation project(':react-native-fbsdk')
}
then run the android again.
Upvotes: 1
Reputation: 949
For some reason react-native-fbsdk (react native 0.47.1) won't create module compile project(':react-native-fbsdk')
so I had to clone this project https://github.com/facebook/react-native-fbsdk and import it myself with Android Studio. And of course add import com.facebook.reactnative.androidsdk.FBSDKPackage;
Upvotes: 1
Reputation: 11
Got this FBSDKPackage missing issue too 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 documentation on github:
https://github.com/facebook/react-native-fbsdk/blob/master/README.md
Upvotes: 1
Reputation: 2398
I faced the same problem like you. I have succeeded on compiling the project without FBSDKPackage
and I couldn't find any solution for that.
For the other parts, if rnpm
didn't work (in my case it didn't), you first need to update dependencies in build.gradle (Module: app) file and add
compile "com.facebook.android:facebook-android-sdk:[4,5)"
After the sync process finishes, update your MainApplication.java (not MainActivity) such that it has these methods.
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);
}
}
and in your MainActivity.java, you need to update onActivityResult such that it uses MainApplication's callback manager's onActivity result.
MainActivity.java
@Override
public void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);
MainApplication.getCallbackManager().onActivityResult(requestCode, resultCode, data);
}
Upvotes: 0