Issue:
App crashes on FB ad with deferred link clicked on some OEMs like Oppo, with the error Methods marked with @UiThread must be executed on the main thread.
Version used:
flutter_facebook_sdk: 0.0.5
Full error log:
log
2021-10-27 00:24:10.419 27751-27800/? E/AndroidRuntime: FATAL EXCEPTION: AsyncTask #4
Process: com.bluepad.android, PID: 27751
java.lang.RuntimeException: Methods marked with @UiThread must be executed on the main thread. Current thread: AsyncTask #4
at io.flutter.embedding.engine.FlutterJNI.ensureRunningOnMainThread(FlutterJNI.java:992)
at io.flutter.embedding.engine.FlutterJNI.dispatchPlatformMessage(FlutterJNI.java:736)
at io.flutter.embedding.engine.dart.DartMessenger.send(DartMessenger.java:72)
at io.flutter.embedding.engine.dart.DartExecutor$DefaultBinaryMessenger.send(DartExecutor.java:363)
at io.flutter.embedding.engine.dart.DartExecutor.send(DartExecutor.java:168)
at io.flutter.plugin.common.EventChannel$IncomingStreamRequestHandler$EventSinkImplementation.success(EventChannel.java:221)
at saad.farhan.flutter_facebook_sdk.FlutterFacebookSdkPlugin$initFbSdk$1.onDeferredAppLinkDataFetched(FlutterFacebookSdkPlugin.kt:201)
at com.facebook.applinks.AppLinkData.fetchDeferredAppLinkFromServer(AppLinkData.java:248)
at com.facebook.applinks.AppLinkData.access$000(AppLinkData.java:50)
at com.facebook.applinks.AppLinkData$1.run(AppLinkData.java:151)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1167)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:641)
at java.lang.Thread.run(Thread.java:764)
File & code line responsible:
File path: flutter_facebook_sdk/android/src/main/kotlin/saad/farhan/flutter_facebook_sdk/FlutterFacebookSdkPlugin.kt
Line no: 201
Method: initFbSdk
Solution:
Just call the @UIThread marked code in ui-thread. Maybe like below-
Issue: App crashes on FB ad with deferred link clicked on some OEMs like Oppo, with the error
Methods marked with @UiThread must be executed on the main thread
.Version used: flutter_facebook_sdk: 0.0.5
Full error log:
log
2021-10-27 00:24:10.419 27751-27800/? E/AndroidRuntime: FATAL EXCEPTION: AsyncTask #4 Process: com.bluepad.android, PID: 27751 java.lang.RuntimeException: Methods marked with @UiThread must be executed on the main thread. Current thread: AsyncTask #4 at io.flutter.embedding.engine.FlutterJNI.ensureRunningOnMainThread(FlutterJNI.java:992) at io.flutter.embedding.engine.FlutterJNI.dispatchPlatformMessage(FlutterJNI.java:736) at io.flutter.embedding.engine.dart.DartMessenger.send(DartMessenger.java:72) at io.flutter.embedding.engine.dart.DartExecutor$DefaultBinaryMessenger.send(DartExecutor.java:363) at io.flutter.embedding.engine.dart.DartExecutor.send(DartExecutor.java:168) at io.flutter.plugin.common.EventChannel$IncomingStreamRequestHandler$EventSinkImplementation.success(EventChannel.java:221) at saad.farhan.flutter_facebook_sdk.FlutterFacebookSdkPlugin$initFbSdk$1.onDeferredAppLinkDataFetched(FlutterFacebookSdkPlugin.kt:201) at com.facebook.applinks.AppLinkData.fetchDeferredAppLinkFromServer(AppLinkData.java:248) at com.facebook.applinks.AppLinkData.access$000(AppLinkData.java:50) at com.facebook.applinks.AppLinkData$1.run(AppLinkData.java:151) at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1167) at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:641) at java.lang.Thread.run(Thread.java:764)File & code line responsible: File path: flutter_facebook_sdk/android/src/main/kotlin/saad/farhan/flutter_facebook_sdk/FlutterFacebookSdkPlugin.kt Line no: 201 Method: initFbSdk
Solution: Just call the @UIThread marked code in ui-thread. Maybe like below-
sample
Handler(Looper.getMainLooper()).post { eventSink!!.success(deepLinkUrl) }