5

Ich folge this tutorial, um einen Schrittzähler zu machen, und es funktioniert gut als Android-Projekt, aber wenn ich das Android-Projekt eine Bibliothek machen und es in unity3d verwenden will, stürzt es und gibt mir ein Fehler class not found: exception Meine Einheit Code ist wie folgt:Unity3d Anwendung stürzt ab, wenn Android plugin

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; 
    } 
} 

und mein android-Code ist wie folgt:

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"); 
} 
} 

Nachdem ein android-Glas machen, halte ich es in den Plugin-Ordner in unity3d. Habe ich etwas vermisst?

Meine Android Manifest-Datei ist wie folgt:

<?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

Haben Sie eine Stack-Trace oder Fehlerprotokoll, das Sie posten können? –

+0

Kannst du die 'AndroidManifest.xml' aus deinem Unity-Plugin-Ordner veröffentlichen? – LPeteR90

+0

Ich habe meine Manifestdetails als @ LPeteR90 hinzugefügt. –

Antwort

0

Hier sind die beiden Dinge, die ich versuchen würde.

Ändern Sie zuerst die folgende Zeile in Ihnen AndroidManifest.xml, damit das Paket Scoping auf der android:name Eigenschaft übereinstimmt.

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

zu

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

Das andere potenzielle Problem ist, dass Ihre Klasse nicht erstellt werden, weil es konkrete Implementierungen der abstrakten Methoden in den Eltern-Klassen und Schnittstellen fehlt. Um das zu beheben, fügen Sie diese Implementierungen zu MainActivity