thebergamo / react-native-fbsdk-next

MIT License
633 stars 165 forks source link

Attempt to invoke virtual method 'void com.facebook.AccessTokenTracker.stopTracking()' on a null object reference #473

Closed GreenFella closed 5 months ago

GreenFella commented 5 months ago

Error:

 ERROR  Your app just crashed. See the error below.
java.lang.NullPointerException: Attempt to invoke virtual method 'void com.facebook.AccessTokenTracker.stopTracking()' on a null object reference
  com.facebook.reactnative.androidsdk.FBAccessTokenModule.onCatalystInstanceDestroy(FBAccessTokenModule.java:81)
  com.facebook.react.bridge.BaseJavaModule.invalidate(BaseJavaModule.java:76)
  com.facebook.react.bridge.ModuleHolder.destroy(ModuleHolder.java:110)
  com.facebook.react.bridge.NativeModuleRegistry.notifyJSInstanceDestroy(NativeModuleRegistry.java:108)
  com.facebook.react.bridge.CatalystInstanceImpl$1.run(CatalystInstanceImpl.java:359)
  android.os.Handler.handleCallback(Handler.java:942)
  android.os.Handler.dispatchMessage(Handler.java:99)
  com.facebook.react.bridge.queue.MessageQueueThreadHandler.dispatchMessage(MessageQueueThreadHandler.java:27)
  android.os.Looper.loopOnce(Looper.java:226)
  android.os.Looper.loop(Looper.java:313)
  com.facebook.react.bridge.queue.MessageQueueThreadImpl$4.run(MessageQueueThreadImpl.java:228)
  java.lang.Thread.run(Thread.java:1012)

🐛 Bug Report

The app crashes as soon as it is opened with the above error message. Two people have reported this issue within the last 5 days I found in this thread: https://github.com/expo/expo/issues/18497

Code Example

Installed via the expo install guide npx expo install react-native-fbsdk-next and then rebuilt my app using npx eas build --profile development --platform android This is all I have added to my app related to react-native-fbsdk-next and it is in app.json

"react-native-fbsdk-next",
        {
          "appID": "myappid",
          "clientToken": "myclienttoken",
          "displayName": "myappdisplayname",
          "scheme": "myappscheme"
        }

Environment

npx expo-env-info

  expo-env-info 1.0.5 environment info:
    System:
      OS: Windows 10 10.0.19045
    Binaries:
      Node: 18.18.0 - C:\Program Files\nodejs\node.EXE
      npm: 10.1.0 - C:\Program Files\nodejs\npm.CMD
    IDEs:
      Android Studio: AI-223.8836.35.2231.10671973
    npmPackages:
      @expo/webpack-config: ^19.0.0 => 19.0.0
      expo: ^49.0.7 => 49.0.13
      react: 18.2.0 => 18.2.0
      react-dom: 18.2.0 => 18.2.0
      react-native: 0.72.5 => 0.72.5
      react-native-web: ~0.19.6 => 0.19.9
    Expo Workflow: bare
mikehardy commented 5 months ago

com.facebook.reactnative.androidsdk.FBAccessTokenModule.onCatalystInstanceDestroy(FBAccessTokenModule.java:81)

https://github.com/thebergamo/react-native-fbsdk-next/blob/36a762af896bc4ed2dd08b1f361267f107e830ed/android/src/main/java/com/facebook/reactnative/androidsdk/FBAccessTokenModule.java#L81

Looks like it's missing a simple null check, but I don't reproduce this so I can produce a patch and new version but you'll need to report back if it worked or not.

mikehardy commented 5 months ago

I've posted PR #474 which I will merge and release assuming it builds successfully, if you could report success/fail there I would appreciate it

I think you may be failing to properly initialize the Facebook SDK and simply doing that correctly would also avoid the problem. Specifically I see your app.json chunk but I'm not sure you have added the expo plugin into the plugin list? Because if you did I believe that would initialize things, then the object that is null and causing the crash would not be null

github-actions[bot] commented 5 months ago

:tada: This issue has been resolved in version 12.1.1 :tada:

The release is available on:

Your semantic-release bot :package::rocket:

GreenFella commented 5 months ago

I've posted PR #474 which I will merge and release assuming it builds successfully, if you could report success/fail there I would appreciate it

I think you may be failing to properly initialize the Facebook SDK and simply doing that correctly would also avoid the problem. Specifically I see your app.json chunk but I'm not sure you have added the expo plugin into the plugin list? Because if you did I believe that would initialize things, then the object that is null and causing the crash would not be null

@mikehardy The new release fixed this issue but just adding my app.json file in here in response to your notes:

{
  "expo": {
    "name": "......",
    "slug": "......",
    "version": "1.0.0",
    "orientation": "portrait",
    "icon": "./assets/icon.png",
    "userInterfaceStyle": "automatic",
    "scheme": "......",
    "splash": {
      "image": "./assets/splash.png",
      "resizeMode": "contain",
      "backgroundColor": "#ffffff"
    },
    "assetBundlePatterns": [
      "**/*"
    ],
    "ios": {
      "supportsTablet": true,
      "googleServicesFile": "./GoogleService-Info.plist"
    },
    "android": {
      "adaptiveIcon": {
        "foregroundImage": "./assets/adaptive-icon.png",
        "backgroundColor": "#ffffff"
      },
      "googleServicesFile": "./google-services.json",
      "package": "......"
    },
    "web": {
      "favicon": "./assets/favicon.png"
    },
    "plugins": [
      "@react-native-firebase/app",
      "@react-native-firebase/auth",
      "expo-build-properties",
      [
        "expo-location",
        {
          "locationAlwaysAndWhenInUsePermission": "Allow $(PRODUCT_NAME) to use your location."
        }
      ],
      [
        "expo-build-properties",
        {
          "ios": {
            "useFrameworks": "static"
          }
        }
      ],
      [
        "expo-image-picker",
        {
          "photosPermission": "The app accesses your photos to let you share them with your friends."
        }
      ],
      [
        "react-native-fbsdk-next",
        {
         "appID": "myappid",
         "clientToken": "myclienttoken",
         "displayName": "myappdisplayname",
         "scheme": "myappscheme"
       }
      ]
    ],
    "extra": {
      "eas": {
        "projectId": "......"
      }
    }
  }
}
mikehardy commented 5 months ago

Fascinating. The plugin is in there! I dunno. Well, at least it can't crash now, thanks for testing and reporting back (I saw the comment on the PR, much appreciated)