Search code examples
androidunity-game-engineclassnotfoundexceptionandroid-7.0-nougatandroid-7.1-nougat

java.lang.ClassNotFoundException without the name of the class


I have a Unity game deployed to Android.

In Google play console, I am seeing many crashes that happen on old Android versions (<=7.1). The crash is caused by a ClassNotFoundException, but the report does not show the class that is not found.

In the crashes console I get the following stack trace:

java.lang.RuntimeException: 
  at android.app.ActivityThread.handleReceiver (ActivityThread.java:3025)
  at android.app.ActivityThread.-wrap18 (ActivityThread.java)
  at android.app.ActivityThread$H.handleMessage (ActivityThread.java:1565)
  at android.os.Handler.dispatchMessage (Handler.java:102)
  at android.os.Looper.loop (Looper.java:179)
  at android.app.ActivityThread.main (ActivityThread.java:6152)
  at java.lang.reflect.Method.invoke (Native Method)
  at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run (ZygoteInit.java:886)
  at com.android.internal.os.ZygoteInit.main (ZygoteInit.java:776)
Caused by: java.lang.ClassNotFoundException: 
  at dalvik.system.BaseDexClassLoader.findClass (BaseDexClassLoader.java:56)
  at java.lang.ClassLoader.loadClass (ClassLoader.java:380)
  at java.lang.ClassLoader.loadClass (ClassLoader.java:312)
  at android.app.ActivityThread.handleReceiver (ActivityThread.java:3020)

Which is too generic and does not hint on what class is missing.

I was wondering if there is another way to find the missing class. I am using Multidex (I don't know if it's relative to the problem).

Any help will be appreciated here..


Solution

  • So I found the cause for the ClassNotFoundException, which was not the multidex configuration, but a Receiver that one of my plugins added to the manifest with a class that was not included in the project.

    More important is how I have found it, this can help others.. it appears that Google play console does not show the entire exception data if it's a multiline message. I have installed Firebase Crashlytics, and within a few hours got the actual missing class.

    Here is what you get in Google play console:

    Caused by: java.lang.ClassNotFoundException: 
      at dalvik.system.BaseDexClassLoader.findClass (BaseDexClassLoader.java:56)
      at java.lang.ClassLoader.loadClass (ClassLoader.java:380)
      at java.lang.ClassLoader.loadClass (ClassLoader.java:312)
      at android.app.ActivityThread.handleReceiver (ActivityThread.java:3049)
    

    Here is what you get in Firebase Crashlytics:

    Caused by java.lang.ClassNotFoundException
    Didn't find class "com.mintegral.msdk.click.AppReceiver" on path: DexPathList[[zip file "/data/app/com.bbumgames.spadesroyale-1/base.apk", zip file "/data/app/com.bbumgames.spadesroyale-1/split_config.arm64_v8a.apk"],nativeLibraryDirectories=[/data/app/com.bbumgames.spadesroyale-1/lib/arm64, /data/app/com.bbumgames.spadesroyale-1/base.apk!/lib/arm64-v8a, /data/app/com.bbumgames.spadesroyale-1/split_config.arm64_v8a.apk!/lib/arm64-v8a, /system/lib64, /vendor/lib64]]
    

    I am not sure why Google is not showing the second line, seems like a bug to me, but anyways, my problem is now solved.