react-native-unity
react-native-unity copied to clipboard
Unity 2021.3.21f1 wants to access mUnityPlayer field
After upgrading to editor version 2021.3.21f1, Android build is no longer working:
E Unity : AndroidJavaException: java.lang.NoSuchFieldError: no "Ljava/lang/Object;" field "mUnityPlayer" in class "Lcom/example/MainActivity;" or its superclasses
E Unity : java.lang.NoSuchFieldError: no "Ljava/lang/Object;" field "mUnityPlayer" in class "Lcom/example/MainActivity;" or its superclasses
E Unity : at com.unity3d.player.UnityPlayer.nativeRender(Native Method)
E Unity : at com.unity3d.player.UnityPlayer.access$500(Unknown Source:0)
E Unity : at com.unity3d.player.UnityPlayer$e$1.handleMessage(Unknown Source:126)
E Unity : at android.os.Handler.dispatchMessage(Handler.java:102)
E Unity : at android.os.Looper.loop(Looper.java:233)
E Unity : at com.unity3d.player.UnityPlayer$e.run(Unknown Source:20)
E Unity : at UnityEngine.AndroidJNISafe.CheckException () [0x00000] in <00000000000000000000000000000000>:0
E Unity : at UnityEngine.AndroidJNISafe.GetFieldID (System.IntPtr clazz, System.String name, System.String sig) [0x00000] in <00000000000000000000000000000000>:0
E Unity : at UnityEngine._AndroidJNIHelper.GetFieldID (System.IntPtr jclass, System.String fieldName, System.Str
Somehow the Unity native code wants to access mUnityPlayer field of current activity class, which is never defined but it worked in previous versions. After looking into the built-in UnityPlayerActivity I found protected UnityPlayer mUnityPlayer; // don't change the name of this variable; referenced from native code, which has been there before it breaks. So it looks like there is change in the native code, but I can't find the source code of it.
Found a similar report https://stackoverflow.com/questions/75728722/flutter-unity-integration-errorandroidjavaexception-java-lang-nosuchfielderror
It seems Unity has changed the way it interacts with the hosting activity. Just don't know why the native code will need the mUnityPlayer field and what the native code is expecting from the hosting activity.