flutterfire icon indicating copy to clipboard operation
flutterfire copied to clipboard

FlutterJNI.loadLibrary called more than once

Open penhorwood opened this issue 1 year ago • 38 comments

Bug report

Describe the bug The FlutterJNI.loadLibrary is called twice.

Error message displayed in the Debug Console W/FlutterJNI(10613): FlutterJNI.loadLibrary called more than once W/FlutterJNI(10613): FlutterJNI.prefetchDefaultFontManager called more than once

Steps to reproduce

Steps to reproduce the behavior:

  1. Start a simple Flutter App with FirebaseMessaging
  2. Use the FirebaseMessaging.onBackgroundMessage( backgroundRouter );
  3. Run the App in Debug or Release mode

Expected behavior

The FlutterJNI.loadLibrary will only be called once.

Sample project

https://github.com/penhorwood/firetwice

Flutter doctor

Run flutter doctor and paste the output below:

Click To Expand
Doctor summary (to see all details, run flutter doctor -v):
[√] Flutter (Channel stable, 3.3.8, on Microsoft Windows [Version 10.0.19044.2251], locale en-US)
[√] Android toolchain - develop for Android devices (Android SDK version 30.0.3)
[√] Android Studio (version 2021.2)
[√] Connected device (1 available)
[√] HTTP Host Availability



penhorwood avatar Nov 19 '22 03:11 penhorwood

Closing as duplicate of https://github.com/firebase/flutterfire/issues/9912. Please upgrade plugin version to latest to see the fix.

darshankawar avatar Nov 21 '22 10:11 darshankawar

This is not a duplicate as this is still happening

I have all of the latest fixes but the duplicate Flutter.JNI.loadLibrary is still loading twice

penhorwood avatar Nov 24 '22 12:11 penhorwood

Here are two screenshots of my app loading today - 11/24/2022 One is with the onBackgroundMessage used the other with that line commented out. You can see that make the difference in whether Flutter.JNI.loadLibrary loads twice.

image

2nd without onBackgroundMessage

image

penhorwood avatar Nov 24 '22 12:11 penhorwood

Thanks for the feedback @penhorwood Can you please provide a complete minimal reproducible code sample in text format that shows the behavior ?

darshankawar avatar Nov 28 '22 12:11 darshankawar

I have a complete example here https://github.com/penhorwood/firetwice. That is my minimal reproducible code sample. If you want me to post the files here I can.

penhorwood avatar Nov 28 '22 18:11 penhorwood

Thanks for the update. I looked at the repo you provided above and observed that the background handler is not the topmost method, unlike in the plugin example.

https://github.com/firebase/flutterfire/blob/26087bb2d1747eb5db82c98424b6d63071137529/packages/firebase_messaging/firebase_messaging/example/lib/main.dart#L47

Also, try to have the @pragma('vm:entry-point') annotation as mentioned in the comments above the declaration and see if it helps in your case.

darshankawar avatar Nov 29 '22 12:11 darshankawar

I followed your instructions. No change on the results.

W/FlutterJNI( 5559): FlutterJNI.loadLibrary called more than once W/FlutterJNI( 5559): FlutterJNI.prefetchDefaultFontManager called more than once

You can view my changes on the repo.

penhorwood avatar Nov 29 '22 22:11 penhorwood

Just an FYI. I think when it says top most method it is talking about as in not part of a class. Where it is in main.dart should not matter but that is just my current understanding. I could be wrong.

penhorwood avatar Nov 29 '22 22:11 penhorwood

Thanks for the update. Using the sample repo, I do see the same behavior as reported. Keeping it open for team's attention and insights.

darshankawar avatar Nov 30 '22 06:11 darshankawar

Thanks for the report, I'm investigating this

This error is caused by line 159 in FlutterFirebaseMessagingBackgroundExecutor.java. Not sure if we can intervene here.

Lyokone avatar Dec 02 '22 10:12 Lyokone

Seeing the same thing here

mark8044 avatar Dec 20 '22 04:12 mark8044

D/FlutterGeolocator(29054): Creating service. D/FlutterGeolocator(29054): Binding to location service. D/FlutterLocationService(29054): Creating service. D/FlutterLocationService(29054): Binding to location service. D/FlutterGeolocator(29054): Flutter engine connected. Connected engine count 1 W/FlutterJNI(29054): FlutterJNI.loadLibrary called more than once W/FlutterJNI(29054): FlutterJNI.prefetchDefaultFontManager called more than once W/FlutterJNI(29054): FlutterJNI.init called more than once D/FlutterGeolocator(29054): Flutter engine connected. Connected engine count 2

sadaqatdev avatar Jan 03 '23 06:01 sadaqatdev

I am also facing the same issue. @darshankawar Any progress on this?

pushpendraKh avatar Jan 29 '23 06:01 pushpendraKh

this issue happened to me. occurs when the application is first run only and in the app foreground.

after receiving/displaying notification in foreground then after a few seconds the app got crashed (force close/Wait & Ok Prompt). if i choose Wait, the app and notification (fcm) running smoothly.

I've tried various ways to overcome this issue, but no significant result.

please, any workaround for this issue?

library use :

firebase_messaging: 14.2.2 firebase_core: 2.5.0

flutter doctor :

[√] Flutter (Channel stable, 3.7.3, on Microsoft Windows [Version 10.0.18363.592], locale en-US)
[√] Windows Version (Installed version of Windows is version 10 or higher)
[√] Android toolchain - develop for Android devices (Android SDK version 30.0.3)
[√] Chrome - develop for the web

Error Log : Attempted to start a duplicate background isolate. Returning

eudorolshop avatar Feb 10 '23 05:02 eudorolshop

@eudorolshop that seems like a different issue, WDYT?

@Lyokone is still happening to me on:

  firebase_core: 2.4.1
  firebase_crashlytics: 3.0.11
  firebase_analytics: 10.1.0
  firebase_messaging: 14.2.1

And on:

  firebase_core: 2.5.0
  firebase_crashlytics: 3.0.12
  firebase_analytics: 10.1.1
  firebase_messaging: 14.2.2

danielgomezrico avatar Feb 14 '23 22:02 danielgomezrico

@eudorolshop that seems like a different issue, WDYT?

@danielgomezrico sometimes i got this issue too, FlutterJNI.loadlibrary called more than once. at least related to this.

eudorolshop avatar Feb 18 '23 03:02 eudorolshop

this cause by location plugin

sadaqatdev avatar Feb 18 '23 08:02 sadaqatdev

It's still happening to me on firebase_messaging: ^14.2.4 firebase_core: ^2.6.1

firebase_messaging_issue

cindyha avatar Feb 21 '23 10:02 cindyha

The same happens to me when the app is in its first launch. I'm using firebase_messaging: ^14.1.1 image

lybur avatar Feb 22 '23 06:02 lybur

Maybe this is related to this other issue?

  • https://github.com/firebase/flutterfire/issues/9689

danielgomezrico avatar Feb 22 '23 15:02 danielgomezrico

Any movement on this bug? This is still happening to me with firebase_messaging: 14.5.0

penhorwood avatar May 08 '23 04:05 penhorwood

Same here. Any updates on this issue?

juliavi avatar Jul 01 '23 16:07 juliavi

@darshankawar

This issue is serous danger! I investigate it , and i come with: 1 - The main isolate called one time in the background 2 - The main isolate thats triggered from the "FCM" going to load the plugins and act normally as a UI isolate, and keep trying render widgets. 3 - When "main" get trigger by FCM notification the "onBackgroundMessage" going to re register it self with another one, (here we got the error ) , and this is why you got just one. 4 - Even if "onBackgroundMessage" handler is not crashed in first time , it will going to call it self in a recursion way

The normal behave : The "FCM" trigger the main isolate but should skip at least run "runapp()", this going to solve the issue if we call "onBackgroundMessage" inside runApp and not directly in the main.

Suggested solution: Provide a way to check which "VM entry point" has called the main. This will provide way to avoid re initiate "onBackgroundMessage" and give the developers options to deal logically on They way.

abdalmonem avatar Jul 24 '23 09:07 abdalmonem

The same happens to me when the app is in its first launch.

  • firebase_core: ^2.15.0
  • firebase_messaging: ^14.6.5
  • firebase_crashlytics: ^3.3.4
Captura de pantalla 2023-08-01 a la(s) 3 20 31 p m

yeikel16 avatar Aug 01 '23 19:08 yeikel16

@yeikel16 i believe we can skip this issue if Dart team add any way to find the name of entry-pointthat ran the main

abdalmonem avatar Aug 02 '23 05:08 abdalmonem

It happens with my app and I am not using firebase messaging. The packages I am using are firebase core, performance and analytics. So I don't think it's an issue on messaging. Probably related to core

milindgoel15 avatar Aug 03 '23 09:08 milindgoel15

I also faced this issue. When I get duplicated push notification in background state then that log is found.

This is my log when I duplicated push notification and not

D/FLTFireMsgReceiver(24096): broadcast received for message W/FlutterJNI(24096): FlutterJNI.loadLibrary called more than once I/ResourceExtractor(24096): Found extracted resources res_timestamp-53-1692196013697 W/FlutterJNI(24096): FlutterJNI.prefetchDefaultFontManager called more than once W/FlutterJNI(24096): FlutterJNI.init called more than once I/FLTFireBGExecutor(24096): Creating background FlutterEngine instance. I/FLTFireMsgService(24096): Service has not yet started, messages will be queued. W/ato.pesca.debu(24096): Accessing hidden method Landroid/os/WorkSource;->add(I)Z (unsupported,test-api, reflection, allowed) W/ato.pesca.debu(24096): Accessing hidden method Landroid/os/WorkSource;->add(ILjava/lang/String;)Z (unsupported,test-api, reflection, allowed) W/ato.pesca.debu(24096): Accessing hidden method Landroid/os/WorkSource;->get(I)I (unsupported, reflection, allowed) W/ato.pesca.debu(24096): Accessing hidden method Landroid/os/WorkSource;->getName(I)Ljava/lang/String; (unsupported, reflection, allowed) D/CompatibilityChangeReporter(24096): Compat change id reported: 160794467; UID 11208; state: ENABLED I/TRuntime.CctTransportBackend(24096): Making request to: https://firebaselogging-pa.googleapis.com/v1/firelog/legacy/batchlog I/FLTFireMsgService(24096): FlutterFirebaseMessagingBackgroundService started! I/TRuntime.CctTransportBackend(24096): Status Code: 200

And this is a log when push notification is not duplicated ( normal state)

D/FLTFireMsgReceiver(26894): broadcast received for message W/ato.pesca.debu(26894): Accessing hidden method Landroid/os/WorkSource;->add(I)Z (unsupported,test-api, reflection, allowed) W/ato.pesca.debu(26894): Accessing hidden method Landroid/os/WorkSource;->add(ILjava/lang/String;)Z (unsupported,test-api, reflection, allowed) W/ato.pesca.debu(26894): Accessing hidden method Landroid/os/WorkSource;->get(I)I (unsupported, reflection, allowed) W/ato.pesca.debu(26894): Accessing hidden method Landroid/os/WorkSource;->getName(I)Ljava/lang/String; (unsupported, reflection, allowed) D/CompatibilityChangeReporter(26894): Compat change id reported: 160794467; UID 11208; state: ENABLED

larsien avatar Aug 16 '23 15:08 larsien

Have same issue. Any success with solving it?

nukeolay avatar Sep 18 '23 13:09 nukeolay

It happens with my app and I am not using firebase messaging. The packages I am using are firebase core, performance and analytics. So I don't think it's an issue on messaging. Probably related to core

That's the separate issue - this issue is for the problem related to onBackgroundMessage - check the opening comment. I suggest creating a separate issue, but check StackOverflow first.

I also faced this issue. When I get duplicated push notification in background state then that log is found.

I suspect this is also a different issue - I have this problem with onBackgroundMessage, but the notifications are arriving only once.

egedib avatar Sep 24 '23 13:09 egedib

Was facing the same problem, After writing @pragma('vm:entry-point') before the top level function it fixed it. Like this:

@pragma('vm:entry-point')
Future<void> _firebaseBackgroundMessage(RemoteMessage message) async {
  if (message.notification != null) {
    print('A message received');
  }
}

void main() async {
  WidgetsFlutterBinding.ensureInitialized();
  SystemChrome.setEnabledSystemUIMode(SystemUiMode.manual, overlays: [
    SystemUiOverlay.top,
    SystemUiOverlay.bottom,
  ]);
  await Firebase.initializeApp(
    options: DefaultFirebaseOptions.currentPlatform,
  );
  await PushNotifications.init();

  runApp(const MyApp());
  FirebaseMessaging.onBackgroundMessage(_firebaseBackgroundMessage);
}

aly22 avatar Oct 06 '23 17:10 aly22