Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
  • Help Room /
avatar image
0
Question by Inboxninja · Apr 22, 2017 at 04:53 AM · androidplugins

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

Comment
Add comment · Show 4
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image liortal · Apr 23, 2017 at 06:26 AM 0
Share

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..

avatar image Inboxninja liortal · Apr 23, 2017 at 07:03 AM 0
Share

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

avatar image liortal Inboxninja · Apr 23, 2017 at 03:42 PM 0
Share

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 :)

Show more comments

1 Reply

· Add your reply
  • Sort: 
avatar image
1
Best Answer

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>
Comment
Add comment · Show 1 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image liortal · Apr 24, 2017 at 08:08 PM 0
Share

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

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this Question

Answers Answers and Comments

159 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

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


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges