googleads-mobile-unity: AndroidJavaException: java.lang.ClassNotFoundException: com.google.android.gms.ads.initialization.OnInitializationCompleteListener

Describe the problem

Steps to reproduce:

I build a project using Admob, it works fine with test app id, ad unit id. But when I release the app, no ads are shown. I test my application using LogCat, it shows these errors.

Relevant Code:

When App start this error is displayed in LogCat

AndroidJavaException: java.lang.ClassNotFoundException: com.google.android.gms.ads.initialization.OnInitializationCompleteListener
java.lang.ClassNotFoundException: com.google.android.gms.ads.initialization.OnInitializationCompleteListener
    at java.lang.Class.classForName(Native Method)
    at java.lang.Class.forName(Class.java:454)
    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:83)
    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: com.google.android.gms.ads.initialization.OnInitializationCompleteListener
    at java.lang.Class.classForName(Native Method) 
    at java.lang.Class.forName(Class.java:454) 
    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:83) 
    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 <000000000000000000000

When I click the show ad button, this error is displayed

AndroidJavaException: java.lang.ClassNotFoundException: com.google.android.gms.ads.AdRequest$Builder
java.lang.ClassNotFoundException: com.google.android.gms.ads.AdRequest$Builder
    at java.lang.Class.classForName(Native Method)
    at java.lang.Class.forName(Class.java:454)
    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:83)
    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: com.google.android.gms.ads.AdRequest$Builder
    at java.lang.Class.classForName(Native Method) 
    at java.lang.Class.forName(Class.java:454) 
    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:83) 
    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 class

I have done Assets > Play Services Resolver > Android Resolver > Force Resolve like many tutorials but it doesn’t work.

My environment

  • Unity version: 2020.3.40f1
  • Google Mobile Ads Unity plugin version: 7.3.1
  • Platform: Android
  • Platform OS version: Android 5.0 to API level 31
  • Any specific devices issue occurs on: All
  • Mediation ad networks used, and their versions: None

Thank you

About this issue

  • Original URL
  • State: closed
  • Created 2 years ago
  • Reactions: 1
  • Comments: 18 (1 by maintainers)

Most upvoted comments

I have this problem too.

  • Unity 2021.3.16f1
  • Mobile Ads Unity plugin 7.1.0-7.3.x
  • Android API level 31-33

Solution:

Build Settings > Player Setting > Publishing Settings > Custom Progurard File

proguard-user.txt:

-keep class com.google.unity.** {
   *;
}
-keep public class com.google.android.gms.ads.**{
   public *;
}
-keep public class com.google.ads.**{
   public *;
}
-keepattributes *Annotation*
-dontobfuscate

I have this problem too.

  • Unity 2021.3.16f1
  • Mobile Ads Unity plugin 7.1.0-7.3.x
  • Android API level 31-33

Solution:

Build Settings > Player Setting > Publishing Settings > Custom Progurard File

proguard-user.txt:

-keep class com.google.unity.** {
   *;
}
-keep public class com.google.android.gms.ads.**{
   public *;
}
-keep public class com.google.ads.**{
   public *;
}
-keepattributes *Annotation*
-dontobfuscate

it is works for me. thank you

I have this problem too.

  • Unity 2021.3.16f1
  • Mobile Ads Unity plugin 7.1.0-7.3.x
  • Android API level 31-33

Solution:

Build Settings > Player Setting > Publishing Settings > Custom Progurard File

proguard-user.txt:

-keep class com.google.unity.** {
   *;
}
-keep public class com.google.android.gms.ads.**{
   public *;
}
-keep public class com.google.ads.**{
   public *;
}
-keepattributes *Annotation*
-dontobfuscate

work for unity 2022.3.3f1 thanks

image

Check out thoes file is exit in unity plugin android dic .If not means generate file error.

Since there were no recent activities for this issue, we are therefore reluctantly going to close this bug for now.

If you are still experiencing the problem, please file a new issue with the same description, what happens and system / network tracing / Charles logs.

All system setups can be slightly different, so it’s always better to open new issues and reference the related ones. Thanks for your contribution.

I have this problem too.

  • Unity 2021.3.16f1
  • Mobile Ads Unity plugin 7.1.0-7.3.x
  • Android API level 31-33

Solution:

Build Settings > Player Setting > Publishing Settings > Custom Progurard File

proguard-user.txt:

-keep class com.google.unity.** {
   *;
}
-keep public class com.google.android.gms.ads.**{
   public *;
}
-keep public class com.google.ads.**{
   public *;
}
-keepattributes *Annotation*
-dontobfuscate

Worked for me thanks. I have been struggling with this issue for days.

i have excluded the last line ‘-dontobfuscate’

Yes, me too. Everything is fine

This issue is often related not running the dependency manager before building.

In the Unity editor, select Assets > External Dependency Manager > Android Resolver > Resolve. The Unity External Dependency Manager library will copy the declared dependencies into the Assets/Plugins/Android directory of your Unity app.

I have this problem too.

  • Unity 2021.3.16f1
  • Mobile Ads Unity plugin 7.1.0-7.3.x
  • Android API level 31-33

Solution:

Build Settings > Player Setting > Publishing Settings > Custom Progurard File

proguard-user.txt:

-keep class com.google.unity.** {
   *;
}
-keep public class com.google.android.gms.ads.**{
   public *;
}
-keep public class com.google.ads.**{
   public *;
}
-keepattributes *Annotation*
-dontobfuscate

it works for me too. Thanks! Wondering, i have excluded the last line ‘-dontobfuscate’, that doesn’t matter right? Coz i think to keep the ‘Obfuscate’ feature.