DevCycleHQ / flutter-client-sdk

DevCycle - Flutter Client SDK
https://docs.devcycle.com/
MIT License
12 stars 3 forks source link

Error Android ExceptionInInitializerError #136

Closed rafaelqcosta closed 6 days ago

rafaelqcosta commented 1 month ago

When I build the application, it runs, but when I start the app, it dies shortly after.

Here's the console log: `Launching lib/main_dev.dart on SM A217M in debug mode... Building with Flutter multidex support enabled. ✓ Built build/app/outputs/flutter-apk/app-dev-debug.apk. Connecting to VM Service at ws://127.0.0.1:63469/khw7vSogW5g=/ws D/FRCPlugin(20016): Sending fetchTimeout: 60 I/flutter (20016): AppModule started! W/om.onovomercad(20016): Accessing hidden method Ljava/lang/invoke/MethodHandles$Lookup;->(Ljava/lang/Class;I)V (unsupported, reflection, allowed) I/flutter (20016): -- AuthModule INITIALIZED E/AndroidRuntime(20016): FATAL EXCEPTION: main E/AndroidRuntime(20016): Process: br.com.onovomercado, PID: 20016 E/AndroidRuntime(20016): java.lang.ExceptionInInitializerError E/AndroidRuntime(20016): at com.fasterxml.jackson.databind.ObjectMapper.(ObjectMapper.java:660) E/AndroidRuntime(20016): at com.fasterxml.jackson.databind.ObjectMapper.(ObjectMapper.java:585) E/AndroidRuntime(20016): at com.fasterxml.jackson.databind.json.JsonMapper.(JsonMapper.java:93) E/AndroidRuntime(20016): at com.fasterxml.jackson.databind.json.JsonMapper.(JsonMapper.java:89) E/AndroidRuntime(20016): at com.fasterxml.jackson.databind.json.JsonMapper.builder(JsonMapper.java:114) E/AndroidRuntime(20016): at com.fasterxml.jackson.module.kotlin.ExtensionsKt.jsonMapper(Extensions.kt:33) E/AndroidRuntime(20016): at com.fasterxml.jackson.module.kotlin.ExtensionsKt.jacksonObjectMapper(Extensions.kt:38) E/AndroidRuntime(20016): at com.devcycle.sdk.android.util.JSONMapper.(JSONMapper.kt:7) E/AndroidRuntime(20016): at com.devcycle.sdk.android.api.DVCApiClient.(DVCApiClient.kt:15) E/AndroidRuntime(20016): at com.devcycle.sdk.android.api.Request.(Request.kt:20) E/AndroidRuntime(20016): at com.devcycle.sdk.android.api.DevCycleClient.(DevCycleClient.kt:51) E/AndroidRuntime(20016): at com.devcycle.sdk.android.api.DevCycleClient.(DevCycleClient.kt:34) E/AndroidRuntime(20016): at com.devcycle.sdk.android.api.DevCycleClient$DevCycleClientBuilder.build(DevCycleClient.kt:623) E/AndroidRuntime(20016): at com.devcycle.devcycle_flutter_client_sdk.DevCycleFlutterClientSdkPlugin.onMethodCall(DevCycleFlutterClientSdkPlugin.kt:70) E/AndroidRuntime(20016): at io.flutter.plugin.common.MethodChannel$IncomingMethodCallHandler.onMessage(MethodChannel.java:267) E/AndroidRuntime(20016): at io.flutter.embedding.engine.dart.DartMessenger.invokeHandler(DartMessenger.java:292) E/AndroidRuntime(20016): at io.flutter.embedding.engine.dart.DartMessenger.lambda$dispatchMessageToQueue$0(DartMessenger.java:319) E/AndroidRuntime(20016): at io.flutter.embedding.engine.dart.DartMessenger.$r8$lambda$2j2MERcK825A5j1fv5sZ7xB2Iuo(DartMessenger.java:0) E/AndroidRuntime(20016): at io.flutter.embedding.engine.dart.DartMessenger$$ExternalSyntheticLambda0.run(R8$$SyntheticClass:0) E/AndroidRuntime(20016): at android.os.Handler.handleCallback(Handler.java:938) E/AndroidRuntime(20016): at android.os.Handler.dispatchMessage(Handler.java:99) E/AndroidRuntime(20016): at android.os.Looper.loopOnce(Looper.java:226) E/AndroidRuntime(20016): at android.os.Looper.loop(Looper.java:313) E/AndroidRuntime(20016): at android.app.ActivityThread.main(ActivityThread.java:8669) E/AndroidRuntime(20016): at java.lang.reflect.Method.invoke(Native Method) E/AndroidRuntime(20016): at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:571) E/AndroidRuntime(20016): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1135) E/AndroidRuntime(20016): Caused by: java.lang.RuntimeException: java.lang.NoSuchMethodException: com.fasterxml.jackson.databind.SerializationFeature.values [] E/AndroidRuntime(20016): at java.lang.Enum.enumValues(Enum.java:315) E/AndroidRuntime(20016): at java.lang.Enum.-$$Nest$smenumValues(Unknown Source:0) E/AndroidRuntime(20016): at java.lang.Enum$1.create(Enum.java:322) E/AndroidRuntime(20016): at java.lang.Enum$1.create(Enum.java:320) E/AndroidRuntime(20016): at libcore.util.BasicLruCache.get(BasicLruCache.java:63) E/AndroidRuntime(20016): at java.lang.Enum.getSharedConstants(Enum.java:334) E/AndroidRuntime(20016): at java.lang.Class.getEnumConstantsShared(Class.java:4036) E/AndroidRuntime(20016): at java.lang.Class.getEnumConstants(Class.java:4022) E/AndroidRuntime(20016): at com.fasterxml.jackson.databind.cfg.MapperConfig.collectFeatureDefaults(MapperConfig.java:108) E/AndroidRuntime(20016): at com.fasterxml.jackson.databind.SerializationConfig.(SerializationConfig.java:41) E/AndroidRuntime(20016): ... 27 more E/AndroidRuntime(20016): Caused by: java.lang.NoSuchMethodException: com.fasterxml.jackson.databind.SerializationFeature.values [] E/AndroidRuntime(20016): at java.lang.Class.getMethod(Class.java:2937) E/AndroidRuntime(20016): at java.lang.Class.getDeclaredMethod(Class.java:2914) E/AndroidRuntime(20016): at java.lang.Enum.enumValues(Enum.java:312) E/AndroidRuntime(20016): ... 36 more I/Process (20016): Sending signal. PID: 20016 SIG: 9 Lost connection to device.

Exited. `

Dependency from pubspec.yaml: devcycle_flutter_client_sdk: ^1.7.3

kaushalkapasi commented 1 month ago

Hey @rafaelqcosta, thanks for opening this issue!

We'll investigate and let you know once we have a better idea of what is causing this error.

rafaelqcosta commented 4 weeks ago

The error occurs when in "DevCycleClientBuilder().sdkKey(F().devcycleKey).user(user).options(options).build();"

Future<void> init(UserEntity? userLogged) async {
    try {
      if (userLogged != null) {
        DevCycleUser user = DevCycleUserBuilder()
            .userId(userLogged.id.toString())
            .email(userLogged.email)
            .name(userLogged.name)
            .build();

        final options = DevCycleOptionsBuilder().logLevel(LogLevel.error).build();

        DevCycleClient devCycleClient =
            DevCycleClientBuilder().sdkKey(F().devcycleKey).user(user).options(options).build();

        devCycleClient.onInitialized(([error]) async {
          if (error == null) {
            await getAllVariables(devCycleClient);
            changeTheme();
          }
        });
      }
    } catch (e) {
      debugPrint('Erro no devcycle: $e');
    }
  } 

The sdkKey, user, and options data are correct image

Apparently the library is having difficulties accessing SharedPreferences. I/DVCSharedPrefs(23838): ANONYMOUS_USER_ID could not be found in SharedPreferences file: 2131623946 W/om.onovomercad(23838): Accessing hidden method Ljava/lang/invoke/MethodHandles$Lookup;->(Ljava/lang/Class;I)V (unsupported, reflection, allowed)

rafaelqcosta commented 4 weeks ago

Another detail that might be relevant is that apparently the error started occurring after we had to change the Gradle settings as per the official Flutter documentation: https://docs.flutter.dev/release/breaking-changes/flutter-gradle-plugin-apply.

kaushalkapasi commented 4 weeks ago

Hey @rafaelqcosta, thanks for the additional context. We'll verify the existing SDK version with the gradle changes you shared and make the appropriate changes to fix the issue!

kaushalkapasi commented 4 weeks ago

@rafaelqcosta one other question, could you share the versions of:

rafaelqcosta commented 3 weeks ago

Doctor summary (to see all details, run flutter doctor -v): [✓] Flutter (Channel stable, 3.19.5, on macOS 14.0 23A344 darwin-x64, locale en-BR) [✓] Android toolchain - develop for Android devices (Android SDK version 34.0.0) [✓] Xcode - develop for iOS and macOS (Xcode 15.3) [✓] Chrome - develop for the web [✓] Android Studio (version 2023.2) [✓] VS Code (version 1.88.1) [✓] Connected device (4 available) [✓] Network resources

• No issues found!

minSdkVersion 21 it's ok

rafaelqcosta commented 3 weeks ago

settings.gradle: plugins { id "dev.flutter.flutter-plugin-loader" version "1.0.0" id "com.android.application" version '7.4.2' apply false id "org.jetbrains.kotlin.android" version "1.9.22" apply false }

kaushalkapasi commented 3 weeks ago

Hey @rafaelqcosta we've released a new version of the Flutter SDK which also includes an update to the underlying Android SDK, could you test out v1.7.5 and let me know if you are still seeing the issue?

rafaelqcosta commented 3 weeks ago

Version 1.7.4 wasn't enough to solve the Android issues, as I'm still experiencing the same errors. I debugged in release mode and noticed that the error occurs exactly on line 70 of the DevCycleFlutterClientSdkPlugin.kt file, at client = clientBuilder.build(). However, it was working fine for iOS. But version 1.7.5, where changes were made for iOS, caused a new error.

Failed to build iOS app Could not build the precompiled application for the device. Swift Compiler Error (Xcode): Value of type 'DevCycleOptions.OptionsBuilder' has no member 'apiProxyUrl' /Users/rafael.costa/.pub-cache/hosted/pub.dev/devcycle_flutter_client_sdk-1.7.5/ios/Classes/SwiftDevCycleFlutterClientSdkPlugin.swift:193:23 SwiftDevCycleFlutterClientSdkPlugin.swift:193

Swift Compiler Error (Xcode): Value of type 'DevCycleOptions.OptionsBuilder' has no member 'eventsApiProxyUrl' /Users/rafael.costa/.pub-cache/hosted/pub.dev/devcycle_flutter_client_sdk-1.7.5/ios/Classes/SwiftDevCycleFlutterClientSdkPlugin.swift:197:23 SwiftDevCycleFlutterClientSdkPlugin.swift:197 2

Error launching application on iPhone.

kaushalkapasi commented 3 weeks ago

Hey @rafaelqcosta sorry for that. I'll revert the latest version and publish a new one with the fix for the iOS issues. In the meantime, we'll keep investigating the Android issues. Thanks!

rafaelqcosta commented 3 weeks ago

Continuing with the topic. How do you debug native code with breakpoints? I've been generating a release APK and importing the Android project from my main app to do this, but it's a time-consuming process. Is there another way?

kaushalkapasi commented 3 weeks ago

We haven't found a better way to debug Android native code via flutter. We're also following the same process you described.

And to confirm you are seeing this behaviour with a physical device? We haven't been able to reproduce the error on an emulator.

Also, I made a mistake earlier, one of my colleagues confirmed that our Flutter SDK requires a minSDKVersion of Android 23 or 26, not 21 (due to a limitation of okhttp on Android).

kaushalkapasi commented 3 weeks ago

Hey @rafaelqcosta we've published a new version of the Flutter SDK (v1.8.0) that includes the fix for the iOS changes that had resulted in the issue and it also bumps to use the latest version of our Android SDK.

We've been unable to reproduce the issue you raised, would it be possible for you to create a minimum repro that we could clone and investigate the issue further?

Thanks!