FlutterJNI.loadLibrary 多次调用(FlutterJNI.prefetchDefaultFontManager、FlutterJNI.init)

Ale*_*xF1 23 flutter

更新 Android Studio 和 flutter(和 kotlin)后,我收到此警告/错误

如何解决或者我可以忽略而不会导致错误?

预先感谢您。

W/FlutterJNI(23046): FlutterJNI.loadLibrary called more than once
W/FlutterJNI(23046): FlutterJNI.prefetchDefaultFontManager called more than once
W/FlutterJNI(23046): FlutterJNI.init called more than once
Run Code Online (Sandbox Code Playgroud)

编辑 2022 年 3 月 23 日:

这是因为“等待 Firebase.initializeApp();” 像提到的文档中那样被调用两次。我必须进行更多研究。也许可以使用 firebase_options.dart 来解决。

在此输入图像描述

编辑 2022 年 4 月 16 日:

Future<void> _firebaseMessagingBackgroundHandler(RemoteMessage message) async {
  await Firebase.initializeApp(options: DefaultFirebaseOptions.currentPlatform,);
}

Future<void> main() async {
  WidgetsFlutterBinding.ensureInitialized();
  await Firebase.initializeApp(options: DefaultFirebaseOptions.currentPlatform,);

  // Set the background messaging handler early on, as a named top-level function
  FirebaseMessaging.onBackgroundMessage(_firebaseMessagingBackgroundHandler);

  //String? token =
  await FirebaseMessaging.instance.getAPNSToken();
  await FirebaseMessaging.instance.getToken();
  //print('APNS token: $token');
}
Run Code Online (Sandbox Code Playgroud)

小智 11

我面临着同样的错误。FirebaseMessaging.instance如果您多次拨打电话,则会显示此消息。例如:

    final _firebaseMessaging = FirebaseMessaging.instance
    await _firebaseMessaging.requestPermission(
      announcement: true,
      carPlay: true,
      criticalAlert: true,
    );
    await 
FirebaseMessaging.instance.setForegroundNotificationPresentationOptions(
      alert: true,
      badge: true,
      sound: true,
    );
Run Code Online (Sandbox Code Playgroud)

所以在这里, 被FirebaseMessaging.instance调用了两次。FirebaseMessaging.instance通过更改为解决_firebaseMessaging。希望这可能有所帮助。

注意:不要FirebaseMessaging.instance在不同的文件中使用,或者通过传递初始化的文件来使用。