googleads / googleads-mobile-android-mediation

Sample Android project showcasing how to build a mediation adapter or custom event for the Google Mobile Ads SDK.
Apache License 2.0
241 stars 197 forks source link

crash after update to com.google.android.gms:play-services-ads:22.2.0 #503

Closed wangjianpeng closed 6 months ago

wangjianpeng commented 9 months ago

After upgrading the AdMob SDK to version 22.2.0, many crashes occurred in the Android app on Firebase. The upgraded dependencies are as follows:

implementation 'com.google.android.gms:play-services-ads:22.2.0'
implementation 'com.google.firebase:firebase-crashlytics:18.3.2'
implementation 'com.google.firebase:firebase-messaging:23.1.1'
implementation 'com.google.firebase:firebase-analytics:21.2.0'
implementation 'com.google.firebase:firebase-auth:22.0.0'

There are two types of issues:

Exceptions related to 'Thread-XX':

Caused by java.lang.NoSuchMethodError: no static method with name='Thread-214' signature='Thread-214' in class Ljava.lang.Object;
Caused by java.lang.NoSuchMethodError: no static method with name='Thread-253' signature='Thread-253' in class Ljava.lang.Object;

These exceptions are occurring in the ReflectionHelper.getMethodID method.

Exceptions related to 'hashCode':

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>(:17)
at com.unity3d.player.ReflectionHelper.getMethodID(:2)

It is mentioned that these issues are related to Firebase. Despite upgrading both AdMob and Firebase to the latest versions:

implementation 'com.google.android.gms:play-services-ads:22.4.0'
implementation 'com.google.firebase:firebase-crashlytics:18.4.0'
implementation 'com.google.firebase:firebase-messaging:23.2.1'
implementation 'com.google.firebase:firebase-analytics:21.3.0'
implementation 'com.google.firebase:firebase-auth:22.1.1'

The crashes remain unresolved.

ygslikewq1 commented 9 months ago

Exception java.lang.Error: FATAL EXCEPTION [Thread-331] Unity version : 2018.4.36f1 Device model : HMD Global Nokia G20 Device fingerprint: Nokia/Ronin_00EEA/RNN_sprout:13/TP1A.220624.014/00WW_3_31E:user/release-keys

Caused by: java.lang.NoSuchMethodError: no static method with name='Thread-331' signature='Thread-331' in class Ljava.lang.Object; at com.unity3d.player.ReflectionHelper.getMethodID

I also have this problem from Google background to crash users are basically 12 13 system

NVentimiglia commented 9 months ago

@ygslikewq1 Can you report this issue to the Android SDK Team?.

Include a link to this issue for reference.

paradizIscool commented 9 months ago

@ygslikewq1 @wangjianpeng

Did you find something about this crash?

We're also facing this issue with 2020, android 12, 13, 14

NVentimiglia commented 9 months ago

@paradizIscool Can you report this issue to the Android SDK Team?.

Include a link to this issue for reference.

dreed-sd commented 7 months ago

Did anyone reach a resolution on this? We are experiencing this despite not even having upgraded our Firebase version, which is strange.

dreed-sd commented 7 months ago

Update for me -- these stack traces are apparently what can happen when code accesses Unity main-thread resources from off the main thread. We introduced the problem in our own code and resolved it by ensuring it did not access any Unity APIs unless dispatched to the main thread (e.g. StartCoroutine). So for anyone else seeing this ReflectionHelper-related errors, question anything that uses Threads (including your dependencies).

wangjianpeng commented 6 months ago

@paradizIscool we have code to call unity API in thread,which result in these crash.

Newbility523 commented 5 months ago

Thanks a lot for the solution. We facing same issue. I wan to reproduce crash and figure it out how this happen, so I can avoid it in our project. As you mention, I called Unity API in otherThread. But it work fine. Here is two ways I tried. 1

  public class ThreadCallUnityAPI : MonoBehaviour
  {
      private AndroidJavaObject javaObject;
      private GameObject newGo;

      public void Invoke()
      {
          for (var i = 0; i < 1000; ++i)
          {
              var thread = new System.Threading.Thread(OtherThreadWork1);
              thread.Start();
          }
      }

      void OtherThreadWork1()
      {
          Debug.Log($"Thread {Thread.CurrentThread.Name} started");

          for (var i = 0; i < 10; ++i)
          {
              newGo = null;
              newGo = new GameObject("Test");   // everything is fine. Unity API can be called from other threads
              newGo.transform.position = new Vector3(i, i, i); // same
          }
      }
  }

2 I also try create Android thread and trigger callback from Unity like this.

  // Unity
  public class AndroidThreadCallUnityAPI : MonoBehaviour
  {
      private class UnityCallbackImplementation : AndroidJavaProxy
      {
          public UnityCallbackImplementation() : base("com.unity3d.player.MyAndroidClass$UnityCallback") { }
          public void onCallback()
          {
              Debug.Log("Called from Android");
              var newGo = new GameObject("Test");  // everything is fine. Unity API can be called from other threads
              newGo.transform.position = new Vector3(1, 1, 1); // same
          }
      }

      public void Invoke()
      {
          var javaObject = new AndroidJavaObject("com.unity3d.player.MyAndroidClass");
          javaObject.Call("setUnityCallback", new UnityCallbackImplementation());
          javaObject.Call("callUnityCallback");
      }
  }
  // Android
  public class MyAndroidClass {
      private static UnityCallback unityCallback;
      public interface UnityCallback {
          void onCallback();
      }

      public void setUnityCallback(UnityCallback callback) {
          unityCallback = callback;
      }

      public void runThread() {
          Thread thread = new Thread(new Runnable() {
              @Override
              public void run() {
                  Log.d("ThreadName", "name is " + Thread.currentThread().getName());
                  if (unityCallback != null) {
                      unityCallback.onCallback();
                  }
              }
          });
          thread.start();
      }

      public void callUnityCallback() {
          runThread();
      }
  }

Could you please provied some code reproduce this crash ? thanks a lot. @wangjianpeng @dreed-sd