Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. Dismiss Notice

[2020.3] com.unity3d.player.ReflectionHelper$a.<init> fatal exception

Discussion in 'Android' started by edgaretermax, Sep 21, 2022.

  1. edgaretermax

    edgaretermax

    Joined:
    Sep 21, 2022
    Posts:
    1
    Hi, we are facing the following exception in Android, after reviewing firebase dashboard we've found the following stack trace:

    Caused by java.lang.NullPointerException: Attempt to invoke virtual method 'int java.lang.String.hashCode()' on a null object reference
    at com.unity3d.player.ReflectionHelper$a.<init>:)19)
    at com.unity3d.player.ReflectionHelper.getMethodID:)2)

    Fatal Exception: java.lang.Error: FATAL EXCEPTION [Thread-9123]
    Unity version : 2020.3.34f1
    Android OS: 12

    Thanks in advance
     
  2. vbogorodskiy

    vbogorodskiy

    Joined:
    Apr 21, 2021
    Posts:
    1
    Hi! We also have a ton of crashes with this stack trace:

    Caused by: java.lang.NullPointerException: Attempt to invoke virtual method 'int java.lang.String.hashCode()' on a null object reference
    at com.unity3d.player.ReflectionHelper$a.<init>
    at com.unity3d.player.ReflectionHelper.getMethodID

    We updated Unity from 2020.1.17f1 to 2020.3.34f1 but it looks like it had no effect on the issue
     
  3. Mike_Olv

    Mike_Olv

    Joined:
    Sep 11, 2017
    Posts:
    7
    Hi! Do you have any updates on this errors?
    We are experiencing the same error on our side :(
     
  4. Mayis

    Mayis

    Joined:
    Feb 1, 2014
    Posts:
    6
    We also see very similar fatal exception in Crashlytics Dashboard. The amount of crashes is critical, because of this exception. Will be good Unity developers response to this thread.

    96% of crash devices has OS: Android 12
    4% of crash devices has OS: Android 13

    We are using Unity 2020.3.41f1 version.


    Caused by java.lang.NullPointerException: Attempt to invoke virtual method 'int java.lang.String.hashCode()' on a null object reference
    at com.unity3d.player.ReflectionHelper$a.<init>(:19)
    at com.unity3d.player.ReflectionHelper.getFieldID(:10)
     
    Last edited: Nov 14, 2022
  5. BBO_Lagoon

    BBO_Lagoon

    Joined:
    Mar 2, 2017
    Posts:
    189
    Hi,
    I'm currently adding AdMob to my project and I have the same error sometimes, do you use AdMob too ? maybe it's related because I did not have this but before.
     
  6. Bestlis

    Bestlis

    Joined:
    Jan 15, 2014
    Posts:
    32
    I have the same issue in 2021.3.13f1. Any updates?
     
  7. Bestlis

    Bestlis

    Joined:
    Jan 15, 2014
    Posts:
    32
    I have InApp purchasing in my game v. 4.4.1. WHen game started I got warning message:
    Unity IAP: <b>Unity In-App Purchasing</b> requires <b>Unity Gaming Services</b> to have been initialized before use
    I added init code:

    Code (CSharp):
    1. const string k_Environment = "production";
    2.  
    3. void Initialize(Action onSuccess, Action<string> onError)
    4. {
    5.     try
    6.     {
    7.         var options = new InitializationOptions().SetEnvironmentName(k_Environment);
    8.  
    9.         UnityServices.InitializeAsync(options).ContinueWith(task => onSuccess());
    10.     }
    11.     catch (Exception exception)
    12.     {
    13.         onError(exception.Message);
    14.     }
    15. }
    16.  
    17. void OnSuccess()
    18. {
    19.     var text = "Congratulations!\nUnity Gaming Services has been successfully initialized.";
    20.     informationText.text = text;
    21.     Debug.Log(text);
    22. }
    23.  
    24. void OnError(string message)
    25. {
    26.     var text = $"Unity Gaming Services failed to initialize with error: {message}.";
    27.     informationText.text = text;
    28.     Debug.LogError(text);
    29. }
    And when I added this code I got this error.

    Update: when I changed code to
    Code (CSharp):
    1. const string k_Environment = "production";
    2.  
    3. async void Initialize(Action onSuccess, Action<string> onError)
    4. {
    5.     try
    6.     {
    7.         var options = new InitializationOptions().SetEnvironmentName(k_Environment);
    8.  
    9.         await UnityServices.InitializeAsync(options);
    10.  
    11.        OnSuccess();
    12.     }
    13.     catch (Exception exception)
    14.     {
    15.         onError(exception.Message);
    16.     }
    17. }
    18.  
    19. void OnSuccess()
    20. {
    21.     var text = "Congratulations!\nUnity Gaming Services has been successfully initialized.";
    22.     informationText.text = text;
    23.     Debug.Log(text);
    24. }
    25.  
    26. void OnError(string message)
    27. {
    28.     var text = $"Unity Gaming Services failed to initialize with error: {message}.";
    29.     informationText.text = text;
    30.     Debug.LogError(text);
    31. }
    crash stoped.
     
    Last edited: Nov 15, 2022
  8. Mayis

    Mayis

    Joined:
    Feb 1, 2014
    Posts:
    6
    Yes we use AdMob in our project.
     
  9. formatingxie

    formatingxie

    Joined:
    Jun 18, 2021
    Posts:
    1
    java.lang.NullPointerException: Attempt to invoke virtual method 'int java.lang.Object.hashCode()' on a null object reference
    at com.unity3d.player.ReflectionHelper$a.<init>(Unknown Source:11)
    at com.unity3d.player.ReflectionHelper.getMethodID(Unknown Source:2)
    unity 2019.4.10 I met the same problem,
     
  10. daven_tk

    daven_tk

    Joined:
    Nov 15, 2022
    Posts:
    1
    I also encountered the same problem, but I can't reproduce it locally. Can anyone provide a stable reproduction step?
    Unity version : 2020.3.25f1c1
    Android OS: 12+
    Target:31

    Thanks
     
  11. BBO_Lagoon

    BBO_Lagoon

    Joined:
    Mar 2, 2017
    Posts:
    189
    I had Unity Mediation packages residual files + admob, I think the plugins was colliding.
    After removing the Unity Mediation files all is ok.
     
  12. BBO_Lagoon

    BBO_Lagoon

    Joined:
    Mar 2, 2017
    Posts:
    189
    Hmm seems I talked too fast, the error is still here, but very rare and I can't find a way to reproduce it.
     
  13. BBO_Lagoon

    BBO_Lagoon

    Joined:
    Mar 2, 2017
    Posts:
    189
    OK, find a way to reproduce the bug using AdMob at 100%

    Code (CSharp):
    1.  
    2.     public void CreateAndLoadRewardedAd()
    3.     {
    4.         #if UNITY_ANDROID
    5.             string adUnitId = "ca-app-pub-3940256099942544/5224354917";
    6.         #elif UNITY_IPHONE
    7.             string adUnitId = "ca-app-pub-3940256099942544/1712485313";
    8.         #else
    9.             string adUnitId = "unexpected_platform";
    10.         #endif
    11.  
    12.         this.rewardedAd = new RewardedAd(adUnitId);
    13.  
    14.         this.rewardedAd.OnAdLoaded += HandleRewardedAdLoaded;
    15.         this.rewardedAd.OnUserEarnedReward += HandleUserEarnedReward;
    16.         this.rewardedAd.OnAdClosed += HandleRewardedAdClosed;
    17.  
    18.         // Create an empty ad request.
    19.         AdRequest request = new AdRequest.Builder().Build();
    20.         // Load the rewarded ad with the request.
    21.         this.rewardedAd.LoadAd(request);
    22.     }
    23.  
    24.     public async void HandleRewardedAdClosed(object sender, EventArgs args)
    25.     {
    26.         await Task.Delay(2000);
    27.         CreateAndLoadRewardedAd(); // here the crash happen !
    28.     }
    29.  
    Just trying to reload the ad after an async delay makes the app crash.
    In case of load failed I added a reload after a delay and the crash happend in these case.

    To fix the issue in this case just use something like https://github.com/PimDeWitte/Unity...b/master/Runtime/UnityMainThreadDispatcher.cs.

    So changing the above code with:
    Code (CSharp):
    1.  
    2.     public async void HandleRewardedAdClosed(object sender, EventArgs args)
    3.     {
    4.         await Task.Delay(2000);
    5.         UnityMainThreadDispatcher.Instance().Enqueue( CreateAndLoadRewardedAd ); // no crash here
    6.     }
    7.  
    Fixes the bug.

    Hope this could help someone ;)
     
  14. AminAghajoon

    AminAghajoon

    Joined:
    May 17, 2013
    Posts:
    20
    We do not use Admob but we are also getting this error:
    Unity 2020.3.30f1

    Code (CSharp):
    1. Caused by: java.lang.NullPointerException: Attempt to invoke virtual method 'int java.lang.String.hashCode()' on a null object reference
    2.   at com.unity3d.player.ReflectionHelper$a.<init>
    3.   at com.unity3d.player.ReflectionHelper.getMethodID
     
    Last edited: Nov 27, 2022
    dan_ginovker likes this.
  15. BBO_Lagoon

    BBO_Lagoon

    Joined:
    Mar 2, 2017
    Posts:
    189
    Do you call native function after an await ?
     
  16. AminAghajoon

    AminAghajoon

    Joined:
    May 17, 2013
    Posts:
    20
    No, we are not using Await/Async.
     
    Last edited: Dec 17, 2022
  17. AminAghajoon

    AminAghajoon

    Joined:
    May 17, 2013
    Posts:
    20
    Did you managed to find the problem?
     
  18. BBO_Lagoon

    BBO_Lagoon

    Joined:
    Mar 2, 2017
    Posts:
    189
    After making the update available on the store I have lot of errors spamming in the Android Vital page, I deactivate the ads and the errors stopped.
    Anyone finds a way to correct this error ?
    Maybe someone from Unity could read this topic and gives some help ?

    As I think the bug is related somehow to AdMob I also posted in the AdMob issue tracker:
    https://github.com/googleads/googleads-mobile-unity/issues/2480
     
    Last edited: Jan 12, 2023
  19. Mike_Olv

    Mike_Olv

    Joined:
    Sep 11, 2017
    Posts:
    7
    So it didn't worked at the end?
     
  20. BBO_Lagoon

    BBO_Lagoon

    Joined:
    Mar 2, 2017
    Posts:
    189
    It kind of worked as before the fix I had 100% reproductible bug and after I never reproduce it on my test devices. In production I have still some crash because of this bug (1000 crash on 400 unique users on 15 days on my game with near 10000 daily users).
    But this bug has caused my game to reach the crash rate limit on google play store, so I had to disable AdMob for the moment. I'm currently trying to resolve the issue (changing ad mediation partner) to be able te re-activate ads on my game.
     
    Mike_Olv likes this.
  21. Mike_Olv

    Mike_Olv

    Joined:
    Sep 11, 2017
    Posts:
    7
    Thank you for your quick answer! We are also trying to fix this errors on our games. If we manage to find something, I will update this thread

    We are using Unity 2020.3.38 and ApplovinMAX as mediation of the advertising networks.
    We will try to update to 2021.3 on some of our games. But as Unity 2021.3 was shipped with a bugged NDK, we don't want to be based on this version of Unity.
    We hope Unity will release an LTS version of 2022 soon
     
  22. BBO_Lagoon

    BBO_Lagoon

    Joined:
    Mar 2, 2017
    Posts:
    189
    I'm currently on the 2021.3.14f1 and I have the bug so no need to upgrade to 2021.3 ;)
    For the NDK bug, it's a little random, sometimes the build succeed, sometimes not, so I changed the C++ Compiler Configuration to "release" instead of "master", now the build always succeed.
     
  23. Mike_Olv

    Mike_Olv

    Joined:
    Sep 11, 2017
    Posts:
    7
    Ok good to know! Thanks :D

    Yeah but when you set the C++ Compiler Configuration to `release` it increases the AAB/APK size. In our case we were above the 150MB size limit of GooglePlay console
     
  24. TelloSoft

    TelloSoft

    Joined:
    Oct 29, 2019
    Posts:
    17
    Same issue on my side, has anyone resolved it?
     
  25. TelloSoft

    TelloSoft

    Joined:
    Oct 29, 2019
    Posts:
    17
    BBO_Lagoon can you please confirm if I disable admob plugin, will this crash not happen? I am using 2021.3.16f1 LTS with Google Ads 7.2.0
     
  26. BBO_Lagoon

    BBO_Lagoon

    Joined:
    Mar 2, 2017
    Posts:
    189
    On my game, I disabled the videos (SDK still here but initialisation and ads code is not called) and now the crash don't happen anymore.
     
  27. Mike_Olv

    Mike_Olv

    Joined:
    Sep 11, 2017
    Posts:
    7
    Ok so it's only Fullscreen ads (Rewarded videos and Interstitial videos). Seems normal as they are using the same code for display
     
  28. ByMedion

    ByMedion

    Joined:
    May 10, 2018
    Posts:
    19
    Unity 2021.3.11, same issue. No Admob, no Unity Services
     
  29. unity_BBC92DE73332ECB1B686

    unity_BBC92DE73332ECB1B686

    Joined:
    Jul 4, 2022
    Posts:
    2
    I am also using Applovin Max SDK ads for my game and I am facing almost same problem. There are a lots of crashes for Android OS version 11 and 12 as reported by play store. Is there any update for this problem?
     
  30. BBO_Lagoon

    BBO_Lagoon

    Joined:
    Mar 2, 2017
    Posts:
    189
  31. MigrantP

    MigrantP

    Joined:
    Jun 24, 2013
    Posts:
    116
    Also running into this today on Unity 2021.3.18f1. Weirdly it's only happening on one build variant (production, not beta) that are fairly similar to each other (same AndroidManifest.xml, etc). We don't use ads, just Unity IAP.
     
  32. MigrantP

    MigrantP

    Joined:
    Jun 24, 2013
    Posts:
    116
    This is still happening in Unity 2021.3.21f1 and is going to be a blocker for us. Any ideas? Unity 2022?
     
  33. MigrantP

    MigrantP

    Joined:
    Jun 24, 2013
    Posts:
    116
    I sent a report in via the bug reporter. In the meantime I will try Unity 2022.
     
  34. MigrantP

    MigrantP

    Joined:
    Jun 24, 2013
    Posts:
    116
    Updating to Unity 2022.2.11f1 seems to have solved this for us.
     
  35. Muhmer

    Muhmer

    Joined:
    Oct 20, 2021
    Posts:
    1
    Hello, I had the same crash on a test phase of IAP system. The crash was happening because of a code line just like this one => UnityServices.InitializeAsync(options).ContinueWith(task => onSuccess()); Unity version was 2021.3.16f1.

    I think this code causes onSuccess to be called on a thread other than main thread. And since UnityEngine library is not thread safe and not suitable for multithreading it throws an exception. In situations like this usually there is another method named as ContinueWithMainThread() or sth like that.

    When I stopped using ContinueWith() method the crash was fixed.
     
    Russopelegrosso likes this.
  36. MigrantP

    MigrantP

    Joined:
    Jun 24, 2013
    Posts:
    116
    I had the problem in async void Awake() calling await UnityServices.InitializeAsync(options);

    Still seems happy on Unity 2022 so we're going with that.
     
  37. lToTyl

    lToTyl

    Joined:
    Mar 1, 2020
    Posts:
    1
    Hi everyone, I am from the same company that Edgar, the starter of this thread.

    We found a solution for this issue, in our case the problem was caused because some metrics were tracked in other threads that was not the MainThread. We use UniRX in our project and we think that this could be related to this issue.

    The recommendation is to check the events of firebase (or other metric software, we have 4 different in our project) and force this process to go through the MainThread of Unity.

    Every call of native java code in Unity must go through the MainThread or has to be attached with AttachCurrentThread() method.

    I hope this could help someone. Thank everyone for the help and research!
     
    dan_ginovker likes this.
  38. trooper

    trooper

    Joined:
    Aug 21, 2009
    Posts:
    746
    The error went away for us, I only did 2 things.

    I added more switching to main thread during advert loading and showing but my testers were still able to crash the build (I didn't release to users).

    I also turned incremental GC back on (I had turned it off at the same time the errors started comming in), i released this and that specific crash seems to have gone away (although GC_locks are back.
     
  39. Russopelegrosso

    Russopelegrosso

    Joined:
    Dec 10, 2018
    Posts:
    1
    This solution helped me, I had a problem after updating to Unity 2021.3.16. It was associated with Firebase.FirebaseAppCheckAndFixDependenciesAsync(). ContinueWit() after switching to ContinueWithOnMainThread() the problem disappeared.