本文介绍了我无法统一获取 currentActivity,并且在设备中运行应用程序后出现以下错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

java.lang.NoSuchFieldError: 没有Ljava/lang/Object;"场地类Lcom/unity/unity3d/player/UnityPlayer"中的currentActivity";或者它的超类 com.unity3d.player.UnityPlayer

void Start () 
{
    ajc1 = new AndroidJavaClass(className);
    ajc2 = new AndroidJavaClass ("com.unity3d.player.UnityPlayer");
    obj = ajc1.GetStatic<AndroidJavaObject> ("currentActivity");
    adhancrListener = new AndroidJavaClass("com.adhancr.adhancrlistener");
}

public void Initialize()
{
    ajc1.CallStatic<bool> (initFunctionName,obj,null);

}

这是我的 android 清单文件:

here's my android manifest file:

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.adhancr.adhancr" android:versionCode="1"
android:versionName="1.0" >
<application>
<activity android:name="com.google.android.gms.ads.AdActivity"
android:theme="@android:style/Theme.Translucent"
 android:configChanges="keyboard|keyboardHidden|orientation|screenLayout|uiMode|
screenSize|smallestScreenSize"/>
<activity android:name="com.inmobi.androidsdk.IMBrowserActivity"android:configChanges="keyboardHidden|orientation|keyboard|smallestScreenSize|
 screenSize" android:theme="@android:style/Theme.Translucent.NoTitleBar" 
android:hardwareAccelerated="true" />
</application>
</manifest>

推荐答案

我得到了答案,我们所要做的就是在 android manifest 文件中添加 unity player 的活动,你就可以开始了.

i got the answer, All we have to do is add activity of unity player in the android manifest file and you are good to go.

<activity android:name="com.unity3d.player.UnityPlayerNativeActivity"
          android:label="@string/app_name">
  <intent-filter>
    <action android:name="android.intent.action.MAIN" />
    <category android:name="android.intent.category.LAUNCHER" />
    <category android:name="android.intent.category.LEANBACK_LAUNCHER" />
  </intent-filter>
  <meta-data android:name="unityplayer.UnityActivity" android:value="true"
  />
  <meta-data
 android:name="unityplayer.ForwardNativeEventsToDalvik"android:value="false"
  />
</activity>

这篇关于我无法统一获取 currentActivity,并且在设备中运行应用程序后出现以下错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-31 16:17