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

Nis*_*dya 5 google-play-services android-studio google-fit unity3d-5 android-unity-plugin

我正在按照这个教程制作一个步骤计数器,它可以很好地作为一个Android项目但是当我使android项目成为一个库并想在unity3d中使用它时,它崩溃并给我一个错误class not found: exception 我的统一代码如下:

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;
    }
}
Run Code Online (Sandbox Code Playgroud)

我的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");
}
}
Run Code Online (Sandbox Code Playgroud)

制作一个android jar后,我将它保存在unity3d的插件文件夹中.我错过了什么吗?

我的Android Manifest文件如下:

<?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>
Run Code Online (Sandbox Code Playgroud)

Jos*_*gan 0

这是我要尝试的两件事。

首先更改以下行,AndroidManifest.xml以便包范围与android:name属性匹配。

<activity android:name="com.xxx.testapp.MainActivity"
         android:label="@string/app_name">
Run Code Online (Sandbox Code Playgroud)

<activity android:name="com.test.testapp.MainActivity"
         android:label="@string/app_name">
Run Code Online (Sandbox Code Playgroud)

另一个潜在的问题是您的类没有被编译,因为它缺少父类和接口中抽象方法的具体实现。要解决此问题,请将这些实现添加到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) {

}
Run Code Online (Sandbox Code Playgroud)