简体   繁体   English

Unity的Android插件给出了错误

[英]Android Plugin for Unity giving errors

i was doing a test application to learn how we cam use java code in unity through Plugin. 我正在做一个测试应用程序,以了解我们如何通过插件使用java代码统一使用java代码。

I created a simple Android Activity class using Android 3.2 in eclipse. 我在eclipse中使用Android 3.2创建了一个简单的Android Activity类。

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 这是我的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.. 根据教程,我将classes.jar复制到我的libs文件夹,然后将其添加到我的类路径中。

then I made my project "Is Library ". 然后我制作了我的项目“Is Library”。

Finally I added my unitycontrol.jar to Assests->Plugins->Android folder along with the AndroidManifest.xml. 最后,我将unitycontrol.jar与AndroidManifest.xml一起添加到Assests-> Plugins-> Android文件夹中。

To Access my code in C# script I wrote. 我在C#脚本中访问我的代码。

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) JNI:无法找到'currentActivity'的字段ID(静态)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:* * 无法使用以下参数重新打包资源: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_配置:*

Any Help ...!!! 任何帮助...... !!! What can I do resolve this Issue 我该怎么做才能解决这个问题

Just try to remove AndroidManifest.xml? 试着删除AndroidManifest.xml? For library, it is useless. 对于图书馆来说,这是没用的。

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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