Android java plugin only works in a developement build
Hi there... I created a simple android java plugin to take html and print it. It works fine in development builds, but not at all in a non-development build. The logcat shows no appreciable difference between the two builds, and there are no errors that are shown that tell me it's permissions, or something else.
the plugin itself is quite basic, and works fine in dev builds, so I'm at a loss as to what could be different between the two apks. I've tried giving the app all permissions in the manifest (no luck) and coming the logcat yields nothing useful.
the plugin is here: paste bin
and the code used to call it is:
using (var javaUnityPlayer = new AndroidJavaClass("com.unity3d.player.UnityPlayer"))
{
using (var currentActivity = javaUnityPlayer.GetStatic<AndroidJavaObject>("currentActivity"))
{
using (var androidPlugin = new AndroidJavaObject("com.funtobuildgames.AndroidPrint.AndroidPrint", currentActivity))
{
Debug.Log("before androidPlugin.Call");
androidPlugin.Call("DoPrint", HTML, docName);
Debug.Log("after androidPlugin.Call");
}
}
}
Any help would be appreciated
Not really sure what is the matter here (might be different reasons), but you can try add this code before you call into Java code:
AndroidJNIHelper.debug = true;
Then, when running on your Android device, take a look at the logcat log, to see if you find any errors when accessing your Java code from Unity..
I had tried that earlier, however AndroidJNIHelper.debug = true; only seems to work in development build .. and since my issue only happens in a release build, it's not helpful.
Thanks for the suggestion tho
I am not sure that is true. Development builds have this enabled by default, but turning it on in non-development builds should have an effect from what i remember.
It could also help to show the logcat logs (from dev and non-dev builds). it's funny but usually these things have the simplest answers eventually :)
Answer by Inboxninja · Apr 24, 2017 at 11:02 AM
What a wild ride... it turns out that, when running development builds, for some reason the plugin is running in the UI thread, but not in the release builds. When I put everything inside .runOnUiThread, all is well
public void DoPrint(final String html_body,final String doc_name) {
((Activity)context).runOnUiThread(new Runnable(){
@Override
public void run() {
<etc>
i don't think the plugin runs in the UI thread in development builds. your Unity code that calls into the plugin runs from the scripting thread (which is not the UI thread). Development builds may have less "strict" enforcing of certain requirements. if it's really interesting, i can check with one of the Unity android developers i am in contact with..
Your answer
![](https://koobas.hobune.stream/wayback/20220612120415im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
Related Questions
Unity Android Plugin onActivityResult not called 0 Answers
Is build.gradle take in account when building? 0 Answers
How to use App indexing Api's by extending a class with Prime31 's UnityPlayerActivity ? 0 Answers
i want to use dji sdk in unity, i tried to make unity android plugin, but it doesn't work 3 Answers
Native Plugin to get Users phone number 0 Answers