Bug 59207 - java.lang.ClassNotFoundException, possibly related to MultiDex
Summary: java.lang.ClassNotFoundException, possibly related to MultiDex
Status: ASSIGNED
Alias: None
Product: Forms
Classification: Xamarin
Component: Android ()
Version: 2.3.4
Hardware: PC Windows
: --- normal
Target Milestone: ---
Assignee: Jimmy [MSFT]
URL:
Depends on:
Blocks:
 
Reported: 2017-09-04 12:39 UTC by John Hardman
Modified: 2017-09-10 13:24 UTC (History)
4 users (show)

Tags: Android MultiDex ClassNotFoundException
Is this bug a regression?: ---
Last known good build:

Notice (2018-05-24): bugzilla.xamarin.com is now in read-only mode.

Please join us on Visual Studio Developer Community and in the Xamarin and Mono organizations on GitHub to continue tracking issues. Bugzilla will remain available for reference in read-only mode. We will continue to work on open Bugzilla bugs, copy them to the new locations as needed for follow-up, and add the new items under Related Links.

Our sincere thanks to everyone who has contributed on this bug tracker over the years. Thanks also for your understanding as we make these adjustments and improvements for the future.


Please create a new report for Bug 59207 on Developer Community or GitHub if you have new information to add and do not yet see a matching new report.

If the latest results still closely match this report, you can use the original description:

  • Export the original title and description: Developer Community HTML or GitHub Markdown
  • Copy the title and description into the new report. Adjust them to be up-to-date if needed.
  • Add your new information.

In special cases on GitHub you might also want the comments: GitHub Markdown with public comments

Related Links:
Status:
ASSIGNED

Description John Hardman 2017-09-04 12:39:21 UTC
I tested my app on a new Android phone last night. On that particular device I got the following exception when running a debug build, even though the debug build runs happily on other devices and the release build runs happily on all of my test devices. The device it fails on is running Android 7.0, which none of the other devices run.

When I got this exception, it initially could not find AndroidSentTextMessageReceiver. I went through my code and removed all references of that class. On running again, the same exception was reported, but now referring to another class. As I experimented, the classes named were a mixture of mine and of third-party plugins. To me, it looks like an issue with Multi-Dex. My guess is that my release build is fine because it ends up with < 64k Java methods, but the debug build has more than 64k Java methods, and the class that could not be found is possibly not in the first 64k Java methods. Why it works on all but one of my test devices - again at a guess, I suspect that Android 7 handles large apps differently in some way. Vague guesswork I know. I've Googled around this and found many similar reports. Unfortunately, none gave a clear answer as to what causes it or how to workaround it. Lots of "I did this and it went away". Some pointing the finger at James Montemagno's connectivity plugin (I'm pretty sure that's not the cause, although I do use it). Whether it is an Android problem, or whether it is a problem in the build processes for Multi-Dex, or both, needs investigation. Also, could be related to https://bugzilla.xamarin.com/show_bug.cgi?id=55268 which is logged as a Mono problem (see https://bugzilla.xamarin.com/show_bug.cgi?id=55268#c11 )

java.lang.ClassNotFoundException: Didn't find class "md5b1140724aef5ec7a0d1d152758003f9f.AndroidSentTextMessageReceiver" on path: DexPathList[[zip file "/data/app/com.MyApp.MyApp-1/base.apk"],nativeLibraryDirectories=[/data/app/com.MyApp.MyApp-1/lib/arm, /data/app/com.MyApp.MyApp-1/base.apk!/lib/armeabi-v7a, /system/lib, /vendor/lib]]
dalvik.system.BaseDexClassLoader.findClass()BaseDexClassLoader.java:56
java.lang.ClassLoader.loadClass()ClassLoader.java:380
java.lang.ClassLoader.loadClass()ClassLoader.java:312
md55c8ca24d64f7073bdf3784e6cf59d8ed.MainActivity.n_onResume(Native Method)
md55c8ca24d64f7073bdf3784e6cf59d8ed.MainActivity.onResume()MainActivity.java:114
android.app.Instrumentation.callActivityOnResume()Instrumentation.java:1277
android.app.Activity.performResume()Activity.java:7058
android.app.ActivityThread.performResumeActivity()ActivityThread.java:3765
android.app.ActivityThread.handleResumeActivity()ActivityThread.java:3828
android.app.ActivityThread.handleLaunchActivity()ActivityThread.java:2991
at android.app.ActivityThread.-wrap14(ActivityThread.java)
android.app.ActivityThread$H.handleMessage()ActivityThread.java:1635
android.os.Handler.dispatchMessage()Handler.java:102
android.os.Looper.loop()Looper.java:154
android.app.ActivityThread.main()ActivityThread.java:6692
java.lang.reflect.Method.invoke(Native Method)
com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run()ZygoteInit.java:1468
com.android.internal.os.ZygoteInit.main()ZygoteInit.java:1358
Xamarin caused by: Java.Lang.ClassNotFoundException: Didn't find class "md5b1140724aef5ec7a0d1d152758003f9f.AndroidSentTextMessageReceiver" on path: DexPathList[[zip file "/data/app/com.MyApp.MyApp-1/base.apk"],nativeLibraryDirectories=[/data/app/com.MyApp.MyApp-1/lib/arm, /data/app/com.MyApp.MyApp-1/base.apk!/lib/armeabi-v7a, /system/lib, /vendor/lib]]
Java.Interop.JniEnvironment.Types.FindClass(string classname)<50812bf827614c0faffacac58772b4fa>:0
Java.Interop.JniType.JniType(string classname)<50812bf827614c0faffacac58772b4fa>:0
Java.Interop.JniPeerMembers.JniInstanceMethods.JniPeerMembers(Type declaringType)<50812bf827614c0faffacac58772b4fa>:0
Java.Interop.JniPeerMembers.JniInstanceMethods.GetConstructorsForType(Type declaringType)<50812bf827614c0faffacac58772b4fa>:0
Java.Interop.JniPeerMembers.JniInstanceMethods.StartCreateInstance(string constructorSignature, Type declaringType, JniArgumentValue* parameters)<50812bf827614c0faffacac58772b4fa>:0
Android.Content.BroadcastReceiver.BroadcastReceiver()<71828dd8fb5f4508815e23d6996c45c2>:0
MyAppAndroid.AndroidSentTextMessageReceiver.AndroidSentTextMessageReceiver(ITextMessageService textMessageService)<fd90d52352024e32ba8ae169930e9735>:0
MyAppAndroid.MainActivity.OnResume()<fd90d52352024e32ba8ae169930e9735>:0
Android.App.Activity.n_OnResume(IntPtr jnienv, IntPtr native__this)<71828dd8fb5f4508815e23d6996c45c2>:0
at (wrapper dynamic-method) System.Object:ef830fb9-4c37-4eec-913c-e48165e439c8 (intptr,intptr)
--- End of managed Java.Lang.ClassNotFoundException stack trace ---
java.lang.ClassNotFoundException: Didn't find class "md5b1140724aef5ec7a0d1d152758003f9f.AndroidSentTextMessageReceiver" on path: DexPathList[[zip file "/data/app/com.MyApp.MyApp-1/base.apk"],nativeLibraryDirectories=[/data/app/com.MyApp.MyApp-1/lib/arm, /data/app/com.MyApp.MyApp-1/base.apk!/lib/armeabi-v7a, /system/lib, /vendor/lib]]
dalvik.system.BaseDexClassLoader.findClass()BaseDexClassLoader.java:56
java.lang.ClassLoader.loadClass()ClassLoader.java:380
java.lang.ClassLoader.loadClass()ClassLoader.java:312
md55c8ca24d64f7073bdf3784e6cf59d8ed.MainActivity.n_onResume(Native Method)
md55c8ca24d64f7073bdf3784e6cf59d8ed.MainActivity.onResume()MainActivity.java:114
android.app.Instrumentation.callActivityOnResume()Instrumentation.java:1277
android.app.Activity.performResume()Activity.java:7058
android.app.ActivityThread.performResumeActivity()ActivityThread.java:3765
android.app.ActivityThread.handleResumeActivity()ActivityThread.java:3828
android.app.ActivityThread.handleLaunchActivity()ActivityThread.java:2991
at android.app.ActivityThread.-wrap14(ActivityThread.java)
android.app.ActivityThread$H.handleMessage()ActivityThread.java:1635
android.os.Handler.dispatchMessage()Handler.java:102
android.os.Looper.loop()Looper.java:154
android.app.ActivityThread.main()ActivityThread.java:6692
java.lang.reflect.Method.invoke(Native Method)
com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run()ZygoteInit.java:1468
com.android.internal.os.ZygoteInit.main()ZygoteInit.java:1358
Comment 1 Jimmy [MSFT] 2017-09-05 19:58:59 UTC
Hey John, what's your Xamarin.Android version? 

I also got a ClassNotFoundException today and it seemed to only happen with Xamarin.Android 7.5.0.8 which is in the VS2017 15.4 preview. Rebuilding and deploying the same project with Xamarin.Android and VS2017 15.3 resulted in no exception so I'm wondering if we are seeing the same issue which would seem to be a bug in Xamarin.Android.
Comment 2 John Hardman 2017-09-05 22:33:33 UTC
Hi Jimmy,

Version details are:

Microsoft Visual Studio Community 2017
Version 15.3.0
VisualStudio.15.Release/15.3.0+26730.3

Xamarin.Android SDK   7.4.0.19 (0cd0214)
Xamarin.Android Reference Assemblies and MSBuild support.

Are you only seeing the exception on some test devices (perhaps Android 7), rather than all?
Comment 3 Brendan Zagaeski (Xamarin Team, assistant) 2017-09-06 22:48:27 UTC
## Cross-reference

One likely cause of this error message with Xamarin.Android 7.4 is Bug 59036.

As noted in that bug, one way to work around that issue temporarily is to copy the generated multidex.keep file into your project folder, add the missing newlines, and then add it to your project with a build action of MultiDexMainDexList.  If that manual workaround does indeed resolve the issue for the reporter of this bug, this bug can be marked as a duplicate of Bug 59036.
Comment 4 John Hardman 2017-09-10 13:24:13 UTC
Hi Brendan,

I tried the manual workaround (thankfully I know how to convert line-endings automatically, as there were over 18000). It did not resolve the problem.