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.

AndroidJavaException: java.lang.ClassNotFoundException: com.google.android.gms.ads.initialization.OnInitializationCompleteListener

See original GitHub issue

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

Issue Analytics

  • State:closed
  • Created 9 months ago
  • Reactions:1
  • Comments:14 (1 by maintainers)

github_iconTop GitHub Comments

12reactions
shedeikancommented, Jan 2, 2023

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
1reaction
Battle4Kingcommented, Jun 27, 2023

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

Read more comments on GitHub >

github_iconTop Results From Across the Web

java.lang.ClassNotFoundException: com ...
I workaround and find out that, newest Google Mobile Ads Mediation have several code that call Java static com.google.android.gms.ads.initialization.
Read more >
java.lang.ClassNotFoundException: com.google.android. ...
while i have try Android resolver version but its not fix it while if select force Android resolver version than i get gradle...
Read more >
Can anybody explain me what is code mean in logcat?
Basically I get this line of code when I initialize the add and request for banner ad. Basically the test banner ad does...
Read more >
Admob plugin error: Java.Lang.ClassNotFoundException
Good morning everyone, I have a problem with Admob, this is the first time this has happened to me. The ads work PERFECTLY...
Read more >
Admob plugin error: Java.Lang.ClassNotFoundException ...
Since switching my build method from internal to gradle I can no longer get the admob plugin to work for unity, the following...
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