facebookarchive / react-native-fbsdk

A React Native wrapper around the Facebook SDKs for Android and iOS. Provides access to Facebook login, sharing, graph requests, app events etc.
https://developers.facebook.com/docs/react-native
Other
2.99k stars 908 forks source link

TypeError: Cannot read property 'logInWithPermissions' of undefined. #671

Closed motogod closed 4 years ago

motogod commented 4 years ago

🐛 Bug Report

Use login function will show TypeError: Cannot read property 'logInWithPermissions' of undefined. on Android.

螢幕快照 2019-11-16 下午6 11 18

To Reproduce

step 1: yarn add react-native-fbsdk step 2: add the code on Android side: android/app/src/main/res/values/strings.xml

<resources>
    <string name="app_name">MyProjectName</string>
    <string name="facebook_app_id">290084008583199</string>
</resources>

step 3-1: add the code on root: android/app/src/main/AndroidManifest.xml

<application>
...
<meta-data android:name="com.facebook.sdk.ApplicationId" android:value="@string/facebook_app_id"/>
...
<application>

step 3-2 add mavenCentral() polipolisalon/android/build.gradle

    repositories {
        mavenCentral()
        google()
        jcenter()
    }

step 3-3:

I'm not sure should I type the code , but I just type it on android/app/build.gradle

`implementation 'com.facebook.android:facebook-android-sdk:[4,5)'`

step 4: run the project by Android Studio.

step 5: trigger the facebookSignIn function on React Native:

import { LoginManager } from 'react-native-fbsdk';

// for Facebook sginIn
  facebookSignIn = () => {
    LoginManager.logInWithPermissions(["public_profile"]).then(
  function(result) {
    if (result.isCancelled) {
      console.log("Login cancelled");
    } else {
      console.log(
        "Login success with permissions: " +
          result.grantedPermissions.toString()
      );
    }
  },
  function(error) {
    console.log("Login fail with error: " + error);
  }
);
  }

Expected Behavior

It should show the facebook login view just like IOS.

Environment

```

"react": "16.9.0", "react-native": "0.61.2", "react-native-fbsdk": "^1.1.1",



IOS works fine but get failed on Android.  Is any step I miss it ?  
JarnoNijhof commented 4 years ago

Hi, Are you sure the package is linked on both andoriod and ios Mayby it's linked on ios but not on android.

Just try to run another time and make sure you are linking with libRCTFBSDK.a

motogod commented 4 years ago

Hi, Are you sure the package is linked on both andoriod and ios Mayby it's linked on ios but not on android.

Just try to run another time and make sure you are linking with libRCTFBSDK.a

Hi,

I am sure I link the package on IOS (Because LoginManager works on IOS). But why I can't link the package on Android in my step. ( include 3-1, 3-2, 3-3).

About the file libRCTFBSDK.a is IOS side not Android side right ?

motogod commented 4 years ago

I found what my problem, when I try to run my project by react-native run-android

Show the message that can't find the device.

It looks like something wrong with my android simulator.

So I change to another simulator and it works now.

Close issue.