Search Unity

How to use javaPlugin in unity

Discussion in 'Android' started by rasarahul, Mar 11, 2011.

  1. rasarahul


    Jan 19, 2011
    Hello all,

    I am trying use the sample ndk application given with android ndk in unity.

    public class HelloJni extends Activity
    public void onCreate(Bundle savedInstanceState)
    TextView tv = new TextView(this);
    tv.setText( stringFromJNI() );

    /* A native method that is implemented by the
    * 'hello-jni' native library, which is packaged
    * with this application.
    public native String stringFromJNI();

    This is my Jni

    #include <string.h>
    #include <jni.h>

    jstring Java_com_myownjni_jni_HelloJni_stringFromJNI( JNIEnv* env,
    jobject thiz )
    return (*env)->NewStringUTF(env, "Hello from JNI !");
    I have built the whole project,i placed the libhello-jni inside plugin/Android,from Unity i tried to access the library like this below
    using UnityEngine;
    using System.Collections;
    using System.Runtime.InteropServices;
    using System;

    public class CallJavaCode : MonoBehaviour {

    private static extern string stringFromJNI();

    private string myText= "Get value from Jni";
    void OnGUI ()
    if (GUI.Button(new Rect (15, 125, 450, 100), myText))
    string textFromJni= stringFromJNI();

    myText= textFromJni;

    But i am not getting any result,should i place the jar of the java class???
    Can anyone help