- Home /
Leadbolt Unity Plugin Example gets JNI Exception
Hello, I'm rather new to Unity and I try to build a simple app to test most of Unity.
But since I also want to monetize my future stuff, I wanted to try out 3rd party plugins for monetization. Since I have used Leadbolt before, I hoped I could use it here on Unity again.
I downloaded everything from Leadbolt and tried to set it up, but I only got an NullPointerExeption. I tried the example-app from Leadbolt itself and got the same error.
Since it is the example app who also throws the exeption I guess I did something wrong when I set up the environment. I use the sdk Android 5.0(API 21) and JRE1.8._025.
This is the error message I get from Unity:
Exception: JNI: Init'd AndroidJavaClass with null ptr! UnityEngine.AndroidJavaClass..ctor (IntPtr jclass) (at C:/BuildAgent/work/d63dfc6385190b60/Runtime/Export/AndroidJavaImpl.cs:539) UnityEngine.AndroidJavaObject.get_JavaLangClass () (at C:/BuildAgent/work/d63dfc6385190b60/Runtime/Export/AndroidJavaImpl.cs:517) UnityEngine.AndroidJavaObject.FindClass (System.String name) (at C:/BuildAgent/work/d63dfc6385190b60/Runtime/Export/AndroidJavaImpl.cs:508) UnityEngine.AndroidJavaClass._AndroidJavaClass (System.String className) (at C:/BuildAgent/work/d63dfc6385190b60/Runtime/Export/AndroidJavaImpl.cs:528) UnityEngine.AndroidJavaClass..ctor (System.String className) (at C:/BuildAgent/work/d63dfc6385190b60/artifacts/EditorGenerated/AndroidJava.cs:93) AppTrackerAndroid.initializeAppTracker () (at Assets/AppTrackerAndroid.cs:17) AppTrackerAndroid.startSession (System.String apikey) (at Assets/AppTrackerAndroid.cs:24) Ad.Start () (at Assets/Ad.cs:15)
Answer by liortal · Dec 10, 2014 at 07:01 AM
Somewhere in your code you are initializing the plugin like this:
AndroidJavaClass plugin = new AndroidJavaClass("fullname");
The name you pass to this constructor cannot be found, which can be caused by a few reasons:
You misspelled the plugin's class full name? (it should be the FULL NAME, e.g: package.class)
You did not include the plugin's library in your build. The plugin's code should be included with your project so it can be accessed at runtime. Usually you would place your plugin's JAR under Plugins/Android so it will be packaged with your game when you export it.
Yes, it is this: AndroidJavaClass jc = new AndroidJavaClass("com.unity3d.player.UnityPlayer");
I included every jar and cs-file like described in the readme, I also changed the manifest.xml, like it said und put it in Plugins/Android.
In another forum I found the hint, that it only throws an error because it's not on an android device, but when I try to run it on my device the app simply crashes.
This call will not work unless you're on Android (this call reaches out to the Java V$$anonymous$$ and locates a loaded class with that name. In the editor or other platforms this will fail). Try to run it on an Android device and get the logs they will show what's going on (use logcat).
Your answer
Follow this Question
Related Questions
Accessing Data from a Android java class 1 Answer
Issue installing apk using old Cert 1 Answer
Error Building Android Project 2 Answers