launchdarkly / flutter-client-sdk

LaunchDarkly Client-side SDK for Flutter mobile applications
Other
15 stars 17 forks source link

[ERROR:flutter/runtime/dart_vm_initializer.cc(41)] Unhandled Exception: MissingPluginException(No implementation found for method start on channel launchdarkly_flutter_client_sdk) #57

Closed mattbajorek closed 11 months ago

mattbajorek commented 12 months ago

Describe the bug .start method immediately errors out with MissingPluginException on Android for both simulator and physical device. Is there an extra SDK integration needed?

To reproduce

  1. Add launchdarkly_flutter_client_sdk: ^3.0.1 to pubspec.yaml
  2. After WidgetsFlutterBinding.ensureInitialized(); add:
final ldConfig = LDConfigBuilder(launchDarklyKey, AutoEnvAttributes.Enabled).build();
final ldContext = LDContextBuilder().build();
await LDClient.start(ldConfig, ldContext);

Expected behavior A clear and concise description of what you expected to happen.

Logs E/flutter (17494): [ERROR:flutter/runtime/dart_vm_initializer.cc(41)] Unhandled Exception: MissingPluginException(No implementation found for method start on channel launchdarkly_flutter_client_sdk) E/flutter (17494): #0 MethodChannel._invokeMethod (package:flutter/src/services/platform_channel.dart:308:7) E/flutter (17494): E/flutter (17494): #1 LDClient.startWithContext (package:launchdarkly_flutter_client_sdk/launchdarkly_flutter_client_sdk.dart:106:5) E/flutter (17494):

Flutter version >=3.0.6 <4.0.0

SDK version 4.0.1 and 2.1.0

OS/platform Android

tanderson-ld commented 12 months ago

Hi @mattbajorek , the current version of our Flutter SDK wraps our iOS and Android SDKs as native plugins. This sounds like a good place to start the investigation. Have you been able to run our hello-flutter repo?

tanderson-ld commented 12 months ago

Can you confirm the presence of the android folder in the Flutter Plugins section of your project? (This is a Flutter project opened in Android Studio).

image

mattbajorek commented 11 months ago

If these are wrappers are there any specific Android or iOS changes needed? I tried following the Android documents by adding:

implementation 'com.launchdarkly:launchdarkly-android-client-sdk:5.0.0'

to app/build.gradle and

import com.launchdarkly.sdk.*
import com.launchdarkly.sdk.android.*

to MainActivity.kt with no avail.

tanderson-ld commented 11 months ago

You shouldn't need to make any iOS / Android file changes. I just wanted to confirm the dependency that was fetched does have the native folders.

tanderson-ld commented 11 months ago

Have you been able to run our hello-flutter repo?

mattbajorek commented 11 months ago

I am able to run the hello-flutter repo. I found the issue for anyone else is struggling with this. The LDContextBuilder must have a kind set. By following the example with builder.kind('user', 'user-key-123abc'); the issue went away.

Is there a way to initially not have a kind and then add a kind as user information is provided dynamically?

tanderson-ld commented 11 months ago

Ah, I see what happened. We have an existing discrepancy between our Android and iOS SDK where the Android SDK must be provided a non-empty context with a key. We plan to fix the bug Android side when time permits. That error is very cryptic.

I recommend using an anonymous context for the period of time where you have no user information.

https://docs.launchdarkly.com/sdk/features/anonymous#flutter

tanderson-ld commented 11 months ago

Thank you for tracking down the cause. I missed that a kind was missing in the original code snippet. Issue has been logged internally as 224717.

mattbajorek commented 11 months ago

@tanderson-ld thank you for the update. I added:

ldContextBuilder.kind('user', 'user-key-123abc').anonymous(true);

The plugin no longer crashes, however when fetching feature flags for example:

var result = await LDClient.boolVariation(featureFlag, true);

The result value is always false even with the default and even though the dashboard is serving true. Any ideas on why this is happening?

tanderson-ld commented 11 months ago

Have you turned the targeting for that flag to On? This is a common culprit.

image

mattbajorek commented 11 months ago

Yes we have it on. We can validate that on the web SDK. We have multiple feature flags and they all come back false for Flutter, but true for web. Screenshot 2023-11-20 at 11 32 05 AM Screenshot 2023-11-20 at 11 32 16 AM

mattbajorek commented 11 months ago

Also calling:

final flags = await LDClient.allFlags();

Properly returns all the names of our tags, but all of them are set as false.

tanderson-ld commented 11 months ago

I just tested a killSwitch template locally with the Flutter SDK, and it is working on my machine. Do you have any interesting configurations with respect to network permissions, storage permissioning, VPN? Trying to develop a few more theories.

tanderson-ld commented 11 months ago

Perhaps the wrong environment key copied/pasted?

mattbajorek commented 11 months ago

Ahh I found it. I was using the prod environment key which was setup but the flags weren't set yet. We can close this.

tanderson-ld commented 11 months ago

No worries! We've all been there. If you need other higher level support, you can open a support ticket here. If you run into any more nitty gritty code issues / suspected bugs, feel free to open another issue. Thanks.

Mik77o commented 9 months ago

@tanderson-ld, I confirm this statement you added once: We have an existing discrepancy between our Android and iOS SDK where the Android SDK must be provided a non-empty context with a key. A non-empty value solves this problem. ​