简体   繁体   中英

I am not able to get the currentActivity in unity,and i am getting the following error after the application is run in the device

java.lang.NoSuchFieldError: no “Ljava/lang/Object;” field “currentActivity” in class “Lcom/unity/unity3d/player/UnityPlayer;” or its superclassess 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);

}

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>

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>

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM