2

I've upgraded my Windows to 10.0.16299 (latest) and my Visual Studio to 15.5.1 (latest). Since then, when I build and run my Android app built in my Xamarin the app crashes instantly.

Unfortunately, [AppName] has stopped.

The issue appears no matter whether I want to run the app on an emulator or a connected real device. The output window shows this error message:

FATAL EXCEPTION: main
Process: [AppName], PID: 16778
java.lang.RuntimeException: Unable to instantiate application md53c5f17a815ca1a4a699c7162c91a7059.MainApplication: java.lang.ClassNotFoundException: Didn't find class "md53c5f17a815ca1a4a699c7162c91a7059.MainApplication" on path: DexPathList[[zip file "/data/app/nz.HUMANiT.Frank-1/base.apk"],nativeLibraryDirectories=[/data/app/nz.HUMANiT.Frank-1/lib/arm64, /data/app/[AppName]-1/base.apk!/lib/arm64-v8a, /vendor/lib64, /system/lib64]]
    at android.app.LoadedApk.makeApplication(LoadedApk.java:587)
    at android.app.ActivityThread.handleBindApplication(ActivityThread.java:4932)
    at android.app.ActivityThread.-wrap1(ActivityThread.java)
    ...
    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:679)

Caused by: java.lang.ClassNotFoundException: Didn't find class "md53c5f17a815ca1a4a699c7162c91a7059.MainApplication" on path: DexPathList[[zip file "/data/app/[AppName]-1/base.apk"],nativeLibraryDirectories=[/data/app/[AppName]-1/lib/arm64, /data/app/[AppName]-1/base.apk!/lib/arm64-v8a, /vendor/lib64, /system/lib64]]
    at dalvik.system.BaseDexClassLoader.findClass(BaseDexClassLoader.java:56)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:511)
    ...

Suppressed: java.lang.ClassNotFoundException: md53c5f17a815ca1a4a699c7162c91a7059.MainApplication
    at java.lang.Class.classForName(Native Method)
    at java.lang.BootClassLoader.findClass(ClassLoader.java:781)
    ...

Caused by: java.lang.NoClassDefFoundError: Class not found using the boot class loader; no stack trace available

I found hints that there were bugs in Xamarin in the past; however, the explained solutions and fixes don't work. Enabling or disabling multidex doesn't solve the issue either.

Is this a new bug in Xamarin? Any idea? Any advice?

Quality Catalyst
  • 6,531
  • 8
  • 38
  • 62
  • Have you tried to use `Repair` in `Visual Studio Installer`? – Robbit Dec 11 '17 at 06:49
  • Yes. I also uninstalled and installed the Xamarin component. Uninstalled and installed all of Visual Studio. Uninstalled Visual Studio, removed all leftovers I found manually and installed it again. Nothing helped. – Quality Catalyst Dec 11 '17 at 07:48
  • You have mention that you are using multidex in your project,[I think this maybe will help you](https://przemekraciborski.eu/2016/09/30/multidex-in-xamarin/) – Robbit Dec 11 '17 at 08:51
  • @JoeLv, very good finding. Thank you! The issue, however, appears in both cases with and without multidex. I only tried to enable multidex because other posts recommended to do so as it solved their issues. Also, I have tried the exact same solution / code base on a separate machine, equally set up, but VS 15.5.0 and there it works. – Quality Catalyst Dec 11 '17 at 18:20
  • Clean your project solution, delete the bin and obj files,restart your Visual Studio and try again, it did work on my side. – York Shen Dec 21 '17 at 12:10
  • @YorkShen-MSFT: Thank you! This didn't work on my end. Turned out that an upgrade to Visual Studio 15.5.2 helped overcome the problem. – Quality Catalyst Dec 21 '17 at 18:34
  • Exact same issue. Already on 15.5.2, already tried clean, delete bin, obj, restart and rebuild. – maplemale Dec 31 '17 at 01:14
  • @SushiHangover, that's not a duplicate to the question https://stackoverflow.com/questions/48039351/do-i-know-if-i-need-multi-dex-enabled-classnotfoundexception - they only have the same error message. Enabling multidex doesn't solve the issue as stated in my question. I am **not** having a Java variable counter overflow which the multi-dex option circumvents. – Quality Catalyst Dec 31 '17 at 22:31
  • @QualityCatalyst https://stackoverflow.com/a/48039749/4984832 – SushiHangover Jan 01 '18 at 00:55
  • @SushiHangover: Weird to classify an old question to be a duplicate of a question that was asked less than 24 hours ago. Further, I am not having a mult-dex issue. Your answer given on the multi-dex question would fit to my question as well as you can see from a couple from my earlier comments. – Quality Catalyst Jan 01 '18 at 02:57
  • @QualityCatalyst It has nothing to do with multi-dex, it is a bug in the Xamarin.Android build process concerning how the classes.zip is created that causes the ClassNotFoundException (the root problem) and there were were over 6 questions recently posted all concerning this since that version release, I "consolidated" them into the only one that had an accepted answer. If this particular Xamarin.Android bug is not the problem stated in your question, I'll vote to re-open this one. (when the problem occurs for you, try to unzip the classes.zip file to see if it contains another classes.zip) – SushiHangover Jan 01 '18 at 04:38

1 Answers1

0

Had the same problem.

It looks like a Xamarin bug : the android package names are wrong in the generated AndroidManifest (not the same as those in the generated java classes).

Workaround : specify a package name for your android activities (and Application class if any) with the "Name" attribute.

If your activity was :

[Activity(Label = "App1", Icon = "@drawable/icon", Theme = "@style/MainTheme", ConfigurationChanges = ConfigChanges.ScreenSize | ConfigChanges.Orientation, LaunchMode = LaunchMode.SingleTask)]
public class MainActivity : FormsAppCompatActivity {
...
}

Change it to :

[Activity(Name = "apackagename.MainActivity", Label = "App1", Icon = "@drawable/icon", Theme = "@style/MainTheme", ConfigurationChanges = ConfigChanges.ScreenSize | ConfigChanges.Orientation, LaunchMode = LaunchMode.SingleTask)]
public class MainActivity : FormsAppCompatActivity {
...
}

This should solve the problem.

  • I tried and it didn't solve my issue. It turned out that an upgrade to Visual Studio 15.5.2 helped overcome the problem. – Quality Catalyst Dec 23 '17 at 20:43
  • This did not work for me either. Also, already on 15.5.2 (latest of visual studio). – maplemale Dec 31 '17 at 01:14
  • Enabling Multi-Dex fixed this issue. Easily reproducible for me, just uncheck it, clean and rebuild: issue is back. Enable Multi-Dex, clean rebuild, issue gone. There is no way I am exceeding the 64k limit. Don't understand this behavior - maybe bug? – maplemale Dec 31 '17 at 01:47
  • @maplemale: see my question: the multi-dex option is a common solution for the issue with that particular error message, as the one you have had, but not the one I am having, which was the reason why I posted my question. I am *not* having a Java variable counter overflow which the multi-dex option circumvents. – Quality Catalyst Dec 31 '17 at 22:34
  • @QualityCatalyst This still may be the same issue, did you try inspecting the obj\Debug\android\bin\classes directory? Does it have a classes.zip file in it? If so, move that up one (So it's in the same directory as the classes folder ie. in the bin folder). dont' copy/paste it up one directory, actually move it. – maplemale Jan 01 '18 at 02:18
  • @maplemale: you stated " I discovered enabling Multi-Dex resolved it." - this has nothing to do with my question. My question is related to a bug in Xamarin. And no, moving thew file doesn't help as my builds are on a remote build server where I cannot control temporary folders. – Quality Catalyst Jan 01 '18 at 03:04
  • @QualityCatalyst I was trying a lot of things for over a day. At some point / several times enabling Multi-Dex temporarily alleviated (but didn't resolve) the issue. Make no mistake: If that file is in that folder (Classes.zip in the classes folder), then you absolutely are experiencing this bug: https://github.com/xamarin/xamarin-android/pull/1142 It sucks, but whether you are capable of moving the files on a remote build server or not, is irrelevant. If you are seeing the classes.zip in the classes folder, I'd suggest maybe a build script to resolve until you can upgrade. Sorry – maplemale Jan 01 '18 at 21:40
  • @maplemale. At one stage you state "Enabling Multi-Dex fixed this issue", now you say it didn't. As mentioned multiple times, including yourself, this was a Xamarin bug. We should just leave it to that :) I solved my build by upgrading to 15.5.2 - no other workaround needed. – Quality Catalyst Jan 01 '18 at 21:50
  • @QualityCatalyst Right - because technically it's not a "fix" persay. If upgrading to 15.5.2 fixed it for you, then it's not the same bug... glad you got it working though. – maplemale Jan 01 '18 at 21:51
  • Ha, funny, that's what I told @SushiHangover, but he believed it is.Thanks for your help! – Quality Catalyst Jan 01 '18 at 21:55