thebergamo / react-native-fbsdk-next

MIT License
674 stars 167 forks source link

[expo][Android] Crash if the plugin is not enabled #395

Closed Nek- closed 1 year ago

Nek- commented 1 year ago

🐛 Bug Report

It is a problem because you may want to enable or disable Facebook integration at build time, not install time. It is also extremely disturbing for newcomers to have the android app crash while the iOS app does not.

To Reproduce

  1. Install react-native-fbsdk-next
  2. Build
  3. iOS is OK, Android crashes

Expected Behavior

No crash if the plugin is not enabled

mikehardy commented 1 year ago

A crash without a stacktrace is not a valid report - we have no information to help. I can tell you, this does not happen in my project, but without details, that is not useful to you either, right?

watch adb logcat, please post stack traces of crashes if you report a crash, thank you

mikehardy commented 1 year ago

don't forget to provide version numbers etc - here's a handy guide: https://stackoverflow.com/help/how-to-ask

Nek- commented 1 year ago

Expo version: ~47.0.12 Package Version: ^11.1.0

Here is the stacktrace:

The SDK has not been initialized, make sure to call
FacebookSdk.sdkInitialize0 first.
at
com.facebook.internal.Validate.sdkInitialized(Validate.kt:1
7)
at
com.facebook.appevents.AppEventsLoggerlmpl.<init>(Api
ventsLoggerlmpl.kt:630)
at
com.facebook.appevents.AppEventsLoggerlmpl.<init>(Api
ventsLoggerlmpl.kt:70)
at
com.facebook.appevents.AppEventsLogger.<init>(AppEve
sLogger.kt:106)
at
com.facebook.appevents.AppEventsLogger.<init>(Unknon
Source:0)
at
com.facebook.appevents.AppEventsLogger$Companion.r
wLogger(AppEventsLogger.kt:357)
at
com.facebook.appevents.AppEventsLogger.newLogger(U nown Source:2)
at
com.facebook.reactnative.androidsdk.FBAppEventsLogge
Module.initialize(FBAppEventsLoggerModule.java:129)
at
com.facebook.react.bridge.ModuleHolder.dolnitialize(Moc
eHolder.java:236)
at
com.facebook.react.bridge.ModuleHolder.markInitializabl‹
ModuleHolder. java:100)
at
com.facebook.react.bridge.NativeModuleRegistry.notifyJS
stancelnitializedNativeModuleRegistry.java:124)
at
com.facebook.react.bridge.CatalystInstancelmp|$2.run(C
lystInstancelmpl.java:452)
atandroid.os.Handler.handleCallback(Handler.java:942)
at android.os. Handler.dispatchMessage(Handler.java:99) at
com.facebook.react.bridge.queue.MessageQueueThreadt
ndler.dispatchMessage(MessageQueueThreadHandler.jav
27)
a android.os.Looper.loopOnce(Looper.java:201)
at android.os.Looper.loop (Looper.java:288)
at
com.facebook.react.bridge.queue.MessageQueueThreadli
pl$4.run(MessageQueueThreadlmpl.java:228)
at java.lang. Thread.run(Thread.java:1012)

It's only in the production version otherwise not fun.

mikehardy commented 1 year ago

The SDK has not been initialized, make sure to call FacebookSdk.sdkInitialize0 first.

mikehardy commented 1 year ago

That error message is always something project-specific. What? I'm not sure without https://stackoverflow.com/help/minimal-reproducible-example and even then, it will require a fix in project

Those errors never lead to changes in this repository so it is not actionable here

Nek- commented 1 year ago

The SDK is initialized via the plugin. My point is that I do not want to enable the plugin. Did you read the only 2 lines I wrote? Let's say crashing is normal then.

mikehardy commented 1 year ago

@Nek- you are reporting a crash that no one else is reporting, where the only other reports were fixed by project-specific code changes.

If you do not want to enable the plugin you should not include the plugin. Including it but not initializing it will lead to a native crash, with the log message indicating the initialization failure as you see.

It is maybe, possibly, I've never tested it, possible to do all sorts of AndroidManifest.xml changes where you disable all the automatic logging that the SDK brings in, but you're using Expo so I suspect that's distasteful. That would be https://developers.facebook.com/docs/app-events/gdpr-compliance

otani-mnbf commented 8 months ago

@mikehardy sorry for mentioning, I'd appreciate if you know how to do something like this. so using expo, if I wanna initialize SDK only for production env app, it would be like this? (since on Android it seems to get initialized automatically)

setting isAutoInitEnabled false by default in app.json

      [
        "react-native-fbsdk-next",
        {
          "appID": "xxxxx",
          "clientToken": "xxxxx",
          "scheme": "fbxxxxx",
          "advertiserIDCollectionEnabled": false,
          "autoLogAppEventsEnabled": false,
          "isAutoInitEnabled": false,
        }
      ]

index.ts

if (Constants.expoConfig?.android?.package === 'production-app') {
  FB_SDK.setAutoLogAppEventsEnabled(true);
  FB_SDK.setAdvertiserTrackingEnabled(true);
  FB_SDK.setAdvertiserIDCollectionEnabled(true);
  FB_SDK.initializeSDK();
}
mikehardy commented 8 months ago

I don't use expo sorry. Seems reasonable but I won't be able to test it and the details/ testing results are the only thing that matters. Try it and see I think

otani-mnbf commented 8 months ago

so true. thanks for replying!