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 514 forks source link

Failed to handle method call : java.lang.NullPointerException #984

Open chetu-ko opened 1 week ago

chetu-ko commented 1 week ago

The bug The export and flutter build is successful after that, we are getting a yellow screen error on the screen both the real device and the emulator device.

ScreenShot

Error log

E/MethodChannel#flutter/platform_views(10293): Failed to handle method call E/MethodChannel#flutter/platform_views(10293): java.lang.NullPointerException E/MethodChannel#flutter/platform_views(10293): at com.xraph.plugin.flutter_unity_widget.FlutterUnityWidgetController.reattachToView(FlutterUnityWidgetController.kt:359) E/MethodChannel#flutter/platform_views(10293): at com.xraph.plugin.flutter_unity_widget.FlutterUnityWidgetController.onResume(FlutterUnityWidgetController.kt:238) E/MethodChannel#flutter/platform_views(10293): at androidx.lifecycle.FullLifecycleObserverAdapter.onStateChanged(FullLifecycleObserverAdapter.java:42) E/MethodChannel#flutter/platform_views(10293): at androidx.lifecycle.LifecycleRegistry$ObserverWithState.dispatchEvent(LifecycleRegistry.java:360) E/MethodChannel#flutter/platform_views(10293): at androidx.lifecycle.LifecycleRegistry.addObserver(LifecycleRegistry.java:202) E/MethodChannel#flutter/platform_views(10293): at com.xraph.plugin.flutter_unity_widget.FlutterUnityWidgetController.bootstrap(FlutterUnityWidgetController.kt:265) E/MethodChannel#flutter/platform_views(10293): at com.xraph.plugin.flutter_unity_widget.FlutterUnityWidgetBuilder.build(FlutterUnityWidgetBuilder.kt:22) E/MethodChannel#flutter/platform_views(10293): at com.xraph.plugin.flutter_unity_widget.FlutterUnityWidgetFactory.create(FlutterUnityWidgetFactory.kt:34) E/MethodChannel#flutter/platform_views(10293): at io.flutter.plugin.platform.PlatformViewsController.createPlatformView(PlatformViewsController.java:527) E/MethodChannel#flutter/platform_views(10293): at io.flutter.plugin.platform.PlatformViewsController$1.createForTextureLayer(PlatformViewsController.java:199) E/MethodChannel#flutter/platform_views(10293): at io.flutter.embedding.engine.systemchannels.PlatformViewsChannel$1.create(PlatformViewsChannel.java:128) E/MethodChannel#flutter/platform_views(10293): at io.flutter.embedding.engine.systemchannels.PlatformViewsChannel$1.onMethodCall(PlatformViewsChannel.java:55) E/MethodChannel#flutter/platform_views(10293): at io.flutter.plugin.common.MethodChannel$IncomingMethodCallHandler.onMessage(MethodChannel.java:267) E/MethodChannel#flutter/platform_views(10293): at io.flutter.embedding.engine.dart.DartMessenger.invokeHandler(DartMessenger.java:292) E/MethodChannel#flutter/platform_views(10293): at io.flutter.embedding.engine.dart.DartMessenger.lambda$dispatchMessageToQueue$0$io-flutter-embedding-engine-dart-DartMessenger(DartMessenger.java:319) E/MethodChannel#flutter/platform_views(10293): at io.flutter.embedding.engine.dart.DartMessenger$$ExternalSyntheticLambda0.run(Unknown Source:12) E/MethodChannel#flutter/platform_views(10293): at android.os.Handler.handleCallback(Handler.java:958) E/MethodChannel#flutter/platform_views(10293): at android.os.Handler.dispatchMessage(Handler.java:99) E/MethodChannel#flutter/platform_views(10293): at android.os.Looper.loopOnce(Looper.java:205) E/MethodChannel#flutter/platform_views(10293): at android.os.Looper.loop(Looper.java:294) E/MethodChannel#flutter/platform_views(10293): at android.app.ActivityThread.main(ActivityThread.java:8177) E/MethodChannel#flutter/platform_views(10293): at java.lang.reflect.Method.invoke(Native Method) E/MethodChannel#flutter/platform_views(10293): at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:552) E/MethodChannel#flutter/platform_views(10293): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:971) E/OpenGLRenderer(10293): Unable to match the desired swap behavior. E/flutter (10293): [ERROR:flutter/runtime/dart_vm_initializer.cc(41)] Unhandled Exception: PlatformException(error, null, null, java.lang.NullPointerException E/flutter ( 7556): at com.xraph.plugin.flutter_unity_widget.FlutterUnityWidgetController.reattachToView(FlutterUnityWidgetController.kt:359) E/flutter ( 7556): at com.xraph.plugin.flutter_unity_widget.FlutterUnityWidgetController.onResume(FlutterUnityWidgetController.kt:238) E/flutter ( 7556): at androidx.lifecycle.DefaultLifecycleObserverAdapter.onStateChanged(DefaultLifecycleObserverAdapter.kt:26) E/flutter ( 7556): at androidx.lifecycle.LifecycleRegistry$ObserverWithState.dispatchEvent(LifecycleRegistry.kt:322) E/flutter ( 7556): at androidx.lifecycle.LifecycleRegistry.addObserver(LifecycleRegistry.kt:199) E/flutter ( 7556): at com.xraph.plugin.flutter_unity_widget.FlutterUnityWidgetController.bootstrap(FlutterUnityWidgetController.kt:265) E/flutter ( 7556): at com.xraph.plugin.flutter_unity_widget.FlutterUnityWidgetBuilder.build(FlutterUnityWidgetBuilder.kt:22) E/flutter ( 7556): at com.xraph.plugin.flutter_unity_widget.FlutterUnityWidgetFactory.create(FlutterUnityWidgetFactory.kt:34) E/flutter ( 7556): at io.flutter.plugin.platform.PlatformViewsController.createPlatformView(PlatformViewsController.java:523) E/flutter ( 7556): at io.flutter.plugin.platform.PlatformViewsController$1.createForTextureLayer(PlatformViewsController.java:197) E/flutter ( 7556): at io.flutter.embedding.engine.systemchannels.PlatformViewsChannel$1.create(PlatformViewsChannel.java:128) E/flutter ( 7556): at io.flutter.embedding.engine.systemchannels.PlatformViewsChannel$1.onMethodCall(PlatformViewsChannel.java:55) E/flutter ( 7556): at io.flutter.plugin.common.MethodChannel$IncomingMethodCallHandler.onMessage(MethodChannel.java:267) E/flutter ( 7556): at io.flutter.embedding.engine.dart.DartMessenger.invokeHandler(DartMessenger.java:292) E/flutter ( 7556): at io.flutter.embedding.engine.dart.DartMessenger.lambda$dispatchMessageToQueue$0$io-flutter-embedding-engine-dart-DartMessenger(DartMessenger.java:319) E/flutter ( 7556): at io.flutter.embedding.engine.dart.DartMessenger$$ExternalSyntheticLambda0.run(Unknown Source:12) E/flutter ( 7556): at android.os.Handler.handleCallback(Handler.java:958) E/flutter ( 7556): at android.os.Handler.dispatchMessage(Handler.java:99) E/flutter ( 7556): at android.os.Looper.loopOnce(Looper.java:205) E/flutter ( 7556): at android.os.Looper.loop(Looper.java:294) E/flutter ( 7556): at android.app.ActivityThread.main(ActivityThread.java:8177) E/flutter ( 7556): at java.lang.reflect.Method.invoke(Native Method) E/flutter ( 7556): at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:552) E/flutter ( 7556): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:971) E/flutter ( 7556): ) E/flutter ( 7556): #0 StandardMethodCodec.decodeEnvelope (package:flutter/src/services/message_codecs.dart:648:7) E/flutter ( 7556): #1 MethodChannel._invokeMethod (package:flutter/src/services/platform_channel.dart:334:18) E/flutter ( 7556): E/flutter ( 7556): #2 TextureAndroidViewController._sendCreateMessage (package:flutter/src/services/platform_views.dart:1164:28) E/flutter ( 7556): E/flutter ( 7556): #3 AndroidViewController.create (package:flutter/src/services/platform_views.dart:827:5) E/flutter ( 7556): E/flutter ( 7556): #4 AndroidViewController.setSize (package:flutter/src/services/platform_views.dart:854:7) E/flutter ( 7556): E/flutter ( 7556): #5 RenderAndroidView._sizePlatformView (package:flutter/src/rendering/platform_view.dart:176:29) E/flutter ( 7556):

Please help us with the issue. I don't know if the above log works to debug the issue, but this is what I am getting in the debug logger. Let me know if any other details are needed.

To see the versions used please refer #981

Thank you.

timbotimbo commented 1 week ago

Flutter: 3.19.2 Gradle: Distribution URL: Distribution https://services.gradle.org/distributions/gradle-7.6-bin.zip Classpath: classpath 'com.android.tools.build:gradle:7.3.1' Kotlin Version: ext.kotlin_version = '1.9.0' Unity: 2023.2.20f minSdkVersion: 26 targetSdkVersion: 34

chetu-ko commented 1 week ago
  1. Yes, I am using the unity version 2022.3.43f1.
  2. No I have not used true/false parameter in UnityWidget.
  3. I tried running example, It's working fine with all configurations.

I am using flutter version 3.19 and android > 10 which is 14 I an using.

chetu-ko commented 3 days ago

Hi @timbotimbo I am now getting a different error, I am using Android> 10, and I upgraded my Flutter version to 3.24 to the recent version, This time not even the Flutter build is completed.

I checked the issue I have not found the same issue in the issue list, Can you please tag if any issue is already listed and solved?

e: file:///Users/chetan/.pub-cache/hosted/pub.dev/flutter_unity_widget-2022.2.1/android/src/main/kotlin/com/xraph/plugin/flutter_unity_widget/FlutterUnityWidgetPlugin.kt:97:9 Cannot weaken access privilege 'public' for 'lifecycle' in 'LifecycleOwner' e: file:///Users/chetan/.pub-cache/hosted/pub.dev/flutter_unity_widget-2022.2.1/android/src/main/kotlin/com/xraph/plugin/flutter_unity_widget/FlutterUnityWidgetPlugin.kt:97:21 'lifecycle' hides member of supertype 'LifecycleOwner' and needs 'override' modifier

FAILURE: Build failed with an exception.

timbotimbo commented 2 days ago

The lifecycle error looks like https://github.com/juicycleff/flutter-unity-view-widget/issues/973

chetu-ko commented 1 day ago

HI @timbotimbo.

I have configured everything, and I did every step you told me, but I am still getting the same error, and the black screen once the build is successful, Please help me to fix this. Also, I have tried adding a useAndroidViewSurface true or false but still not working tried flutter clean.

Android > 10 flutter 3.24.0 unity 2022.3.43f1. package

  flutter_unity_widget:
      git:
        url: https://github.com/juicycleff/flutter-unity-view-widget.git
        ref: flutter_3.24_android_hotfix

ERROR:

java.lang.NullPointerException

https://github.com/juicycleff/flutter-unity-view-widget/issues/984#issue-2515875345

emileswain commented 18 hours ago

i'm dealing with multiple errors, but I believe that the following fixed an issue that threw this error, .FlutterUnityWidgetController.reattachToView I'm adding this comment to help others deal with unity/flutter version upgrades where you often end up here again and again.

Adding <string name="game_view_content_description">Game view</string> to the andoird/app/src/main/res/values/styles.xml fixed the issue for me. (solution related to UAAL here )

I personaly believe that the .FlutterUnityWidgetController.reattachToView error is reflecting the fact that something else went horribly wrong at a low level, and this is where the error surfaces to the user. I.e. its not really anthing to do with reattachToView. For example, requesting an android res that doesn't exist isn't being handled very well.

chetu-ko commented 3 minutes ago

@emileswain Thank you for the response, but this doesn't solve any of my problems. Please check if I am adding it in right way.

Screenshot 2024-09-19 at 3 12 47 PM