5

我跟隨this tutorial作出一個步驟計數器,它作爲一個Android項目,但是當我把android項目的圖書館,並希望在unity3d中使用它,它是崩潰,並給我錯誤class not found: exception 我統一代碼如下:Unity3d應用程序崩潰時使用Android插件

void Start() 
{ 
    #if UNITY_ANDROID 
    AndroidJNI.AttachCurrentThread(); 
    androidClass = new AndroidJavaClass("com.test.testapp.MainActivity"); 
    #endif 
} 
#if UNITY_ANDROID 
public void checkMyIntOnJava(string message){ 
    if (message == "READY") { 
     int myInt = androidClass.CallStatic<int>("getMyInt"); 
     guiText.text = "My Int: " + myInt; 
    } 
} 

和我的Android代碼如下:

public class MainActivity extends UnityPlayerActivity 
implements OnDataPointListener, GoogleApiClient.ConnectionCallbacks, 
    GoogleApiClient.OnConnectionFailedListener 
{ 
public static void callbackToUnityMethod(int num, String gameObject,String methodName){ 
    _myInt = num; 
    Log.e("GoogleFit", "in callbackToUnityMethod"); 
    UnityPlayer.UnitySendMessage(gameObject, methodName, "READY"); 
} 
} 

製作一個機器人罐子後,我把它在unity3d的插件文件夾。 我錯過了什麼嗎?

我的Android清單文件如下:

<?xml version="1.0" encoding="utf-8"?> 
<manifest xmlns:android="http://schemas.android.com/apk/res/android" 
    package="com.xxx.testapp" android:versionCode="1" 
    android:versionName="1.0"> 
<uses-sdk android:minSdkVersion="9" /> 
<application android:label="@string/app_name"> 
    <activity android:name="com.xxx.testapp.MainActivity" 
       android:label="@string/app_name"> 
     <intent-filter> 
      <action android:name="android.intent.action.MAIN" /> 
      <category android:name="android.intent.category.LAUNCHER" /> 
     </intent-filter> 
    </activity> 
    <activity android:name="com.xxx.testapp.UnityPlayerActivity" 
    android:configChanges="fontScale|keyboard|keyboardHidden|locale|mnc|mcc|navigation|orientation|screenLayout|screenSize|smallestScreenSize|uiMode|touchscreen" 
    android:label="@string/app_name" android:launchMode="singleTask" android:theme="@android:style/Theme.Translucent.NoTitleBar.Fullscreen" /> 
</application> 
</manifest> 
+1

您是否有可以發佈的堆棧跟蹤或錯誤日誌? –

+0

你可以從你的統一插件文件夾發佈'AndroidManifest.xml'嗎? – LPeteR90

+0

我添加了我的清單細節,作爲@ LPeteR90想要的。 –

回答

0

這裏有兩件事情我會嘗試。

首先將AndroidManifest.xml中的以下行更改爲使包打包範圍在android:name屬性上匹配。

<activity android:name="com.xxx.testapp.MainActivity" 
     android:label="@string/app_name"> 

<activity android:name="com.test.testapp.MainActivity" 
     android:label="@string/app_name"> 

另一個潛在問題是,你的類不被編譯,因爲它缺少對父母的類和接口的抽象方法的具體實現。要修復將這些實現添加到MainActivity

@Override 
protected void onCreate(Bundle savedInstanceState) { 
    super.onCreate(savedInstanceState); 
    setContentView(R.layout.activity_main); 
} 

@Override 
public void onConnected(Bundle bundle) { 

} 

@Override 
public void onConnectionSuspended(int i) { 

} 

@Override 
public void onConnectionFailed(ConnectionResult connectionResult) { 

} 

@Override 
public void onDataPoint(DataPoint dataPoint) { 

}