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.ClassNotFoundException: com.google.android.gms.ads.initialization.OnInitializationCompleteListener #2458

Closed
namthangnguyen opened this issue Dec 16, 2022 · 19 comments
Assignees
Labels
P3 Low priority issue.

Comments

@namthangnguyen
Copy link

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

@SYRollingStone
Copy link

我也有这个问题,蹲一手

@Aseim99
Copy link

Aseim99 commented Dec 30, 2022

Hi, I have the same problem. Test ads work fine on editor but nothing happens on the mobile device (via apk).
"15938 15986 Error Unity AndroidJavaException: java.lang.ClassNotFoundException: com.google.android.gms.ads.AdSize"

Anyone got any solution? I have tried resolve and force resolve for android.

@SYRollingStone
Copy link

我将Gradle版本升级到6.9.x,并且重新修复了网络环境后,这个问题解决了。

@Aseim99
Copy link

Aseim99 commented Dec 30, 2022

Sorry don't speak Japanese.

@shedeikan
Copy link

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

@AshleyLv
Copy link

AshleyLv commented Jan 3, 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

it is works for me. thank you

@yong2khoo88
Copy link

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.

@NVentimiglia
Copy link
Member

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.

@NVentimiglia NVentimiglia self-assigned this Jan 18, 2023
@NVentimiglia NVentimiglia added P3 Low priority issue. integration issue labels Jan 18, 2023
@shedeikan
Copy link

i have excluded the last line '-dontobfuscate'

Yes, me too. Everything is fine

@diyapkaba
Copy link

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.

@kunny kunny added the wontfix label Feb 6, 2023
@kunny
Copy link
Collaborator

kunny commented Feb 6, 2023

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.

@kunny kunny closed this as completed Feb 6, 2023
@wentaoma
Copy link

image

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

@varanofficial
Copy link

Edit>Project Settings>Publishing Settings [Uncheck all the boxes]
this fixed for me
EZ WAY

@Battle4King
Copy link

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

@xGeorgeV
Copy link

It works! Many Thanks!

@MetaAnomie
Copy link

Unchecking "Use R8" from Edit->Project Settings->Publishing Settings under "Minify" solved this for me.
FYI I still have "Release" checked.

@huseyingunes
Copy link

it works

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. thx

@nicolastinkl
Copy link

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

@lucian-nk
Copy link

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
P3 Low priority issue.
Projects
None yet
Development

No branches or pull requests