Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

AndroidJavaException: java.lang.NoSuchMethodError #2815

Closed
desouse opened this issue Jul 7, 2023 · 1 comment
Closed

AndroidJavaException: java.lang.NoSuchMethodError #2815

desouse opened this issue Jul 7, 2023 · 1 comment
Assignees
Labels
P1 Priority issue. Plugin Issue with the Unity plugin.

Comments

@desouse
Copy link

desouse commented Jul 7, 2023

[REQUIRED] Step 1: Describe your environment

  • Unity version: 2020.3.19f1
  • Google Mobile Ads Unity plugin version: 8.4.0
  • Platform: Android
  • Platform OS version: Android 11
  • Any specific devices issue occurs on:
  • Mediation ad networks used, and their versions:

[REQUIRED] Step 2: Describe the problem

Steps to reproduce:

I was trying to call the new method ApplicationPreferences.SetString("key", "value"), which was added in ApplicationPreferences API to manage GMA preferences. However, I get this exception:

AndroidJavaException: java.lang.NoSuchMethodError: no non-static method with name='getDefaultSharedPreferences' signature='()Ljava/lang/Object;' in class Ljava.lang.Object;
java.lang.NoSuchMethodError: no non-static method with name='getDefaultSharedPreferences' signature='()Ljava/lang/Object;' in class Ljava.lang.Object;
	at com.unity3d.player.ReflectionHelper.getMethodID(Unknown Source:162)
	at com.unity3d.player.UnityPlayer.nativeRender(Native Method)
	at com.unity3d.player.UnityPlayer.access$300(Unknown Source:0)
	at com.unity3d.player.UnityPlayer$e$1.handleMessage(Unknown Source:95)
	at android.os.Handler.dispatchMessage(Handler.java:102)
	at android.os.Looper.loop(Looper.java:268)
	at com.unity3d.player.UnityPlayer$e.run(Unknown Source:20)
at UnityEngine.AndroidJNISafe.CheckException () [0x00000] in <00000000000000000000000000000000>:0
at UnityEngine.AndroidJNISafe.CallStaticObjectMethod (System.IntPtr clazz, System.IntPtr methodID, UnityEngine.jvalue[] args) [0x00000] in <000000000000000000000000

Relevant Code:

The problem is in the way of getting the Java interface SharedPreferences.Editor.
So instead of this

AndroidJavaObject androidJavaObject = new AndroidJavaClass("android.preference.PreferenceManager").Call<AndroidJavaObject>("getDefaultSharedPreferences").Call<AndroidJavaObject>("edit");

it should be this

AndroidJavaClass unityPlayer = new AndroidJavaClass("com.unity3d.player.UnityPlayer");
AndroidJavaObject currentActivity = unityPlayer.GetStatic<AndroidJavaObject>("currentActivity");
AndroidJavaObject androidJavaObject = new AndroidJavaClass("android.preference.PreferenceManager").CallStatic<AndroidJavaObject>("getDefaultSharedPreferences", currentActivity).Call<AndroidJavaObject>("edit");
@NVentimiglia NVentimiglia self-assigned this Jul 10, 2023
@NVentimiglia NVentimiglia added P1 Priority issue. SDK Sdk engineering issue. Plugin Issue with the Unity plugin. and removed SDK Sdk engineering issue. labels Jul 10, 2023
@NVentimiglia
Copy link
Member

@desouse

I have confirmed the issue. We will get a fix out. b/290671721

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
P1 Priority issue. Plugin Issue with the Unity plugin.
Projects
None yet
2 participants