Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 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 /
avatar image
1
Question by trs9556 · Aug 05, 2013 at 12:40 AM · androidjava4.2

JNI Exception in the editor [Android] Unity 4.2

Hello,

So I just updated to Unity 4.2 and I now get this error in my console when running my game:

Exception: JNI: Init'd AndroidJavaClass with null ptr!

UnityEngine.AndroidJavaClass..ctor (IntPtr jclass) (at C:/BuildAgent/work/cac08d8a5e25d4cb/Runtime/Export/AndroidJavaImpl.cs:533)

Now I ignored this error at first because I assumed it was because I'm not on an Android device. But because of this error my events don't work so I can't truely test my game without exporting it.

Let me note that this error did NOT happen on Unity 4.1, I did no change in my code, just updated Unity.

This is the code that is cuasing the error:

     #if UNITY_ANDROID
         AdClass = new AndroidJavaClass("com.package.name.Ads");    
     #endif

AdClass is declared as followed

     public static AndroidJavaClass AdClass;
  
  

When I build my APK and put it on my android device there are no problems. So this is just happening in the editor. Like stated before I can't ignore this error because it stops all my events so my game doesn't run properly.

Anyone have any suggestions on how I can get rid of this error?

Comment
Add comment
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

4 Replies

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

Answer by trs9556 · Aug 05, 2013 at 12:58 AM

So this isn't a solution but it is a work around:

I added this around my JavaClass calls:

 #if UNITY_EDITOR
     ignoreAdClass = true;
 #endif
     
     
 #if UNITY_ANDROID
     if(!ignoreAdClass){
         AdClass = new AndroidJavaClass("com.package.name.Ads");    
     }
 #endif

  

And I declared ignoreAdClass as false initially.

(Any real solution rather than a work around would still be greatly appreciated.

Comment
Add comment · 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
6

Answer by xanxa3624 · Dec 15, 2013 at 01:48 PM

I had the same problem and I used this:

  #if UNITY_ANDROID && !UNITY_EDITOR
       AdClass = new AndroidJavaClass("com.package.name.Ads"); 
  #endif

I hope it's works for you.

Comment
Add comment · Show 2 · 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 Bunny83 · Dec 15, 2013 at 01:51 PM 0
Share

I just saw this question being bumbed without any new posts or edits, so i checked the moderation queue and found your answer ;)

I was about to post an answer or comment suggesting this since it make the most sense. JNI only works on the actual device. UNITY_ANDROID is just a switch for the targetplatform, but doesn't exclude the editor.

+1

avatar image RFLG · Sep 13, 2014 at 01:01 AM 0
Share

Solved the same issue just fine! +1

avatar image
1

Answer by viame · Aug 11, 2013 at 11:32 AM

How about using this code

if(Application.platform == RuntimePlatform.Android) // do something in android platform

Comment
Add comment · 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
0

Answer by liortal · Sep 14, 2014 at 10:38 PM

UNITY_ANDROID will be defined if the Android platform is selected in the Build Settings menu.

In order to ignore this code inside the editor, you can check use an extra #if:

 #if UNITY_EDITOR
     // do nothing ?
 #elif UNITY_ANDROID
         AdClass = new AndroidJavaClass("com.package.name.Ads");    
 #endif

Comment
Add comment · 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

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

18 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

Related Questions

AndroidJavaClass. Call returns null ptr. 1 Answer

Using PackageManager to launch/check app on Android 1 Answer

NoSuchMethodError calling android method 2 Answers

How to pass Java object to C#? 2 Answers

Using AndroidJavaClass in a java Unity3d plugin 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