Game has stopped when using Android plugin for Unity3D

237 Views Asked by At

sorry for my bad English I made an Android plugin for Unity3D v4.5 by command prompt, JDK, SDK and Apache Ant. The command "ant jar" built it with no errors, but when I try to open my game in my mobile device, he tells me: "Unfortunately, TheGame has stopped." My mobile is Android 4.1.2 (Api 16) and I built the game in Api 15.

Before using plugin I had no problems and I had no errors using Apache and JDK.


This is my java code "MyLibrary.java" in src\com\test\app:

package com.test.app;
import com.unity3d.player.UnityPlayerActivity;
public class MyLibrary extends UnityPlayerActivity
{
    public static float GetValue()
    {
        return 1.0f;
    }
} 

As you see, I want to use it to simply get a float number (1.0f)


This is the Manifest:

<?xml version="1.0" encoding="utf-8"?>
<manifest
    xmlns:android="http://schemas.android.com/apk/res/android"
    package="com.test.app"
    android:versionCode="1"
    android:versionName="1.0">
    <supports-screens
        android:smallScreens="true"
        android:normalScreens="true"
        android:largeScreens="true"
        android:xlargeScreens="true"
        android:anyDensity="true"/>

    <application android:label="@string/app_name" android:icon="@drawable/app_icon">
        <activity android:name=".MyLibrary"
            android:label="@string/app_name"
            android:configChanges="fontScale|keyboard|keyboardHidden|locale|mnc|mcc|navigation|orientation|screenLayout|screenSize|smallestScreenSize|uiMode|touchscreen">
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />
                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>

        <activity android:name="com.unity3d.player.UnityPlayerActivity"
                  android:label="@string/app_name"
                  android:configChanges="fontScale|keyboard|keyboardHidden|locale|mnc|mcc|navigation|orientation|screenLayout|screenSize|smallestScreenSize|uiMode|touchscreen">
        </activity>

    </application>
</manifest>

And it`s my C# Script for unity:

using UnityEngine;
using System.Collections;

public class Test : MonoBehaviour {
    AndroidJavaClass pluginTutorialActivityJavaClass;

    public string GetValue () 
    {
        AndroidJNI.AttachCurrentThread();
        pluginTutorialActivityJavaClass = new AndroidJavaClass("com.test.app.MyLibrary");
        float number = pluginTutorialActivityJavaClass.CallStatic<float>("GetValue");
        return number.ToString();
    }

    string val = "";
    void OnGUI()
    {
        if(GUI.Button(new Rect(0,0,200,200),"GetValue"))
        {
            val = GetValue();
        }
        GUI.TextArea(new Rect(0,200,200,200),val);
    }
}

Did I do something wrong? Help me please Thanks

0

There are 0 best solutions below