juicycleff / flutter-unity-view-widget

Embeddable unity game engine view for Flutter. Advance demo here https://github.com/juicycleff/flutter-unity-arkit-demo
BSD 3-Clause "New" or "Revised" License
2.13k stars 518 forks source link

[Error] The "events#onViewReattached" method does not exists. #820

Open Raonshi opened 1 year ago

Raonshi commented 1 year ago

Hi. I've got the below error message.

ERROR:flutter/runtime/dart_vm_initializer.cc(41)] Unhandled Exception: PlatformException(error, null, null, java.lang.NullPointerException
 at com.xraph.plugin.flutter_unity_widget.FlutterUnityWidgetController.reattachToView(FlutterUnityWidgetController.kt:362)
 at com.xraph.plugin.flutter_unity_widget.FlutterUnityWidgetController.onResume(FlutterUnityWidgetController.kt:239)
 at androidx.lifecycle.FullLifecycleObserverAdapter.onStateChanged(FullLifecycleObserverAdapter.java:42)
 at androidx.lifecycle.LifecycleRegistry$ObserverWithState.dispatchEvent(LifecycleRegistry.java:354)
 at androidx.lifecycle.LifecycleRegistry.addObserver(LifecycleRegistry.java:196)
 at com.xraph.plugin.flutter_unity_widget.FlutterUnityWidgetController.bootstrap(FlutterUnityWidgetController.kt:266)
 at com.xraph.plugin.flutter_unity_widget.FlutterUnityWidgetBuilder.build(FlutterUnityWidgetBuilder.kt:22)
 at com.xraph.plugin.flutter_unity_widget.FlutterUnityWidgetFactory.create(FlutterUnityWidgetFactory.kt:34)
 at io.flutter.plugin.platform.PlatformViewsController$1.createPlatformView(PlatformViewsController.java:503)
 at io.flutter.plugin.platform.PlatformViewsController$1.createForTextureLayer(PlatformViewsController.java:191)
 at io.flutter.embedding.engine.systemchannels.PlatformViewsChannel$1.create(PlatformViewsChannel.java:128)
 at io.flutter.embedding.engine.systemchannels.PlatformViewsChannel$1.onMethodCall(PlatformViewsChannel.java:55)
 at io.flutter.plugin.common.MethodChannel$IncomingMethodCallHandler.onMessage(MethodChannel.java:258)
 at io.flutter.embedding.engine.dart.DartMessenger.invokeHandler(DartMessenger.java:295)
 at io.flutter.embedding.engine.dart.DartMessenger.lambda$dispatchMessageToQueue$0$io-flutter-embedding-engine-dart-DartMessenger(DartMessenger.java:322)
 at io.flutter.embedding.engine.dart.DartMessenger$$ExternalSyntheticLambda0.run(D8$$SyntheticClass)
 at android.os.Handler.handleCallback(Handler.java:751)
 at android.os.Handler.dispatchMessage(Handler.java:95)
 at android.os.Looper.loop(Looper.java:154)
 at android.app.ActivityThread.main(ActivityThread.java:6682)
 at java.lang.reflect.Method.invoke(Native Method)
 at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1520)
 at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1410)
)

In FlutterUnityWidgetController class, the"events#onViewReattached" method has been called, but there is no receiver in devide_method.dartflutter.

Like this,

// FlutterUnityWidgetController.kt
fun reattachToView() {
        if (UnityPlayerUtils.unityPlayer!!.parent != view) {
            this.attachToView()
            Handler(Looper.getMainLooper()).post {
                methodChannel.invokeMethod("events#onViewReattached", null)
            }
        }
        view.requestLayout()
    }
// device_method.dart
  Future<dynamic> _handleMethodCall(MethodCall call, int unityId) async {
    switch (call.method) {
      case "events#onUnityMessage":
        _unityStreamController.add(UnityMessageEvent(unityId, call.arguments));
        break;
      case "events#onUnityUnloaded":
        _unityStreamController.add(UnityLoadedEvent(unityId, call.arguments));
        break;
      case "events#onUnitySceneLoaded":
        _unityStreamController.add(UnitySceneLoadedEvent(
            unityId, SceneLoaded.fromMap(call.arguments)));
        break;
      case "events#onUnityCreated":
        _unityStreamController.add(UnityCreatedEvent(unityId, call.arguments));
        break;
      default:
        throw UnimplementedError("Unimplemented ${call.method} method");
    }
  }

Is can fixable soon?

wzlsquall commented 1 year ago

Just add this node to your string.xml <string name="game_view_content_description">game_view_content_description</string>

Raonshi commented 1 year ago

Just add this node to your string.xml <string name="game_view_content_description">game_view_content_description</string>

@wzlsquall I already added that, but not solved. I want "reattach" process, not "resolving exception".

jmorin-illumix commented 4 months ago

Has this ever been resolved? Or is there a work around? I get the following:

W/Parcel ( 2587): Expecting binder but got null! I/IL2CPP ( 2587): JNI_OnLoad E/ix_flutter_uaal( 2587): Invalid ID 0x00000000. E/UnityPlayerUtils( 2587): android.content.res.Resources$NotFoundException: String resource ID #0x0 D/FlutterUnityController( 2587): onCreate D/FlutterUnityController( 2587): onResume E/MethodChannel#flutter/platform_views( 2587): Failed to handle method call E/MethodChannel#flutter/platform_views( 2587): java.lang.NullPointerException E/MethodChannel#flutter/platform_views( 2587): at com.xraph.plugin.flutter_unity_widget.FlutterUnityWidgetController.reattachToView(FlutterUnityWidgetController.kt:359) E/MethodChannel#flutter/platform_views( 2587): at com.xraph.plugin.flutter_unity_widget.FlutterUnityWidgetController.onResume(FlutterUnityWidgetController.kt:238) E/MethodChannel#flutter/platform_views( 2587): at androidx.lifecycle.FullLifecycleObserverAdapter.onStateChanged(FullLifecycleObserverAdapter.java:42) E/MethodChannel#flutter/platform_views( 2587): at androidx.lifecycle.LifecycleRegistry$ObserverWithState.dispatchEvent(LifecycleRegistry.java:354) E/MethodChannel#flutter/platform_views( 2587): at androidx.lifecycle.LifecycleRegistry.addObserver(LifecycleRegistry.java:196) E/MethodChannel#flutter/platform_views( 2587): at com.xraph.plugin.flutter_unity_widget.FlutterUnityWidgetController.bootstrap(FlutterUnityWidgetController.kt:265) E/MethodChannel#flutter/platform_views( 2587): at com.xraph.plugin.flutter_unity_widget.FlutterUnityWidgetBuilder.build(FlutterUnityWidgetBuilder.kt:22) E/MethodChannel#flutter/platform_views( 2587): at com.xraph.plugin.flutter_unity_widget.FlutterUnityWidgetFactory.create(FlutterUnityWidgetFactory.kt:34) E/MethodChannel#flutter/platform_views( 2587): at io.flutter.plugin.platform.PlatformViewsController.createPlatformView(PlatformViewsController.java:527) E/MethodChannel#flutter/platform_views( 2587): at io.flutter.plugin.platform.PlatformViewsController$1.createForTextureLayer(PlatformViewsController.java:199) E/MethodChannel#flutter/platform_views( 2587): at io.flutter.embedding.engine.systemchannels.PlatformViewsChannel$1.create(PlatformViewsChannel.java:128) E/MethodChannel#flutter/platform_views( 2587): at io.flutter.embedding.engine.systemchannels.PlatformViewsChannel$1.onMethodCall(PlatformViewsChannel.java:55) E/MethodChannel#flutter/platform_views( 2587): at io.flutter.plugin.common.MethodChannel$IncomingMethodCallHandler.onMessage(MethodChannel.java:267) E/MethodChannel#flutter/platform_views( 2587): at io.flutter.embedding.engine.dart.DartMessenger.invokeHandler(DartMessenger.java:292) E/MethodChannel#flutter/platform_views( 2587): at io.flutter.embedding.engine.dart.DartMessenger.lambda$dispatchMessageToQueue$0$io-flutter-embedding-engine-dart-DartMessenger(DartMessenger.java:319) E/MethodChannel#flutter/platform_views( 2587): at io.flutter.embedding.engine.dart.DartMessenger$$ExternalSyntheticLambda0.run(Unknown Source:12) E/MethodChannel#flutter/platform_views( 2587): at android.os.Handler.handleCallback(Handler.java:942) E/MethodChannel#flutter/platform_views( 2587): at android.os.Handler.dispatchMessage(Handler.java:99) E/MethodChannel#flutter/platform_views( 2587): at android.os.Looper.loopOnce(Looper.java:346) E/MethodChannel#flutter/platform_views( 2587): at android.os.Looper.loop(Looper.java:475) E/MethodChannel#flutter/platform_views( 2587): at android.app.ActivityThread.main(ActivityThread.java:7950) E/MethodChannel#flutter/platform_views( 2587): at java.lang.reflect.Method.invoke(Native Method) E/MethodChannel#flutter/platform_views( 2587): at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:548) E/MethodChannel#flutter/platform_views( 2587): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:942) W/OnBackInvokedCallback( 2587): OnBackInvokedCallback is not enabled for the application. W/OnBackInvokedCallback( 2587): Set 'android:enableOnBackInvokedCallback="true"' in the application manifest. E/flutter ( 2587): [ERROR:flutter/runtime/dart_vm_initializer.cc(41)] Unhandled Exception: PlatformException(error, null, null, java.lang.NullPointerException E/flutter ( 2587): at com.xraph.plugin.flutter_unity_widget.FlutterUnityWidgetController.reattachToView(FlutterUnityWidgetController.kt:359) E/flutter ( 2587): at com.xraph.plugin.flutter_unity_widget.FlutterUnityWidgetController.onResume(FlutterUnityWidgetController.kt:238) E/flutter ( 2587): at androidx.lifecycle.FullLifecycleObserverAdapter.onStateChanged(FullLifecycleObserverAdapter.java:42) E/flutter ( 2587): at androidx.lifecycle.LifecycleRegistry$ObserverWithState.dispatchEvent(LifecycleRegistry.java:354) E/flutter ( 2587): at androidx.lifecycle.LifecycleRegistry.addObserver(LifecycleRegistry.java:196) E/flutter ( 2587): at com.xraph.plugin.flutter_unity_widget.FlutterUnityWidgetController.bootstrap(FlutterUnityWidgetController.kt:265) E/flutter ( 2587): at com.xraph.plugin.flutter_unity_widget.FlutterUnityWidgetBuilder.build(FlutterUnityWidgetBuilder.kt:22) E/flutter ( 2587): at com.xraph.plugin.flutter_unity_widget.FlutterUnityWidgetFactory.create(FlutterUnityWidgetFactory.kt:34) E/flutter ( 2587): at io.flutter.plugin.platform.PlatformViewsController.createPlatformView(PlatformViewsController.java:527) E/flutter ( 2587): at io.flutter.plugin.platform.PlatformViewsController$1.createForTextureLayer(PlatformViewsController.java:199) E/flutter ( 2587): at io.flutter.embedding.engine.systemchannels.PlatformViewsChannel$1.create(PlatformViewsChannel.java:128) E/flutter ( 2587): at io.flutter.embedding.engine.systemchannels.PlatformViewsChannel$1.onMethodCall(PlatformViewsChannel.java:55) E/flutter ( 2587): at io.flutter.plugin.common.MethodChannel$IncomingMethodCallHandler.onMessage(MethodChannel.java:267) E/flutter ( 2587): at io.flutter.embedding.engine.dart.DartMessenger.invokeHandler(DartMessenger.java:292) E/flutter ( 2587): at io.flutter.embedding.engine.dart.DartMessenger.lambda$dispatchMessageToQueue$0$io-flutter-embedding-engine-dart-DartMessenger(DartMessenger.java:319) E/flutter ( 2587): at io.flutter.embedding.engine.dart.DartMessenger$$ExternalSyntheticLambda0.run(Unknown Source:12) E/flutter ( 2587): at android.os.Handler.handleCallback(Handler.java:942) E/flutter ( 2587): at android.os.Handler.dispatchMessage(Handler.java:99) E/flutter ( 2587): at android.os.Looper.loopOnce(Looper.java:346) E/flutter ( 2587): at android.os.Looper.loop(Looper.java:475) E/flutter ( 2587): at android.app.ActivityThread.main(ActivityThread.java:7950) E/flutter ( 2587): at java.lang.reflect.Method.invoke(Native Method) E/flutter ( 2587): at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:548) E/flutter ( 2587): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:942) E/flutter ( 2587): ) E/flutter ( 2587): #0 StandardMethodCodec.decodeEnvelope (package:flutter/src/services/message_codecs.dart:651:7) E/flutter ( 2587): #1 MethodChannel._invokeMethod (package:flutter/src/services/platform_channel.dart:334:18) E/flutter ( 2587): <asynchronous suspension> E/flutter ( 2587): #2 TextureAndroidViewController._sendCreateMessage (package:flutter/src/services/platform_views.dart:1175:28) E/flutter ( 2587): <asynchronous suspension> E/flutter ( 2587): #3 AndroidViewController.create (package:flutter/src/services/platform_views.dart:838:5) E/flutter ( 2587): <asynchronous suspension> E/flutter ( 2587): #4 AndroidViewController.setSize (package:flutter/src/services/platform_views.dart:865:7) E/flutter ( 2587): <asynchronous suspension> E/flutter ( 2587): #5 RenderAndroidView._sizePlatformView (package:flutter/src/rendering/platform_view.dart:176:29) E/flutter ( 2587): <asynchronous suspension> E/flutter ( 2587):

makamekm commented 4 months ago

I drop using the extension. It does not work. We are moving back to React Native. The example shows this error. I see that library is not being developed.