Unity3d应用程序崩溃时使用Android插件

问题描述:

我跟随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想要的。 –

这里有两件事情我会尝试。

首先将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) { 

}