launchdarkly / hello-flutter

Hello LaunchDarkly for Flutter
Other
4 stars 4 forks source link

LaunchDarklyException: LDClient.get() was called before init() #5

Closed tazik561 closed 1 year ago

tazik561 commented 1 year ago

I am running the project but I got this error:

Debug service listening on ws://127.0.0.1:62861/MnfeDkb4qeA=/ws
Syncing files to device sdk gphone64 arm64...
E/AndroidRuntime( 3954): FATAL EXCEPTION: DefaultDispatcher-worker-1
E/AndroidRuntime( 3954): Process: com.example.hello_flutter, PID: 3954
E/AndroidRuntime( 3954): com.launchdarkly.sdk.android.LaunchDarklyException: LDClient.get() was called before init()!
E/AndroidRuntime( 3954):    at com.launchdarkly.sdk.android.LDClient.get(LDClient.java:279)
E/AndroidRuntime( 3954):    at com.launchdarkly.launchdarkly_flutter_client_sdk.LaunchdarklyFlutterClientSdkPlugin$onMethodCall$1$1.invokeSuspend(LaunchdarklyFlutterClientSdkPlugin.kt:360)
E/AndroidRuntime( 3954):    at kotlin.coroutines.jvm.internal.BaseContinuationImpl.resumeWith(ContinuationImpl.kt:33)
E/AndroidRuntime( 3954):    at kotlinx.coroutines.DispatchedTask.run(DispatchedTask.kt:106)
E/AndroidRuntime( 3954):    at kotlinx.coroutines.scheduling.CoroutineScheduler.runSafely(CoroutineScheduler.kt:571)
E/AndroidRuntime( 3954):    at kotlinx.coroutines.scheduling.CoroutineScheduler$Worker.executeTask(CoroutineScheduler.kt:750)
E/AndroidRuntime( 3954):    at kotlinx.coroutines.scheduling.CoroutineScheduler$Worker.runWorker(CoroutineScheduler.kt:678)
E/AndroidRuntime( 3954):    at kotlinx.coroutines.scheduling.CoroutineScheduler$Worker.run(CoroutineScheduler.kt:665)
I/Process ( 3954): Sending signal. PID: 3954 SIG: 9

doctor:

alt@Alis-MacBook-Pro hello-flutter-main % flutter doctor
Doctor summary (to see all details, run flutter doctor -v):
[✓] Flutter (Channel stable, 3.7.0, on macOS 13.0.1 22A400 darwin-arm64, locale en-AM)
[!] Android toolchain - develop for Android devices (Android SDK version 33.0.0)
    ✗ Android license status unknown.
      Run `flutter doctor --android-licenses` to accept the SDK licenses.
      See https://flutter.dev/docs/get-started/install/macos#android-setup for more details.
[✓] Xcode - develop for iOS and macOS (Xcode 14.3.1)
[✓] Chrome - develop for the web
[!] Android Studio (version 2022.1)
    ✗ Unable to find bundled Java version.
[!] Android Studio (version 2022.2)
    ✗ Unable to find bundled Java version.
[!] Android Studio (version 2022.3)
    ✗ Unable to find bundled Java version.
[✓] IntelliJ IDEA Ultimate Edition (version 2023.1.5)
[✓] IntelliJ IDEA Ultimate Edition (version 2023.2)
[✓] IntelliJ IDEA Ultimate Edition (version 2023.1.3)
[✓] IntelliJ IDEA Ultimate Edition (version 2023.2)
[✓] VS Code (version 1.80.2)
[✓] Connected device (3 available)
[✓] HTTP Host Availability
tanderson-ld commented 1 year ago

Hi @tazik561 , thank you for reporting this. Several users have been seeing this issue intermittently. We made a fix for a similar issue about 2 months ago in version 2.0.2 of our SDK that helped some users. Others still report it. Would you mind answering a few questions?

1) What version of launchdarkly_flutter_client_sdk resolved? Please check if it is resolving to at least 2.0.2. 2) Do you see this issue 100% of the time? If not, approximately what frequency?

Thank you!

tazik561 commented 1 year ago

I am using launchdarkly_flutter_client_sdk: ^2.0.3 and I always see this issue when I want to use it.

I checked 2.0.2 and I got same error.

E/DartMessenger( 5322): Uncaught exception in binary message listener
E/DartMessenger( 5322): com.launchdarkly.sdk.android.LaunchDarklyException: LDClient.get() was called before init()!
E/DartMessenger( 5322):     at com.launchdarkly.sdk.android.LDClient.get(LDClient.java:279)
E/DartMessenger( 5322):     at com.launchdarkly.launchdarkly_flutter_client_sdk.LaunchdarklyFlutterClientSdkPlugin.onMethodCall(LaunchdarklyFlutterClientSdkPlugin.kt:445)
E/DartMessenger( 5322):     at io.flutter.plugin.common.MethodChannel$IncomingMethodCallHandler.onMessage(MethodChannel.java:258)
E/DartMessenger( 5322):     at io.flutter.embedding.engine.dart.DartMessenger.invokeHandler(DartMessenger.java:295)
E/DartMessenger( 5322):     at io.flutter.embedding.engine.dart.DartMessenger.lambda$dispatchMessageToQueue$0$io-flutter-embedding-engine-dart-DartMessenger(DartMessenger.java:322)
E/DartMessenger( 5322):     at io.flutter.embedding.engine.dart.DartMessenger$$ExternalSyntheticLambda0.run(Unknown Source:12)
E/DartMessenger( 5322):     at android.os.Handler.handleCallback(Handler.java:942)
E/DartMessenger( 5322):     at android.os.Handler.dispatchMessage(Handler.java:99)
E/DartMessenger( 5322):     at android.os.Looper.loopOnce(Looper.java:201)
E/DartMessenger( 5322):     at android.os.Looper.loop(Looper.java:288)
E/DartMessenger( 5322):     at android.app.ActivityThread.main(ActivityThread.java:7850)
E/DartMessenger( 5322):     at java.lang.reflect.Method.invoke(Native Method)
E/DartMessenger( 5322):     at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:548)
E/DartMessenger( 5322):     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:936)
E/flutter ( 5322): [ERROR:flutter/runtime/dart_vm_initializer.cc(41)] Unhandled Exception: MissingPluginException(No implementation found for method allFlags on channel launchdarkly_flutter_client_sdk)
E/flutter ( 5322): #0      MethodChannel._invokeMethod (package:flutter/src/services/platform_channel.dart:308:7)
E/flutter ( 5322): <asynchronous suspension>
E/flutter ( 5322): #1      MethodChannel.invokeMapMethod (package:flutter/src/services/platform_channel.dart:510:43)
E/flutter ( 5322): <asynchronous suspension>
E/flutter ( 5322): #2      LDClient.allFlags (package:launchdarkly_flutter_client_sdk/launchdarkly_flutter_client_sdk.dart:275:41)
E/flutter ( 5322): <asynchronous suspension>
E/flutter ( 5322): #3      FeatureFlagServiceMobile.getAllFlags (package:rr_launchy/utils/feature_flag_service_mobile.dart:34:39)
E/flutter ( 5322): <asynchronous suspension>
E/flutter ( 5322): #4      FeatureFlagServiceMobile._launchDarklyInit.<anonymous closure> (package:rr_launchy/utils/feature_flag_service_mobile.dart:28:22)
E/flutter ( 5322): <asynchronous suspension>
E/flutter ( 5322): 
D/EGL_emulation( 5322): app_time_stats: avg=5782.66ms min=10.26ms max=17192.85ms count=3
tanderson-ld commented 1 year ago

Well that's no good. I tested the hello-flutter app earlier today and it worked on my side. Do you have any feature flags created and enabled for the mobile clients? I wonder if an unauthorized error is causing init to fail for some reason. When you create the flag there is a checkbox. See the image below.

Otherwise, is the emulator especially slow? Curious if this bug occurs more depending on machine performance.

image

tanderson-ld commented 1 year ago

I was on Flutter Stable 3.7.7 if that helps.

tazik561 commented 1 year ago

I have found the issue :

I had this config: builder.kind('My user Name', '22222222-d216-222-b83e-******');

I added my username instead of the key and my username had a space between its word. I changed to: builder.kind(bbhbhb', '22222222-d216-222-b83e-******');

and now it is ok . bbhbhbis dummy key and with dummy key it is working.

tanderson-ld commented 1 year ago

Great! We should improve our logging in those situations. I'll take a note.