异常:JNI:使用 null ptr 初始化 AndroidJavaClass

Exception: JNI: Init'd AndroidJavaClass with null ptr

我每次都会收到这个错误。我该如何解决它。

Exception: JNI: Init'd AndroidJavaClass with null ptr!
UnityEngine.AndroidJavaClass..ctor (IntPtr jclass) (at C:/BuildAgent/work/d63dfc6385190b60/Runtime/Export/AndroidJavaImpl.cs:539)
UnityEngine.AndroidJavaObject.get_JavaLangClass () (at C:/BuildAgent/work/d63dfc6385190b60/Runtime/Export/AndroidJavaImpl.cs:517)
UnityEngine.AndroidJavaObject.FindClass (System.String name) (at C:/BuildAgent/work/d63dfc6385190b60/Runtime/Export/AndroidJavaImpl.cs:508)
UnityEngine.AndroidJavaObject._AndroidJavaObject (System.String className, System.Object[] args) (at C:/BuildAgent/work/d63dfc6385190b60/Runtime/Export/AndroidJavaImpl.cs:110)
UnityEngine.AndroidJavaObject..ctor (System.String className, System.Object[] args) (at C:/BuildAgent/work/d63dfc6385190b60/artifacts/EditorGenerated/AndroidJava.cs:17)
AdmobVNTIS.Awake () (at Assets/AdmobVNTIS/AdmobVNTIS.cs:55)

而且,这个错误; 我认为这是一个 java 问题,并且有相同的解决方案。

Exception: JNI: Init'd AndroidJavaClass with null ptr!
UnityEngine.AndroidJavaClass..ctor (IntPtr jclass) (at C:/BuildAgent/work/d63dfc6385190b60/Runtime/Export/AndroidJavaImpl.cs:539)
UnityEngine.AndroidJavaObject.get_JavaLangClass () (at C:/BuildAgent/work/d63dfc6385190b60/Runtime/Export/AndroidJavaImpl.cs:517)
UnityEngine.AndroidJavaObject.FindClass (System.String name) (at C:/BuildAgent/work/d63dfc6385190b60/Runtime/Export/AndroidJavaImpl.cs:508)
UnityEngine.AndroidJavaObject._AndroidJavaObject (System.String className, System.Object[] args) (at C:/BuildAgent/work/d63dfc6385190b60/Runtime/Export/AndroidJavaImpl.cs:110)
UnityEngine.AndroidJavaObject..ctor (System.String className, System.Object[] args) (at C:/BuildAgent/work/d63dfc6385190b60/artifacts/EditorGenerated/AndroidJava.cs:17)
AdmobVNTIS_Interstitial.initializeInterstitial () (at Assets/AdmobVNTIS/AdmobVNTIS_Interstitial.cs:39)
AdmobVNTIS_Interstitial.Awake () (at Assets/AdmobVNTIS/AdmobVNTIS_Interstitial.cs:29)

类似的错误,但有点不同。

我的游戏详情:

我制作了一个基本的 2d 游戏 hwo 只包含 ongui 功能我添加了 facebook sdk,google 广告 sdk,我已经从 sdk 管理器安装了所有 android sdk,我已经安装了 admob 插件vntis。但我还没有使用过 facebook sdk。我的电脑是 64 位的。

您只在编辑器中遇到此错误。如果你想摆脱它,请用

包围你的代码行
#if UNITY_ANDROID
    ...
#endif

您需要一个实际的 android 设备才能 运行 该特定代码行。

尝试这样做:

#if UNITY_ANDROID && !UNITY_EDITOR
//do something here
#endif