Skip to content

Resolve mUnityPlayer reference for native plugins #857

@t5ujiri

Description

@t5ujiri

Is your feature request related to a problem? Please describe.

This is about android builds.

Some Native libraries assumes the MainActivity inherits UnityActivity. Those libraries do native function calls in this manner.

            AndroidHelper.Instance.DispatchUiThread(unityActivity =>
            {
                // Create the plugin
                using (AndroidJavaClass cloudServices = new AndroidJavaClass("com.microsoft.CloudServices"))
                {
                    // Initialize the plugin
                    cloudServices.CallStatic("initialize", unityActivity);

                    // Update static variable to say that the plugin has been initialized
                    javaInitialized = true;

                    // Set the task completion source so the CreateSession method can
                    // continue back on the Unity thread.
                    pluginInit.SetResult(true);
                }
            });

Appearently com.microsoft.CloudServices need Unity Player instance.
This doesn't work, as in UaaL the MainActivity class originated from flutter and doesn't inherits UnityActivity.

AndroidJavaException: java.lang.NoSuchFieldError: no "Ljava/lang/Object;" field "mUnityPlayer" in class "Ljp/co/gatari/aurisclassiceditormobile/MainActivity;" or its superclasses
E/Unity   (17038): java.lang.NoSuchFieldError: no "Ljava/lang/Object;" field "mUnityPlayer" in class "Ljp/co/gatari/aurisclassiceditormobile/MainActivity;" or its superclasses
E/Unity   (17038): 	at com.unity3d.player.UnityPlayer.nativeRender(Native Method)
E/Unity   (17038): 	at com.unity3d.player.UnityPlayer.access$500(Unknown Source:0)
E/Unity   (17038): 	at com.unity3d.player.UnityPlayer$e$1.handleMessage(Unknown Source:126)
E/Unity   (17038): 	at android.os.Handler.dispatchMessage(Handler.java:102)
E/Unity   (17038): 	at android.os.Looper.loopOnce(Looper.java:201)
E/Unity   (17038): 	at android.os.Looper.loop(Looper.java:288)
E/Unity   (17038): 	at com.unity3d.player.UnityPlayer$e.run(Unknown Source:20)
E/Unity   (17038):   at UnityEngine.AndroidJNISafe.CheckException () [0x00000] in <00000000000000000000000000000000>:0 
E/Unity   (17038):   at UnityEngine.AndroidJNISafe.GetFieldID (System.IntPtr clazz, System.String name, System.String sig) [0x00000] in <00000000000000000000000000000000>:0 
E/Unity   (17038):   at UnityEngine._Andr

Describe the solution you'd like
Please let me know if there is a way to make those native libraries work.
Can I set the CustomUnityPlayer (which inherits UnityActivity) reference to Flutter's MainActivity?

Metadata

Metadata

Assignees

No one assigned

    Labels

    duplicateThis issue or pull request already exists

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions