简体   繁体   中英

Android Plugin for Unity giving errors

i was doing a test application to learn how we cam use java code in unity through Plugin.

I created a simple Android Activity class using Android 3.2 in eclipse.

package com.control.unitycontrol;
import com.unity3d.player.UnityPlayerActivity;
import android.os.Bundle;
import android.util.Log;
import android.widget.Toast;
public class MainActivity extends UnityPlayerActivity  {
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        Log.d("TEST","Foo method is called is called 1111");


    }

    public static void foo(){

        Log.d("TEST","Foo method is called is called 2222");  // this method is never called



    }}

Here is my AndroidManifest.xml

<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="com.control.unitycontrol"
    android:versionCode="1"
    android:versionName="1.0" >

    <uses-sdk
        android:minSdkVersion="8"
        android:targetSdkVersion="15" />

    <application
        android:icon="@drawable/ic_launcher"
        android:label="@string/app_name"
        android:theme="@style/AppTheme" >
        <activity
            android:name=".MainActivity"
            android:label="@string/title_activity_main"
             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>
    </application>

</manifest>

According to the tutorial I copied classes.jar to my libs folder then added it to my classpath..

then I made my project "Is Library ".

Finally I added my unitycontrol.jar to Assests->Plugins->Android folder along with the AndroidManifest.xml.

To Access my code in C# script I wrote.

using (AndroidJavaClass cls_UnityPlayer = new AndroidJavaClass("com.unity3d.player.UnityPlayer")) 


        {

            using (AndroidJavaObject obj_Activity = cls_UnityPlayer.GetStatic<AndroidJavaObject>("currentActivity")) 

        {

                obj_Activity .CallStatic("foo");

        }

    }

When i play my scene I get error saying:

JNI: Unable to find field id for 'currentActivity' (static) UnityEngine.AndroidJavaObject:GetStatic(String)

If I try to build it I get error saying :

* Failed to re-package resources with the following parameters: package -v -f -m -J gen -M AndroidManifest.xml -S "res" -I "C:/Users/sumit/Documents/android-sdk-windows/platforms/android-16\\android.jar" -F bin/resources.ap_ Configurations:*

Any Help ...!!! What can I do resolve this Issue

Just try to remove AndroidManifest.xml? For library, it is useless.

从应用程序标签中删除图标/主题/标签,绝对有效。

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM