- Home /
How Set Java Plugin on Unity?
I recently started developing a Java plugin. I developed the Java code at Eclipse, and tested it, its works on Android just fine. After that, I checked the projet as 'Library', and dragged my jar file to the Assets/Plugins/Android folder at my Unity project. After that I did a C# code, to call the Android functions. It should work, but do far I have not figured out the problem.
When I play it at the editor, with the remote and the device, it apears that "JNI: Init'd AndroidJavaClass with null ptr!", and when I copy the apk directly at the device and install it, it just doesn't work.
Bellow, my C# code:(the void GetAlarm is the one triggered by a button)
using UnityEngine;
using System.Runtime.InteropServices;
using System.Collections;
public class Awaker : MonoBehaviour {
#if UNITY_ANDROID
public AndroidJavaClass pluginWaker;
public int num;
public void GetAlarm(){
AndroidJNI.AttachCurrentThread();
pluginWaker = new AndroidJavaClass("com.example.awaker.Main"
SetAlarm();
SetInt();
numLabel.text = num.ToString();
}
public void SetAlarm(){
AndroidJNI.AttachCurrentThread();
pluginWaker = new AndroidJavaClass("com.example.awaker.Main");
pluginWaker.Call("setAlarm",14,22);
}
public void SetInt(){
num = pluginWaker.Call<int>("getNumber");
}
#endif
}
Your answer
Follow this Question
Related Questions
Send message to Java Code (without a plugin)? 1 Answer
How do you access a custom Java class from Unity? 1 Answer
Problem in android java plugin 0 Answers
Compass java plugin for Unity Android 4 Answers
Calling static jar function from Unity3D 0 Answers