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

Missing dependencies cause crash when registering AppStateChanged callback #2645

Closed
aaronflippo opened this issue Apr 12, 2023 · 5 comments
Closed
Assignees
Labels
P2 Issue. Plugin Issue with the Unity plugin.

Comments

@aaronflippo
Copy link

Step 0: Are you in the right place?

[REQUIRED] Step 1: Describe your environment

  • Unity version: 2020.29.f1
  • Google Mobile Ads Unity plugin version: 8.8.0
  • Platform: Android
  • Platform OS version: Android 11 (eg iOS 10, Android 9)
  • Any specific devices issue occurs on: _____
  • Mediation ad networks used, and their versions: _____

[REQUIRED] Step 2: Describe the problem

Calling this during startup (to register app stage change events for OnOpen ads):

AppStateEventNotifier.AppStateChanged += OnAppStateChanged;

Results in the following exception:
2023-04-12 11:44:43.679 13474-13538/? E/Unity: AndroidJavaException: java.lang.NoClassDefFoundError: Failed resolution of: Landroidx/lifecycle/DefaultLifecycleObserver;
java.lang.NoClassDefFoundError: Failed resolution of: Landroidx/lifecycle/DefaultLifecycleObserver;
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:223)
at com.unity3d.player.UnityPlayer$e.run(Unknown Source:20)
Caused by: java.lang.ClassNotFoundException: androidx.lifecycle.DefaultLifecycleObserver
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:223) 
at com.unity3d.player.UnityPlayer$e.run(Unknown Source:20) 
at UnityEngine.AndroidJNISafe.CheckException () [0x00000] in <00000000000000000000000000000000>:0
at UnityEngine.AndroidJNISafe.FindClass (System.String name) [0x00000] in <00000000000000000000000000000000>:0
at UnityEngine.AndroidJavaObject._AndroidJavaObject (System.String className, System.Object[] args) [0x00000] in <00000

Steps to reproduce:

  1. Try to execute the following code: AppStateEventNotifier.AppStateChanged += OnAppStateChanged;

It looks like an important dependency may have been removed in commit 598e82e:
598e82e

Adding these lines back into the GoogleMobileAdDependencies.xml file fixes this for me:

https://maven.google.com/ https://maven.google.com/

Relevant Code:

See above
@NVentimiglia NVentimiglia self-assigned this Apr 12, 2023
@NVentimiglia NVentimiglia added P2 Issue. Plugin Issue with the Unity plugin. labels Apr 12, 2023
@NVentimiglia
Copy link
Member

@aaronflippo

I am glad you found a work around, that said the dependencies should have resolved on their own as they are included by the google mobile ads aar file.

Can you help us out by including a log of your external dependency manager resolution process?

Assets > External Dependency Manager > Android Resolver > Force Resolve

@DavianMachete
Copy link

Step 0: Are you in the right place?

[REQUIRED] Step 1: Describe your environment

  • Unity version: 2020.29.f1
  • Google Mobile Ads Unity plugin version: 8.8.0
  • Platform: Android
  • Platform OS version: Android 11 (eg iOS 10, Android 9)
  • Any specific devices issue occurs on: _____
  • Mediation ad networks used, and their versions: _____

[REQUIRED] Step 2: Describe the problem

Calling this during startup (to register app stage change events for OnOpen ads):

AppStateEventNotifier.AppStateChanged += OnAppStateChanged;

Results in the following exception: 2023-04-12 11:44:43.679 13474-13538/? E/Unity: AndroidJavaException: java.lang.NoClassDefFoundError: Failed resolution of: Landroidx/lifecycle/DefaultLifecycleObserver; java.lang.NoClassDefFoundError: Failed resolution of: Landroidx/lifecycle/DefaultLifecycleObserver; 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:223) at com.unity3d.player.UnityPlayer$e.run(Unknown Source:20) Caused by: java.lang.ClassNotFoundException: androidx.lifecycle.DefaultLifecycleObserver 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:223)  at com.unity3d.player.UnityPlayer$e.run(Unknown Source:20)  at UnityEngine.AndroidJNISafe.CheckException () [0x00000] in <00000000000000000000000000000000>:0 at UnityEngine.AndroidJNISafe.FindClass (System.String name) [0x00000] in <00000000000000000000000000000000>:0 at UnityEngine.AndroidJavaObject._AndroidJavaObject (System.String className, System.Object[] args) [0x00000] in <00000

Steps to reproduce:

  1. Try to execute the following code: AppStateEventNotifier.AppStateChanged += OnAppStateChanged;

It looks like an important dependency may have been removed in commit 598e82e: 598e82e

Adding these lines back into the GoogleMobileAdDependencies.xml file fixes this for me:

https://maven.google.com/ https://maven.google.com/

Relevant Code:

See above

This worked for me too, just added the removed lines. Thank you...

@tienassassin
Copy link

I meet this issue again. I tried @aaronflippo 's solution (added the removed lines in GoogleMobileAdDependencies.xml). it not only didn't work, but also made my app crash on startup
Please check @NVentimiglia

@ThinhHB
Copy link

ThinhHB commented Sep 11, 2023

Thanks @aaronflippo , that worked for me!

@faisalameerCS
Copy link

faisalameerCS commented Apr 26, 2024

Adding the following dependencies in the GoogleMobileAdsDependencies.xml worked for me.

<androidPackage spec="androidx.lifecycle:lifecycle-process:2.7.0">
	<repositories>
		<repository>https://maven.google.com/</repository>
	</repositories>
</androidPackage>

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

No branches or pull requests

6 participants