- Home /
Integrate Eclipse and Unity
Hi; I wanna integrate unity with Eclipse, so in Unity i write this script:
using UnityEngine; using System.Collections;
public class Test : MonoBehaviour {
void OnGUI() {
if(GUI.Button(new Rect(20,70,80,20), "Call Android Method"))
{
using (AndroidJavaClass cls_UnityPlayer = new AndroidJavaClass("com.unity.eclipse"))
{
using (AndroidJavaObject obj_Activity = cls_UnityPlayer.GetStatic<AndroidJavaObject>("MainActivity"))
{
obj_Activity .CallStatic("foo");
}
}
}
}
and in Eclipse i create an android Applicatio and create a MainActivity.java in which i write this:
package com.unity.eclipse;
import com.unity3d.player.UnityPlayerActivity; public class MainActivity extends Activity {
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
}
public static void foo(){
Log.d("TEST","Foo method is called is called");
}
}
i exported the project as a jar file and import it in my unity project in Standard Assets/Plugins/Android folder and when i press play , the console shows me these messages:
JNI: Unable to find field id for 'MainActivity' (static) JNI: Init'd AndroidJavaObject with null ptr! JNI: Unable to find method id for 'foo' (static)
i m testing this because i want to create a facebook android project in eclipse and export it as a jar file , import it in unity and show a facebook user id and build it in Android.
Thanks for your help
$$anonymous$$ay I see your logcat output? Ive been struggling with the same exception this week, and maybe I could help. In my case the problem was with the way I was importing the .jar, and the trick to solve it was to copy and paste the .jar in my project's "libs" folder and add it from the Java Build Path screen, ins$$anonymous$$d of adding it as external jars. Hope this helps :)
Please format your code. If you don't know how, you need to watch the tutorial video on the right :)