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 4 years ago
  • Reactions: 1
  • Comments: 24 (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

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

Solved the problem for me

If you’ve followed the above solutions and the problem persists in Unity 2021.3.35, you can try disabling the main Gradle template. When prompted with the following message, click ‘Disable’. image

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 success for me. thanks

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.