Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Крэш на Андроиде при вызове FlutterEngine.destroy из фонового сервиса #379

Open
alod2019 opened this issue Sep 23, 2024 · 1 comment

Comments

@alod2019
Copy link

В приложении реализована фоновая обработка событий как описано в Background processes и в ходе которой создается отдельный FlutterEngine и потом, после обработки события. уничтожается. Проблема в том, что при этом возникает крэш

Caused by java.lang.NullPointerException: Attempt to invoke virtual method 'void x6.k.e(x6.k$c)' on a null object reference
       at com.unact.yandexmapkit.full.InitFull.teardownChannels(InitFull.java:1)
       at com.unact.yandexmapkit.full.InitFull.onDetachedFromEngine(InitFull.java:1)
       at com.unact.yandexmapkit.YandexMapkitPlugin.onDetachedFromEngine(YandexMapkitPlugin.java:3)
       at io.flutter.embedding.engine.FlutterEngineConnectionRegistry.remove(FlutterEngineConnectionRegistry.java:1)
       at io.flutter.embedding.engine.FlutterEngineConnectionRegistry.remove(FlutterEngineConnectionRegistry.java:1)
       at io.flutter.embedding.engine.FlutterEngineConnectionRegistry.removeAll(FlutterEngineConnectionRegistry.java:1)
       at io.flutter.embedding.engine.FlutterEngineConnectionRegistry.destroy(FlutterEngineConnectionRegistry.java:1)
       at io.flutter.embedding.engine.FlutterEngine.destroy(FlutterEngine.java:1)

Приложение собрано Flutter 3.19.6

@alod2019
Copy link
Author

alod2019 commented Sep 25, 2024

Проблема возникла после обновления с версии 4.0.2 на 4.1.0 и, похоже, из-за того, что YandexMapkitPlugin теперь реализован через синглтон BuildConfig.YANDEX_MAPKIT_INIT, а раньше внутри плагина создавался отдельный инстанс variantInit, было

public class YandexMapkitPlugin implements FlutterPlugin, ActivityAware {
  private final Init variantInit;

  public YandexMapkitPlugin() throws IllegalAccessException, InstantiationException {
    this.variantInit = (Init) BuildConfig.YANDEX_MAPKIT_INIT_CLASS.newInstance();
  }

  @Override
  public void onAttachedToEngine(@NonNull FlutterPluginBinding binding) {
    variantInit.onAttachedToEngine(binding);
  }

стало

public class YandexMapkitPlugin implements FlutterPlugin, ActivityAware {

  @Override
  public void onAttachedToEngine(@NonNull FlutterPluginBinding binding) {
    BuildConfig.YANDEX_MAPKIT_INIT.onAttachedToEngine(binding);
  }

и если FlutterEngine-ов больше одного, то после уничтожения олного из них программа падает при уничтожении другого

Caused by: java.lang.NullPointerException: Attempt to invoke virtual method 'void io.flutter.plugin.common.MethodChannel.setMethodCallHandler(io.flutter.plugin.common.MethodChannel$MethodCallHandler)' on a null object reference
    at com.unact.yandexmapkit.full.InitFull.teardownChannels(InitFull.java:62)
    at com.unact.yandexmapkit.full.InitFull.onDetachedFromEngine(InitFull.java:35)
    at com.unact.yandexmapkit.YandexMapkitPlugin.onDetachedFromEngine(YandexMapkitPlugin.java:18)
    at io.flutter.embedding.engine.FlutterEngineConnectionRegistry.remove(FlutterEngineConnectionRegistry.java:272)
    at io.flutter.embedding.engine.FlutterEngineConnectionRegistry.remove(FlutterEngineConnectionRegistry.java:280)
    at io.flutter.embedding.engine.FlutterEngineConnectionRegistry.removeAll(FlutterEngineConnectionRegistry.java:288)
    at io.flutter.embedding.engine.FlutterEngineConnectionRegistry.destroy(FlutterEngineConnectionRegistry.java:123)
    at io.flutter.embedding.engine.FlutterEngine.destroy(FlutterEngine.java:467)
    at io.flutter.embedding.android.FlutterActivityAndFragmentDelegate.onDetach(FlutterActivityAndFragmentDelegate.java:752)
    at io.flutter.embedding.android.FlutterActivity.onDestroy(FlutterActivity.java:875)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant