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

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

Open
chetu-ko opened this issue Sep 10, 2024 · 9 comments
Open

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

chetu-ko opened this issue Sep 10, 2024 · 9 comments

Comments

@chetu-ko
Copy link

chetu-ko commented Sep 10, 2024

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
Copy link
Collaborator

  • Just to confirm the versions mentioned in the other issue, are you now using Unity 2022.3.43f1 instead of 2023?

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

  • Are you using the useAndroidViewSurface (true or false) parameter in the UnityWidget?
    I'm asking because Flutter 3.19 has invisibility and transition/resize issues when this param is false.
    If you are not using AR, using Flutter 3.22+ will help in preventing a lot of small issues.

  • Can you replicate this with the example project?
    Just to check if it is anything specific to your dart code or not.

@chetu-ko
Copy link
Author

chetu-ko commented Sep 10, 2024

  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
Copy link
Author

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.

  • What went wrong:
    Execution failed for task ':flutter_unity_widget:compileDebugKotlin'.

A failure occurred while executing org.jetbrains.kotlin.compilerRunner.GradleCompilerRunnerWithWorkers$GradleKotlinCompilerWorkAction
Compilation error. See log for more details

@timbotimbo
Copy link
Collaborator

timbotimbo commented Sep 16, 2024

The lifecycle error looks like #973

@chetu-ko
Copy link
Author

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

#984 (comment)

@emileswain
Copy link

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
Copy link
Author

@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

@emileswain
Copy link

strictly speaking it should go into the android/app/src/main/res/values/strings.xml create the strings.xml file if it doesn't exist. For example .... you may not need the app_name field.

<?xml version="1.0" encoding="utf-8"?>
<resources>
  <string name="app_name">DemoURPTemplate</string>
  <string name="game_view_content_description">Game view</string>
</resources>

This may be unrelated, its just the error is pretty similar to what i had when this element was missing. Also if you have values-night, make sure its in there as well.

@chetu-ko
Copy link
Author

@emileswain Thank you, I have tried everything. I don't know, why it is not running. I have added the same thing in the path android/app/src/main/res/values/strings.xml path and tried everything after adding that.

Flutter clean
Pub cache repair
fluteter_unity_widget: 2022.0, 2, flutter_3.24_android_hotfix

I tried all the versions of packages by running all the above functions, but it's giving the same error every time I run the Flutter project, I am not sure why it's not working.

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

3 participants