question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

GamePlayActivity no field mUnityPlayer cause a AndroidJavaException crash

See original GitHub issue

Step 0: Are you in the right place?

  • For general technical questions, or help with project-specific issues like setting up ads in your app, reach out to our support team on the Developer Forum.

  • For assistance with your AdMob account, reach out to AdMob Support.

  • For feedback on our documentation, send your feedback by pressing the Send Feedback button at the top right of the documentation page you are on.

  • For issues related to the code in this repository, continue filing this GitHub issue.

  • Once you’ve read this section and determined that your issue is appropriate for this repository, please delete this section.

[REQUIRED] Step 1: Describe your environment

  • Unity version: 2021.3.23f1c1
  • Google Mobile Ads Unity plugin version: v8.1.0 and v8.2.0
  • Platform: Android (iOS, Android, Unity Editor)
  • Platform OS version: Android 7 (eg iOS 10, Android 9)
  • Any specific devices issue occurs on: all
  • Mediation ad networks used, and their versions: no

[REQUIRED] Step 2: Describe the problem

  1. java GamePlayActivity really no field “mUnityPlayer” in my case, mUnityPlayer is in other SDK.I use unity as a library;
  2. Unity C# code, when call MobileAds.Initialize make the problem occur;

Steps to reproduce:

  1. Yes. GamePlayActivity really no field “mUnityPlayer” in my case, mUnityPlayer is in other SDK.I use unity as a library.
  2. Unity C# code, when call MobileAds.Initialize trigger;
  3. UnityPlayer maybe can find by R.id.unitySurfaceView;

What happened? How can we make the problem occur? This could be a description, log/console output, etc.

E/Unity: AndroidJavaException: java.lang.NoSuchFieldError: no “Ljava/lang/Object;” field “mUnityPlayer” in class “Lio/wx/gp/play/ui/GamePlayActivity;” or its superclasses java.lang.NoSuchFieldError: no “Ljava/lang/Object;” field “mUnityPlayer” in class “Lio/wx/gp/play/ui/GamePlayActivity;” or its superclasses at com.unity3d.player.UnityPlayer.nativeRender(Native Method) at com.unity3d.player.UnityPlayer.access$800(Unknown Source) at com.unity3d.player.UnityPlayer$g$1.handleMessage(Unknown Source) at android.os.Handler.dispatchMessage(Handler.java:106) at android.os.Looper.loop(Looper.java:203) at com.unity3d.player.UnityPlayer$g.run(Unknown Source) at UnityEngine.AndroidJNISafe.CheckException () [0x00000] in <00000000000000000000000000000000>:0 at UnityEngine.AndroidJNISafe.GetFieldID (System.IntPtr clazz, System.String name, System.String sig) [0x00000] in <00000000000000000000000000000000>:0 at UnityEngine._AndroidJNIHelper.GetFieldID (System.IntPtr jclass, System.String fieldName, System.St

Please share a downloadable sample project that reproduces the bug, if available. This greatly helps us to diagnose and fix the issue faster.

Relevant Code:

            List<String> deviceIds = new List<String>() { AdRequest.TestDeviceSimulator };
            // Configure TagForChildDirectedTreatment and test device IDs.
            RequestConfiguration requestConfiguration =
                new RequestConfiguration.Builder()
                .SetTagForChildDirectedTreatment(TagForChildDirectedTreatment.Unspecified)
                .SetTestDeviceIds(deviceIds).build();
            MobileAds.SetRequestConfiguration(requestConfiguration);
            // Initialize the Google Mobile Ads SDK.
            MobileAds.Initialize(HandleInitCompleteAction);

Issue Analytics

  • State:closed
  • Created 4 months ago
  • Comments:5 (3 by maintainers)

github_iconTop GitHub Comments

1reaction
guanghui1987commented, May 27, 2023

Maybe I know the reason. Unity AndroidJavaObject.CallStatic maybe need to access mUnityPlayer. Unity AndroidJavaObject.Call maybe not need to access mUnityPlayer.

I do some testing in my case that is GamePlayActivity no field mUnityPlayer. and the results:

  1. Unity 2021.3.6f1c1 google-ads-mobile-unity v8.1.0 v8.2.0 ok
  2. Unity 2021.3.23f1c1 google-ads-mobile-unity v8.1.0 v8.2.0 not ok
  3. Unity 2021.3.25f1c1 google-ads-mobile-unity v8.1.0 v8.2.0 not ok
public void Initialize(Action<IInitializationStatusClient> initCompleteAction)
{
	//IL_000c: Unknown result type (might be due to invalid IL or missing references)
	//IL_0012: Expected O, but got Unknown
	//IL_0023: Unknown result type (might be due to invalid IL or missing references)
	//IL_0029: Expected O, but got Unknown
	this.initCompleteAction = initCompleteAction;
	AndroidJavaClass val = new AndroidJavaClass("com.unity3d.player.UnityPlayer");
	AndroidJavaObject @static = ((AndroidJavaObject)val).GetStatic<AndroidJavaObject>("currentActivity");
	AndroidJavaClass val2 = new AndroidJavaClass("com.google.android.gms.ads.MobileAds");
	((AndroidJavaObject)val2).CallStatic("initialize", new object[2] { @static, this });
}
0reactions
NVentimigliacommented, Jun 1, 2023

@guanghui1987

I was unable to replicate this issue using 2021.3.25f1c1. I am not sure what is happening, but I would need to look at the project or additional logging to figure out what is happening. If you could, can you please open a support case on the on the help forum?

Read more comments on GitHub >

github_iconTop Results From Across the Web

java.lang.NoSuchFieldError: no "Ljava/lang/Object;" field "b"
Hello. We got crash after opening keyboard and inputing text symbols (only digits). DDMS log contains errors:
Read more >
ERROR Unity with native android java : java.lang. ...
ERROR Unity with native android java : java.lang.NoSuchFieldError: no type "" found and so no field "currentActivity" ... I am making an app...
Read more >
ART Runtime Crash bug while using an application [36986569]
It is not always reproducable, it happens frequently though. When it happens, the application disappears from foreground and I have to relaunch it....
Read more >
googleads-mobile-unity
GamePlayActivity no field mUnityPlayer cause a AndroidJavaException crash ... iOS build fails - Mediation Adapters are not compatible with Facebook SDK.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found