googleads / googleads-mobile-unity

Official Unity Plugin for the Google Mobile Ads SDK
https://developers.google.com/admob/unity
Apache License 2.0
1.36k stars 1.08k forks source link

Alot of ANRs and crashes after updating to 7.x #2093

Closed gjerek closed 2 years ago

gjerek commented 2 years ago

I don't know how to reproduce, but this is screen shot from google play console, after we upgraded from 6.0.2 to new admob plugins all of this started:

image image

Admob team this is really critical, because of all new SDKs we upgraded Unity version and now we don't really want to go back. Can you give us some advice what to do?

We are also using those optimization flags: <meta-data android:name="com.google.android.gms.ads.flag.OPTIMIZE_INITIALIZATION" android:value="true"/> <meta-data android:name="com.google.android.gms.ads.flag.OPTIMIZE_AD_LOADING" android:value="true"/>

Please any advice would be appreciated, because google is now ranking us very badly because of this...

gjerek commented 2 years ago

Ok I will close this issue, basicly the problem is on Android with Unity versions after May (2021.3.2 and 2020.3.34 are fine, newer ones are not) and Legacy Input system.

adbourdages commented 2 years ago

Thanks for the update and confirming the Unity versions that are safe. I've just release a version using the new unity input system and will update the thread dedicated to that bug when I get some solid results.

touch2goal commented 2 years ago

Cool, I will downgrade to 2021.3.2 to see if it can solve the problem.

adbourdages commented 2 years ago

@touch2goal on my end, downgrading to that version seems to have solved it, but I haven't done an 1h+ play test yet

nauman415 commented 2 years ago

@gjerek your anrs are still under control or any not? please guide us

gjerek commented 2 years ago

@gjerek your anrs are still under control or any not? please guide us

Yes everything is fine, just either go with latest versions (they fixed the issue), or the versions we mentioned up above.

RicardoGuzmanVelasco commented 2 years ago

@gjerek your anrs are still under control or any not? please guide us

Yes everything is fine, just either go with latest versions (they fixed the issue), or the versions we mentioned up above.

Then it's fixed also in 2020.3.38f1? Thanks.

ChaserKnight commented 1 year ago

I filed over the weekend (IN-11129). Best I can tell, it is a bug in the legacy input system. The repro project is minimal with only a StandardInputModule and a UI.Text on screen (2021.3.6f1). Reproduction rate is 100% after 20 minutes of constant tapping. The new input system appears clear of this issue.

Unless I'm mistaken the source and nature of the bug indicates that it would affect all games using the legacy input system and ugui :-/

There is a thread about that bug on the unity forums

@adbourdages Is the issue related to this legacy input system also fixed in the newer versions of Unity (2020.3.38f1 and 2021.3.8f1)? Please let me know. Also can you please tell me one more thing, is every call like Input.GetMouseButtonDown() is part of the legacy input system?

adbourdages commented 1 year ago

Version 2021.3.8f1 has the fix (Android: Fix overflow of MotionEvent global references). To answer the other question, yes, 'GetMouseButton' and the likes are part of the legacy input system. If you are trying to root out such calls, the easiest way is to switch the 'Active Input Handling' Player setting to 'New'. All the legacy calls will then turn to compile errors.

I went down the route of re-implementing all of the input handling with the new system and well... it is not as straightforward as you'd hope plus the UI (ugui) got a bit glitchy. On the whole I would not recommend it.

ChaserKnight commented 1 year ago

Version 2021.3.8f1 has the fix (Android: Fix overflow of MotionEvent global references). To answer the other question, yes, 'GetMouseButton' and the likes are part of the legacy input system. If you are trying to root out such calls, the easiest way is to switch the 'Active Input Handling' Player setting to 'New'. All the legacy calls will then turn to compile errors.

I went down the route of re-implementing all of the input handling with the new system and well... it is not as straightforward as you'd hope plus the UI (ugui) got a bit glitchy. On the whole I would not recommend it.

@adbourdages Thank you for answering, I am currently using 2020.3.39f1 as in the forum they mention it also has the fix along with 2021.3.8f1, and the build is pretty stable so far, I did not reply here because I was waiting to see if it is stable or not. I Have not moved to the new input system yet as it will take some time for me to implement. For AdMob I am on 7.1.0 because 7.2.0 was not working for me as mentioned in this issue 2272

Bhutta93 commented 1 year ago

@gjerek your anrs are still under control or any not? please guide us

Yes everything is fine, just either go with latest versions (they fixed the issue), or the versions we mentioned up above.

Can you tell me which Version you are using JDK NDK SDK Gradle with Admob 7.0.2

snappedToGrid commented 1 year ago

Not sure it's the exact same problem, but I figured this could be helpful to someone else reading this thread. I've been getting fatal signal 5 when the "OnUserEarnedReward" event fired. I was taking UI actions there such as hiding a canvas, etc. and apparently this callback function isn't running from the main thread, and if you try and take UI actions, the app might just crash. Sigh.

If you got this problem and you're looking for a quick fix, calling this utility to run UI functions on the main thread can help. https://github.com/PimDeWitte/UnityMainThreadDispatcher

shefich commented 1 year ago

@snappedToGrid correct me if i'm wrong but you can always call MobileAdsEventExecutor.ExecuteInUpdate(() =>{ //code to run on the main thread });

snappedToGrid commented 1 year ago

Oh that might work too, didn't even know it existed. Google should seriously warn about these kind of pitfalls and refer to these kind of solutions. I'd expect as little as that from a company that is earning billions of dollars from advertising. These kind of errors seriously make me consider switching to another ad platform, as it's certainly not the only cryptic problem I had with AdMob so far.

shefich commented 1 year ago

@snappedToGrid this code was found on unity forum, but it is Google code. Btw they added boolean flag MobileAds.RaiseAdEventsOnUnityMainThread for raising ad events on the Unity main thread. You can check release notes for plugin v8.0.0 (https://github.com/googleads/googleads-mobile-unity/releases)

danielebanovaz commented 1 year ago

they added boolean flag MobileAds.RaiseAdEventsOnUnityMainThread for raising ad events on the Unity main thread. You can check release notes for plugin v8.0.0 (https://github.com/googleads/googleads-mobile-unity/releases)

This is true, but it doesn't work for interstitial ads. A fix is pending since 2 months, blocked for no reason: https://github.com/googleads/googleads-mobile-unity/pull/2678

snappedToGrid commented 1 year ago

@snappedToGrid this code was found on unity forum, but it is Google code. Btw they added boolean flag MobileAds.RaiseAdEventsOnUnityMainThread for raising ad events on the Unity main thread. You can check release notes for plugin v8.0.0 (https://github.com/googleads/googleads-mobile-unity/releases)

Thanks.

Unfortunately though I found its implementation to be a bit unreliable, at least when working with the new UMP component https://github.com/googleads/googleads-mobile-unity/issues/2611

So for now I continue using https://github.com/PimDeWitte/UnityMainThreadDispatcher