5

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

Ran
  • 1,089
  • 1
  • 12
  • 30

2 Answers2

6

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.

Ran
  • 1,089
  • 1
  • 12
  • 30
  • I have **exactly** the same problem, having `ClassNotFoundException` without class name in Google Play Console. So, based on your success, I integrated Crashlytics. Let's see tomorrow my Firebase console... – Zoli Dec 18 '19 at 13:54
  • @Zotyi did Firebase show you the class that was missing? – qwiboo Apr 14 '20 at 01:32
  • @qwiboo I think so, but I can go back only 90 days in the crash log of Firebase Console, so cannot check which one – Zoli Apr 14 '20 at 07:11
  • @Zotyi I don't really care about the actual class. I just want to know if Firebase Crashlytics actually really shows you more info from the logs than just the logs in google play console? – qwiboo Apr 14 '20 at 13:00
  • @qwiboo: Yes, much more verbose – Zoli Apr 15 '20 at 14:34
  • how did you do that? do you have to publish your app again? i am guessing you implemented into your app and made a new release? – Emil Feb 17 '21 at 23:27
0

It could be a multiplex issue. In your build.gradle (module-level) add the following if not already there:

android {
    defaultConfig {
        ...
        multiDexEnabled true
    }
    ...
}

dependencies {
  implementation 'com.android.support:multidex:1.0.3’
}

If you don’t have an application class in your app add this to your manifest (within the application tag):

android:name="android.support.multidex.MultiDexApplication"

If you do, then add this:

public class MyApplication extends SomeOtherApplication {
      @Override
      protected void attachBaseContext(Context base) {
         super.attachBaseContext(base);
         MultiDex.install(this);
      }
    }

Read more about it here

Nikos Hidalgo
  • 3,666
  • 9
  • 25
  • 39
  • Multidex is enabled, but only by adding the multiDexEnabled flag and not doing the other steps. I have read that if I target android versions greater than 20, this is the only steps needed (?). Maybe Unity does the rest.. https://appmediation.com/unity-enable-multidex/ Anyways, can Multidex be this exception's source? – Ran Oct 02 '19 at 11:28
  • @Ran your minSdkVersion needs to be higher than 20 in order for the above to be taken care of automatically, not your targetSdkVersion. – Nikos Hidalgo Oct 02 '19 at 16:20
  • Ok, I will change my minSdkVersion. Not sure if this is the cause to the problem.. reading other posts it seems that the AndroidX library might be problematic – Ran Oct 03 '19 at 08:31