Skip to content

Exception in Java code called through JNI: java.lang.NoSuchMethodError #3030

Closed
@kamilkarp

Description

@kamilkarp

Platform

Flutter Mobile Android

Obfuscation

Disabled

Debug Info

Disabled

Doctor

[✓] Flutter (Channel stable, 3.27.4, on macOS 14.6 23G80 darwin-arm64, locale en-PL)
    • Flutter version 3.27.4 on channel stable at /Users/kamil/fvm/versions/3.27.4
    • Upstream repository https://github.com/flutter/flutter.git
    • Framework revision d8a9f9a52e (5 months ago), 2025-01-31 16:07:18 -0500
    • Engine revision 82bd5b7209
    • Dart version 3.6.2
    • DevTools version 2.40.3

[✓] Android toolchain - develop for Android devices (Android SDK version 35.0.0-rc2)
    • Android SDK at /Users/kamil/Library/Android/sdk
    • Platform android-35, build-tools 35.0.0-rc2
    • ANDROID_HOME = /Users/kamil/Library/Android/sdk
    • Java binary at: /opt/homebrew/opt/openjdk@17/bin/java
    • Java version OpenJDK Runtime Environment Homebrew (build 17.0.14+0)
    • All Android licenses accepted.

[✓] Xcode - develop for iOS and macOS (Xcode 16.2)
    • Xcode at /Applications/Xcode.app/Contents/Developer
    • Build 16C5032a
    • CocoaPods version 1.16.2

[✓] Chrome - develop for the web
    • Chrome at /Applications/Google Chrome.app/Contents/MacOS/Google Chrome

[✓] Android Studio (version 2024.2)
    • Android Studio at /Applications/Android Studio.app/Contents
    • Flutter plugin can be installed from:
      🔨 https://plugins.jetbrains.com/plugin/9212-flutter
    • Dart plugin can be installed from:
      🔨 https://plugins.jetbrains.com/plugin/6351-dart
    • Java version OpenJDK Runtime Environment (build 21.0.3+-79915917-b509.11)

[✓] VS Code (version 1.94.0)
    • VS Code at /Applications/Visual Studio Code.app/Contents
    • Flutter extension version 3.112.0

[✓] Connected device (5 available)
    • moto g 5G plus (mobile)         • ZY22BJ4GLS            • android-arm64  • Android 11 (API 30)
    • sdk gphone64 arm64 (mobile)     • emulator-5554         • android-arm64  • Android 14 (API 34) (emulator)
    • macOS (desktop)                 • macos                 • darwin-arm64   • macOS 14.6 23G80 darwin-arm64
    • Mac Designed for iPad (desktop) • mac-designed-for-ipad • darwin         • macOS 14.6 23G80 darwin-arm64
    • Chrome (web)                    • chrome                • web-javascript • Google Chrome 137.0.7151.122

[✓] Network resources
    • All expected network resources are available.

• No issues found!

Version

9.1.0

Steps to Reproduce

Run app with this Sentry config:

  @override
  Future<void> initWithAppRun(
    FutureOr<void> Function() appRunner,
  ) async {
    return SentryFlutter.init(
      (options) {
        options
          ..dsn = _urlProvider.sentryDsnUrl
          ..replay.onErrorSampleRate = 1.0
          ..replay.sessionSampleRate = 1.0
          ..screenshotQuality = SentryScreenshotQuality.medium
          ..attachScreenshot = true
          ..privacy.maskAllImages = false
          ..privacy.maskAllText = false
          ..privacy.maskAssetImages = false
          ..privacy.unmask<CachedNetworkImage>()
          ..privacy.mask<EditableText>()
          ..enableLogs = true
          ..environment = _getEnvironmentName()
          ..sendDefaultPii = true
          ..enableTextScaleChangeBreadcrumbs = true
          ..enableWindowMetricBreadcrumbs = true
          ..enableMemoryPressureBreadcrumbs = true
          ..tracesSampleRate = 1.0
          ..sampleRate = 1.0
          ..maxRequestBodySize = MaxRequestBodySize.small;
      },
      appRunner: () => appRunner(),
    );
  }
runApp(
    SentryWidget(
      child: MyApp(),
    ),
  );

Expected Result

Session Replays should be sent with Android device.

Actual Result

For some reason Android devices do not send session replays to Sentry. iOS works correctly. Strangely, when I run my app in debug mode with simulator, replays are sent correctly.

I've checked real device(with production build) with Logcat and whenever I run the app I'm getting this error:

[ERROR:flutter/runtime/dart_isolate.cc(1321)] Unhandled exception:
Exception in Java code called through JNI: java.lang.NoSuchMethodError: no non-static method "Lio/sentry/flutter/SentryFlutterPlugin$Companion;.<init>(Lkotlin/jvm/internal/DefaultConstructorMarker;)V"

java.lang.NoSuchMethodError: no non-static method "Lio/sentry/flutter/SentryFlutterPlugin$Companion;.<init>(Lkotlin/jvm/internal/DefaultConstructorMarker;)V"


#0      Jni.throwException (package:jni/src/jni.dart:195)
#1      _check (package:jni/src/accessors.dart:17)
#2      JniIdLookupResultMethods.methodID (package:jni/src/accessors.dart:88)
#3      GlobalJniEnv.GetMethodID (package:jni/src/third_party/global_env_extensions.dart:220)
#4      JConstructorId._.<anonymous closure> (package:jni/src/jclass.dart:151)
#5      using (package:ffi/src/arena.dart:124)
#6      JConstructorId._ (package:jni/src/jclass.dart:149)
#7      JClass.constructorId (package:jni/src/jclass.dart:20)
#8      SentryFlutterPlugin$Companion._id_new$ (package:sentry_flutter/src/native/java/binding.dart:958)
#9      new SentryFlutterPlugin$Companion (package:sentry_flutter/src/native/java/binding.dart)
#10     _AndroidNativeReplayWorker._handleCommandsToIsolate (package:sentry_flutter/src/native/java/android_replay_recorder.dart:143)
#11     _AndroidNativeReplayWorker._startRemoteIsolate (package:sentry_flutter/src/native/java/android_replay_recorder.dart:186)
#12     _delayEntrypointInvocation.<anonymous closure> (dart:isolate-patch/isolate_patch.dart:300)
#13     _RawReceivePort._handleMessage (dart:isolate-patch/isolate_patch.dart:184)

I see that ReplayWorker is mentioned there. Any ideas why it's happening?

Are you willing to submit a PR?

None

Metadata

Metadata

Assignees

No one assigned

    Type

    Projects

    Status

    No status

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions