This is Xamarin's bug tracking system. For product support, please use the support links listed in your Xamarin Account.
Bug 35491 - Built APK crash below 5.0 - multidex
Summary: Built APK crash below 5.0 - multidex
Status: VERIFIED FIXED
Alias: None
Product: Android
Classification: Xamarin
Component: General (show other bugs)
Version: 6.0.99
Hardware: PC Windows
: --- normal
Target Milestone: 6.1 (C7)
Assignee: Atsushi Eno
URL:
Depends on:
Blocks:
 
Reported: 2015-11-03 05:26 UTC by Przemysław Raciborski
Modified: 2017-01-12 19:17 UTC (History)
14 users (show)

See Also:
Tags:
Is this bug a regression?: ---
Last known good build:


Attachments

Description Przemysław Raciborski 2015-11-03 05:26:00 UTC
APK built with Xamarin.Android RC1 crash on start with exception (logcat) - ClassNotFoundException - Didn't find class "mono.android.app.Application" on Path DexList....

Application crash only on Android less than 5.0 - I suppose that it is caused because of MultiDex. I have reached 65k method limit - and multidexing works different on API 21+ (native support) and API less than 21 (that's might be the reason why it doesn't crash on Android 5.0+).
Comment 1 Przemysław Raciborski 2015-11-03 06:00:08 UTC
uhm looks like it wasn't xamarin RC1 bug - problem still persists even after reverting to stable branch and I have no idea why this exception is thrown
Comment 2 Przemysław Raciborski 2015-11-03 10:16:54 UTC
The problem lies in fact that mono/Android/app/Application.class got generated in secondary .dex file (classes2.dex).
Application class has to be in first dex file or it will crash @startup. Problem does not exist on API21+ because multidex is natively supported - and Application class can be normally loaded (even not from main dex file).

%sdk%\build-tools\\3.0.2\mainDexClasses.bat generates empty multidex.keep file so that's not necessary Xamarin bug.
However:
a) Xamarin should give ability to pick custom multidex.keep file in build config instead of relying on SDK tool ( as android studio for native java dev do )
b) You could add some random runtime annotation to generated Application.class to force mainDexClasses.bat to add entry for "Application.class"

What's the correct format of multidex.keep file? I managed to use custom multidex.keep by modyfing SDK scripts - but Application class still gets generated in secondary dex file.

I tried everything below:

android/app/Application$NotifyTimeZoneChanges.class 
bin/classes/mono/android/app/Application.class 
classes/mono/android/app/Application.class 
mono/android/app/Application.class 
android/app/Application.class 
android/support/multidex/BuildConfig/class 
android/support/multidex/MultiDex$V14/class 
android/support/multidex/MultiDex$V19/class 
android/support/multidex/MultiDex$V4/class 
android/support/multidex/MultiDex/class 
android/support/multidex/MultiDexApplication/class 
android/support/multidex/MultiDexExtractor$1/class 
android/support/multidex/MultiDexExtractor/class 
android/support/multidex/ZipUtil$CentralDirectory/class 
android/support/multidex/ZipUtil/class 
obj\Debug\android\bin\mono\android\app\Application$NotifyTimeZoneChanges.class 
obj/Debug/android/bin/mono/android/app/Application$NotifyTimeZoneChanges.class 
Debug/android/bin/mono/android/app/Application$NotifyTimeZoneChanges.class 
android/bin/mono/android/app/Application$NotifyTimeZoneChanges.class 		
obj/Debug/android/bin/mono/android/app/Application.class 
Debug/android/bin/mono/android/app/Application.class 		
android/bin/mono/android/app/Application.class
Comment 3 Przemysław Raciborski 2015-11-03 11:21:13 UTC
Reverting to SDK tools 23.0.1:
<AndroidSdkBuildToolsVersion>23.0.1</AndroidSdkBuildToolsVersion>
helped - Application class is in main dex now.

However: multidex.keep is still empty. - please investigate that issue further, consider appending some runtime annotation to Application class (that might help with empty multidex.keep)
Comment 4 Atsushi Eno 2015-11-09 01:20:27 UTC
We do run mainDexClasses to generate the configuration for dx that takes only --main-dex-list option for that.
If mainDexClasses.bat does not store any required classes for the main class.dex , then it is rather a bug in Android SDK, not ours (Actually their multidex toolchain is kind of incomplete and do not take many options as proguard does).
You'd like to report their bug at https://code.google.com/p/android/issues .

Having said that, custom main-dex-list is a good considerable option. I support the idea. Leaving this bug open for that, as enhancement.
Comment 5 Atsushi Eno 2015-11-10 05:00:49 UTC
I have added a new "MultiDexMainDexList" MSBuild action (item) in our Android Application project that should work as alternative to automatically-generated output from mainDexClasses(.bat). It will be available in the next major release.

[master 91dc729]
Comment 6 Patrick Suzuki 2015-11-25 17:46:27 UTC
We made a hotfix build but the customer is still experiencing the same issue with a slightly different log. I am including customer's response bellow:

# Customer
The hotfix doesn’t seem to work for us.

I get a slightly different log now, and despite what the bugzilla report says it still plows right on after the failure instead of stopping the build.

[10:04:07][AudioAddict.Android.DI\AudioAddict.Android.DI.csproj.teamcity] _CompileToDalvik (1s)
[10:04:07][_CompileToDalvik] MakeDir
[10:04:07][_CompileToDalvik] CreateMultiDexMainDexClassList
[10:04:07][CreateMultiDexMainDexClassList] C:\Program Files (x86)\Android\android-sdk\build-tools\23.0.1\\mainDexClasses.bat --output obj\Release\multidex.keep "'C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework\MonoAndroid\v6.0\mono.android.jar';'C:\Program Files (x86)\Android\android-sdk\extras\android\support\multidex\library\libs\android-support-multidex.jar';'C:\BuildAgent\work\d91ce446b5f80123\AudioAddict.Android.DI\obj\Release\__library_projects__\AppoxeeSDK\library_project_imports\__reference__commons-cli-1.1.jar';'C:\BuildAgent\work\d91ce446b5f80123\AudioAddict.Android.DI\obj\Release\__library_projects__\AppoxeeSDK\library_project_imports\__reference__commons-codec-1.4.jar';'C:\BuildAgent\work\d91ce446b5f80123\AudioAddict.Android.DI\obj\Release\__library_projects__\AppoxeeSDK\library_project_imports\__reference__commons-io-1.2.jar';'C:\BuildAgent\work\d91ce446b5f80123\AudioAddict.Android.DI\obj\Release\__library_projects__\AppoxeeSDK\library_project_imports\__reference__FlashRuntimeExtensions.jar';'C:\BuildAgent\work\d91ce446b5f80123\AudioAddict.Android.DI\obj\Release\__library_projects__\AppoxeeSDK\library_project_imports\__reference__gson-2.3.1.jar';'C:\BuildAgent\work\d91ce446b5f80123\AudioAddict.Android.DI\obj\Release\__library_projects__\AppoxeeSDK\library_project_imports\__reference__ormlite-android-4.40.jar';'C:\BuildAgent\work\d91ce446b5f80123\AudioAddict.Android.DI\obj\Release\__library_projects__\AppoxeeSDK\library_project_imports\__reference__ormlite-core-4.40.jar';'C:\BuildAgent\work\d91ce446b5f80123\AudioAddict.Android.DI\obj\Release\__library_projects__\AppoxeeSDK\library_project_imports\bin\classes.jar';'C:\BuildAgent\work\d91ce446b5f80123\AudioAddict.Android.DI\obj\Release\__library_projects__\AppoxeeSDK\library_project_imports\libs\appoxee_sdk_v2.5.0.jar';'C:\BuildAgent\work\d91ce446b5f80123\AudioAddict.Android.DI\obj\Release\__library_projects__\Calligraphy\library_project_imports\bin\classes.jar';'C:\BuildAgent\work\d91ce446b5f80123\AudioAddict.Android.DI\obj\Release\__library_projects__\Flurry.Analytics.Android\library_project_imports\FlurryAnalytics-5.5.0.jar';'C:\BuildAgent\work\d91ce446b5f80123\AudioAddict.Android.DI\obj\Release\__library_projects__\GigyaSDK.Android\library_project_imports\gigya-sdk-3.3.0.jar';'C:\BuildAgent\work\d91ce446b5f80123\AudioAddict.Android.DI\obj\Release\__library_projects__\HockeyApp.Android\library_project_imports\HockeySDK-3.6.2.jar';'C:\BuildAgent\work\d91ce446b5f80123\AudioAddict.Android.DI\obj\Release\__library_projects__\MoPubAndroid\library_project_imports\mopub-volley-1.1.0.jar';'C:\BuildAgent\work\d91ce446b5f80123\AudioAddict.Android.DI\obj\Release\__library_projects__\MoPubAndroid\library_project_imports\bin\classes.jar';'C:\BuildAgent\work\d91ce446b5f80123\AudioAddict.Android.DI\obj\Release\__library_projects__\MoPubAndroid\library_project_imports\libs\MMSDK-5.3.0.jar';'C:\BuildAgent\work\d91ce446b5f80123\AudioAddict.Android.DI\obj\Release\__library_projects__\OkHttp\library_project_imports\okhttp-2.3.0-jar-with-dependencies.jar';'C:\BuildAgent\work\d91ce446b5f80123\AudioAddict.Android.DI\obj\Release\__library_projects__\UmanoSlidingUpPanelAndroid\library_project_imports\bin\classes.jar';'C:\BuildAgent\work\d91ce446b5f80123\AudioAddict.Android.DI\obj\Release\__library_projects__\UrlImageViewHelper\library_project_imports\bin\classes.jar';'C:\BuildAgent\work\d91ce446b5f80123\AudioAddict.Android.DI\obj\Release\__library_projects__\Xamarin.Facebook\library_project_imports\AudienceNetwork.jar';'C:\BuildAgent\work\d91ce446b5f80123\AudioAddict.Android.DI\obj\Release\__library_projects__\Xamarin.Facebook\library_project_imports\bolts.jar';'C:\BuildAgent\work\d91ce446b5f80123\AudioAddict.Android.DI\obj\Release\__library_projects__\Xamarin.Facebook\library_project_imports\bin\classes.jar';'C:\Users\ian.DIRADIO\AppData\Local\Xamarin\Android.Support.Design\23.0.1.3\embedded\classes.jar';'C:\Users\ian.DIRADIO\AppData\Local\Xamarin\Android.Support.v4\23.0.1.3\embedded\classes.jar';'C:\Users\ian.DIRADIO\AppData\Local\Xamarin\Android.Support.v4\23.0.1.3\embedded\libs\internal_impl-23.0.1.jar';'C:\Users\ian.DIRADIO\AppData\Local\Xamarin\Android.Support.v7.AppCompat\23.0.1.3\embedded\classes.jar';'C:\Users\ian.DIRADIO\AppData\Local\Xamarin\Android.Support.v7.MediaRouter\23.0.1.3\embedded\classes.jar';'C:\Users\ian.DIRADIO\AppData\Local\Xamarin\Android.Support.v7.MediaRouter\23.0.1.3\embedded\libs\internal_impl-23.0.1.jar';'C:\Users\ian.DIRADIO\AppData\Local\Xamarin\GooglePlayServices.Ads\8.1.0\embedded\classes.jar';'C:\Users\ian.DIRADIO\AppData\Local\Xamarin\GooglePlayServices.Analytics\8.1.0\embedded\classes.jar';'C:\Users\ian.DIRADIO\AppData\Local\Xamarin\GooglePlayServices.AppIndexing\8.1.0\embedded\classes.jar';'C:\Users\ian.DIRADIO\AppData\Local\Xamarin\GooglePlayServices.Base\8.1.0\embedded\classes.jar';'C:\Users\ian.DIRADIO\AppData\Local\Xamarin\GooglePlayServices.Basement\8.1.0\embedded\classes.jar';'C:\Users\ian.DIRADIO\AppData\Local\Xamarin\GooglePlayServices.Cast\8.1.0\embedded\classes.jar';'C:\Users\ian.DIRADIO\AppData\Local\Xamarin\GooglePlayServices.Gcm\8.1.0\embedded\classes.jar';'C:\Users\ian.DIRADIO\AppData\Local\Xamarin\GooglePlayServices.Location\8.1.0\embedded\classes.jar';'C:\Users\ian.DIRADIO\AppData\Local\Xamarin\GooglePlayServices.Maps\8.1.0\embedded\classes.jar';'C:\Users\ian.DIRADIO\AppData\Local\Xamarin\GooglePlayServices.Plus\8.1.0\embedded\classes.jar';'obj\Release\android\bin\classes'"
[10:04:08][CreateMultiDexMainDexClassList] 'java' is not recognized as an internal or external command,
[10:04:08][CreateMultiDexMainDexClassList] operable program or batch file.
[10:04:08][CreateMultiDexMainDexClassList] Invalid option
[10:04:08][CreateMultiDexMainDexClassList] Usage:
[10:04:08][CreateMultiDexMainDexClassList]
[10:04:08][CreateMultiDexMainDexClassList] Short version: Don't use this.
[10:04:08][CreateMultiDexMainDexClassList]
[10:04:08][CreateMultiDexMainDexClassList] Slightly longer version: This tool is used by mainDexClasses script to build
[10:04:08][CreateMultiDexMainDexClassList] the main dex list.
[10:04:08][CreateMultiDexMainDexClassList] Picked up JAVA_TOOL_OPTIONS: -Dfile.encoding=UTF8
[10:04:08][_CompileToDalvik] CompileToDalvik
[10:04:08][CompileToDalvik] C:\Program Files (x86)\Java\jdk1.7.0_55\\bin\java.exe -Xmx2G -jar "C:\Program Files (x86)\Android\android-sdk\build-tools\23.0.1\\lib\dx.jar" --no-strict --dex --multi-dex --main-dex-list=obj\Release\multidex.keep --output=obj\Release\android\bin obj\Release\android\bin\classes "C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework\MonoAndroid\v6.0\mono.android.jar" "C:\Program Files (x86)\Android\android-sdk\extras\android\support\multidex\library\libs\android-support-multidex.jar" C:\BuildAgent\work\d91ce446b5f80123\AudioAddict.Android.DI\obj\Release\__library_projects__\AppoxeeSDK\library_project_imports\__reference__commons-cli-1.1.jar C:\BuildAgent\work\d91ce446b5f80123\AudioAddict.Android.DI\obj\Release\__library_projects__\AppoxeeSDK\library_project_imports\__reference__commons-codec-1.4.jar C:\BuildAgent\work\d91ce446b5f80123\AudioAddict.Android.DI\obj\Release\__library_projects__\AppoxeeSDK\library_project_imports\__reference__commons-io-1.2.jar C:\BuildAgent\work\d91ce446b5f80123\AudioAddict.Android.DI\obj\Release\__library_projects__\AppoxeeSDK\library_project_imports\__reference__FlashRuntimeExtensions.jar C:\BuildAgent\work\d91ce446b5f80123\AudioAddict.Android.DI\obj\Release\__library_projects__\AppoxeeSDK\library_project_imports\__reference__gson-2.3.1.jar C:\BuildAgent\work\d91ce446b5f80123\AudioAddict.Android.DI\obj\Release\__library_projects__\AppoxeeSDK\library_project_imports\__reference__ormlite-android-4.40.jar C:\BuildAgent\work\d91ce446b5f80123\AudioAddict.Android.DI\obj\Release\__library_projects__\AppoxeeSDK\library_project_imports\__reference__ormlite-core-4.40.jar C:\BuildAgent\work\d91ce446b5f80123\AudioAddict.Android.DI\obj\Release\__library_projects__\AppoxeeSDK\library_project_imports\bin\classes.jar C:\BuildAgent\work\d91ce446b5f80123\AudioAddict.Android.DI\obj\Release\__library_projects__\AppoxeeSDK\library_project_imports\libs\appoxee_sdk_v2.5.0.jar C:\BuildAgent\work\d91ce446b5f80123\AudioAddict.Android.DI\obj\Release\__library_projects__\Calligraphy\library_project_imports\bin\classes.jar C:\BuildAgent\work\d91ce446b5f80123\AudioAddict.Android.DI\obj\Release\__library_projects__\Flurry.Analytics.Android\library_project_imports\FlurryAnalytics-5.5.0.jar C:\BuildAgent\work\d91ce446b5f80123\AudioAddict.Android.DI\obj\Release\__library_projects__\GigyaSDK.Android\library_project_imports\gigya-sdk-3.3.0.jar C:\BuildAgent\work\d91ce446b5f80123\AudioAddict.Android.DI\obj\Release\__library_projects__\HockeyApp.Android\library_project_imports\HockeySDK-3.6.2.jar C:\BuildAgent\work\d91ce446b5f80123\AudioAddict.Android.DI\obj\Release\__library_projects__\MoPubAndroid\library_project_imports\mopub-volley-1.1.0.jar C:\BuildAgent\work\d91ce446b5f80123\AudioAddict.Android.DI\obj\Release\__library_projects__\MoPubAndroid\library_project_imports\bin\classes.jar C:\BuildAgent\work\d91ce446b5f80123\AudioAddict.Android.DI\obj\Release\__library_projects__\MoPubAndroid\library_project_imports\libs\MMSDK-5.3.0.jar C:\BuildAgent\work\d91ce446b5f80123\AudioAddict.Android.DI\obj\Release\__library_projects__\OkHttp\library_project_imports\okhttp-2.3.0-jar-with-dependencies.jar C:\BuildAgent\work\d91ce446b5f80123\AudioAddict.Android.DI\obj\Release\__library_projects__\UmanoSlidingUpPanelAndroid\library_project_imports\bin\classes.jar C:\BuildAgent\work\d91ce446b5f80123\AudioAddict.Android.DI\obj\Release\__library_projects__\UrlImageViewHelper\library_project_imports\bin\classes.jar C:\BuildAgent\work\d91ce446b5f80123\AudioAddict.Android.DI\obj\Release\__library_projects__\Xamarin.Facebook\library_project_imports\AudienceNetwork.jar C:\BuildAgent\work\d91ce446b5f80123\AudioAddict.Android.DI\obj\Release\__library_projects__\Xamarin.Facebook\library_project_imports\bolts.jar C:\BuildAgent\work\d91ce446b5f80123\AudioAddict.Android.DI\obj\Release\__library_projects__\Xamarin.Facebook\library_project_imports\bin\classes.jar C:\Users\ian.DIRADIO\AppData\Local\Xamarin\Android.Support.Design\23.0.1.3\embedded\classes.jar C:\Users\ian.DIRADIO\AppData\Local\Xamarin\Android.Support.v4\23.0.1.3\embedded\classes.jar C:\Users\ian.DIRADIO\AppData\Local\Xamarin\Android.Support.v4\23.0.1.3\embedded\libs\internal_impl-23.0.1.jar C:\Users\ian.DIRADIO\AppData\Local\Xamarin\Android.Support.v7.AppCompat\23.0.1.3\embedded\classes.jar C:\Users\ian.DIRADIO\AppData\Local\Xamarin\Android.Support.v7.MediaRouter\23.0.1.3\embedded\classes.jar C:\Users\ian.DIRADIO\AppData\Local\Xamarin\Android.Support.v7.MediaRouter\23.0.1.3\embedded\libs\internal_impl-23.0.1.jar C:\Users\ian.DIRADIO\AppData\Local\Xamarin\GooglePlayServices.Ads\8.1.0\embedded\classes.jar C:\Users\ian.DIRADIO\AppData\Local\Xamarin\GooglePlayServices.Analytics\8.1.0\embedded\classes.jar C:\Users\ian.DIRADIO\AppData\Local\Xamarin\GooglePlayServices.AppIndexing\8.1.0\embedded\classes.jar C:\Users\ian.DIRADIO\AppData\Local\Xamarin\GooglePlayServices.Base\8.1.0\embedded\classes.jar C:\Users\ian.DIRADIO\AppData\Local\Xamarin\GooglePlayServices.Basement\8.1.0\embedded\classes.jar C:\Users\ian.DIRADIO\AppData\Local\Xamarin\GooglePlayServices.Cast\8.1.0\embedded\classes.jar C:\Users\ian.DIRADIO\AppData\Local\Xamarin\GooglePlayServices.Gcm\8.1.0\embedded\classes.jar C:\Users\ian.DIRADIO\AppData\Local\Xamarin\GooglePlayServices.Location\8.1.0\embedded\classes.jar C:\Users\ian.DIRADIO\AppData\Local\Xamarin\GooglePlayServices.Maps\8.1.0\embedded\classes.jar C:\Users\ian.DIRADIO\AppData\Local\Xamarin\GooglePlayServices.Plus\8.1.0\embedded\classes.jar
[10:04:08][CompileToDalvik] COMPILETODALVIK Could not create the Java Virtual Machine.
[10:04:08][CompileToDalvik] COMPILETODALVIK A fatal exception has occurred. Program will exit.
Comment 7 Atsushi Eno 2015-11-26 01:32:19 UTC
Please provide the reproducible project especially now that the project should include custom main dex list. Note that the hotfix does not automagically fix Google's mainDexClasses bug but just to enable users to specify custom main dex list.
Comment 8 Atsushi Eno 2015-11-26 01:36:05 UTC
Also note that those error messages are from Android SDK, see  https://code.google.com/p/android/issues/detail?id=187721
Comment 9 ian 2015-11-26 19:47:22 UTC
> Please provide the reproducible project especially now that the project should
include custom main dex list. Note that the hotfix does not automagically fix
Google's mainDexClasses bug but just to enable users to specify custom main dex
list.

That is an incredibly key piece of information, what do I do for this?
Comment 10 Atsushi Eno 2015-11-26 22:42:28 UTC
To deal with how the standard Android SDK tool works, you need to run mainDexClasses.bat (somewhere outside Windows, in case the bug I mentioned on comment #8 bites) to generate partially valid custom MultiDexMainDexList file to add to your project. Then you need to make sure that list contains any necessary classes for bootstrapping the app.
Comment 11 Przemysław Raciborski 2015-12-17 14:08:28 UTC
ian@di.fm Be aware that this fix is not available in any of current official Xamarin branches (stable/beta/alpha none of that). You can try changing Sdk Build tools in your .csproj - <AndroidSdkBuildToolsVersion>23.0.1</AndroidSdkBuildToolsVersion> might help for a while - otherwise you have to ask Xamarin for hotfix internal-build.
Comment 12 Dominic N 2015-12-17 15:42:44 UTC
Can confirm that the mentioned build resolved Przemysław's issue.
Comment 13 Dimitar Dobrev 2015-12-17 23:41:15 UTC
I have the same problem, how can I get the build in question? I use Xamarin 4.0.0.1717/Xamarin.Android 6.0.0.35 but I don't have the "MultiDexMainDexList" action.
Comment 14 Atsushi Eno 2016-01-05 08:26:31 UTC
Please ask at support@xamarin.com.
Comment 15 Peter Collins 2016-04-11 21:30:07 UTC
This new build action will be available in the upcoming Cycle7 release, and is working as intended against cycle7/b4be22e.
Comment 16 klark 2016-04-12 08:07:43 UTC
Today, I switch beta channel , Update to Xamarin 4.1.0.33 and Xamarin Studio 6.0.0 version!
In the debug mode,my app can run without any problems below android 5.0(andorid 4.4.4),
but in the release mode,my app get the running crashed information:

[AndroidRuntime] Shutting down VM
[AndroidRuntime] FATAL EXCEPTION: main
[AndroidRuntime] Process: AnXinMe.RemoteTv.Droid, PID: 15164
[AndroidRuntime] java.lang.RuntimeException: Unable to instantiate application android.support.multidex.MultiDexApplication: java.lang.ClassNotFoundException: Didn't find class "android.support.multidex.MultiDexApplication" on path: DexPathList[[zip file "/data/app/AnXinMe.RemoteTv.Droid-1.apk"],nativeLibraryDirectories=[/data/app-lib/AnXinMe.RemoteTv.Droid-1, /vendor/lib, /system/lib]]
[AndroidRuntime] at android.app.LoadedApk.makeApplication(LoadedApk.java:509)
[AndroidRuntime] at android.app.ActivityThread.handleBindApplication(ActivityThread.java:4427)
[AndroidRuntime] at android.app.ActivityThread.access$1500(ActivityThread.java:147)
[AndroidRuntime] at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1271)
[AndroidRuntime] at android.os.Handler.dispatchMessage(Handler.java:102)
[AndroidRuntime] at android.os.Looper.loop(Looper.java:136)
[AndroidRuntime] at android.app.ActivityThread.main(ActivityThread.java:5135)
[AndroidRuntime] at java.lang.reflect.Method.invokeNative(Native Method)
[AndroidRuntime] at java.lang.reflect.Method.invoke(Method.java:515)
[AndroidRuntime] at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:795)
[AndroidRuntime] at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:611)
[AndroidRuntime] at dalvik.system.NativeStart.main(Native Method)
[AndroidRuntime] Caused by: java.lang.ClassNotFoundException: Didn't find class "android.support.multidex.MultiDexApplication" on path: DexPathList[[zip file "/data/app/AnXinMe.RemoteTv.Droid-1.apk"],nativeLibraryDirectories=[/data/app-lib/AnXinMe.RemoteTv.Droid-1, /vendor/lib, /system/lib]]
[AndroidRuntime] at dalvik.system.BaseDexClassLoader.findClass(BaseDexClassLoader.java:56)
[AndroidRuntime] at java.lang.ClassLoader.loadClass(ClassLoader.java:497)
[AndroidRuntime] at java.lang.ClassLoader.loadClass(ClassLoader.java:457)
[AndroidRuntime] at android.app.Instrumentation.newApplication(Instrumentation.java:975)
[AndroidRuntime] at android.app.LoadedApk.makeApplication(LoadedApk.java:504)
[AndroidRuntime] ... 11 more
[Process] Sending signal. PID: 15164 SIG: 9

At obj\Debug\android\bin directory exits two class files: classes.dex classes2.dex;
Instead,at obj\Release\android\bin directory exits one class file:classes.dex;
Is release mode msbuild bug?
In the end,I add  multidex.keep file into my project:

android/support/multidex/MultiDexApplication.class
android/support/multidex/MultiDex.class
android/support/multidex/MultiDexExtractor$1.class
android/support/multidex/MultiDexExtractor.class
android/support/multidex/MultiDex$V14.class
android/support/multidex/MultiDex$V19.class
android/support/multidex/MultiDex$V4.class
android/support/multidex/ZipUtil$CentralDirectory.class
android/support/multidex/ZipUtil.class

select build action "MultiDexMainDexList".

Clean all->Rebuild all..

But, still crashed at startup running time!
Comment 17 Peter Collins 2016-04-12 22:24:48 UTC
@klark are you sure the multidex option is enabled in your Release configuration property group in the project? The fact that only one dex file is created seems to indicate it may not have been enabled.

Could you attach diagnostic msbuild build output from a clean release build which produces the package that fails in this manner?

https://developer.xamarin.com/guides/android/troubleshooting/troubleshooting/#Diagnostic_MSBuild_Output
Comment 18 klark 2016-04-13 01:55:33 UTC
@Peter Collins 
I'm sure the multi-dex option is enabled,as the running crashed information is " Caused by: java.lang.ClassNotFoundException: Didn't find class "android.support.multidex.MultiDexApplication" on path:".

Here is my project configuration:

<PropertyGroup>
    <Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
    <Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
    ...
    <OutputType>Library</OutputType>
    <AppDesignerFolder>Properties</AppDesignerFolder>
    ...
    <FileAlignment>512</FileAlignment>
    <TargetFrameworkVersion>v6.0</TargetFrameworkVersion>
    <AndroidApplication>true</AndroidApplication>
    <AndroidResgenFile>Resources\Resource.Designer.cs</AndroidResgenFile>
    <GenerateSerializationAssemblies>Off</GenerateSerializationAssemblies>
    <AndroidManifest>Properties\AndroidManifest.xml</AndroidManifest>
    <AndroidUseLatestPlatformSdk>True</AndroidUseLatestPlatformSdk>
    ...
    <SynchReleaseVersion>false</SynchReleaseVersion>
    <AndroidSdkBuildToolsVersion>23.0.3</AndroidSdkBuildToolsVersion>
    <AndroidEnableMultiDex>true</AndroidEnableMultiDex>
  </PropertyGroup>

  <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
    <DebugSymbols>True</DebugSymbols>
    <DebugType>full</DebugType>
    <Optimize>false</Optimize>
    <OutputPath>bin\Debug\</OutputPath>
    <DefineConstants>DEBUG;TRACE</DefineConstants>
    <ErrorReport>prompt</ErrorReport>
    <WarningLevel>4</WarningLevel>
    <EmbedAssembliesIntoApk>False</EmbedAssembliesIntoApk>
    <Debugger>Xamarin</Debugger>
    <DevInstrumentationEnabled>False</DevInstrumentationEnabled>
    <RunCodeAnalysis>false</RunCodeAnalysis>
    <UseVSHostingProcess>true</UseVSHostingProcess>
    <JavaMaximumHeapSize>1G</JavaMaximumHeapSize>
    <AndroidLinkMode>None</AndroidLinkMode>
    <AndroidSupportedAbis>armeabi;armeabi-v7a;x86</AndroidSupportedAbis>
  </PropertyGroup>

<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
    <Optimize>true</Optimize>
    <OutputPath>bin\Release\</OutputPath>
    <DefineConstants>TRACE</DefineConstants>
    <ErrorReport>prompt</ErrorReport>
    <WarningLevel>4</WarningLevel>
    <JavaMaximumHeapSize>1G</JavaMaximumHeapSize>
    <RunCodeAnalysis>false</RunCodeAnalysis>
    <EmbedAssembliesIntoApk>True</EmbedAssembliesIntoApk>
    <Debugger>Xamarin</Debugger>
    <DebugType>full</DebugType>
    <AndroidUseSharedRuntime>False</AndroidUseSharedRuntime>
    <AndroidSupportedAbis>armeabi;armeabi-v7a</AndroidSupportedAbis>
    <EnableProguard>true</EnableProguard>
    <BundleAssemblies>true</BundleAssemblies>
  </PropertyGroup>
Comment 19 Peter Collins 2016-04-13 16:45:49 UTC
@klark interesting, thanks for the confirmation.

Please provide diagnostic msbuild build output from a release build which reproduces this behavior if possible, it would be very beneficial in attempting to diagnose this.

https://developer.xamarin.com/guides/android/troubleshooting/troubleshooting/#Diagnostic_MSBuild_Output
Comment 20 Peter Collins 2016-04-13 19:45:31 UTC
To avoid additional confusion and possible issue conflation I've filed a new bug for the specific issue reported in Comment #16. The bug tracking this new release-only failure is Bug #40361.
Comment 21 klark 2016-04-24 02:02:58 UTC
@Peter Collins
Recently,I find that my app worked good in debug mode and release mode in all devices when i active multidex option only.When i active proguard in release mode,my project buid error:"java.exe" exited with code 1.A part of building output as follows:
PROGUARD : warning : there were 220 unresolved references to classes or interfaces.
             You may need to specify additional library jars (using '-libraryjars').
    PROGUARD : warning : there were 10 unresolved references to program class members.
             Your input classes appear to be inconsistent.
          You should consider explicitly keeping the mentioned class members
          (using '-keep' or '-keepclassmembers').
             You may need to recompile them and try again.
             Alternatively, you may have to specify the option 
             '-dontskipnonpubliclibraryclassmembers'.
    java.io.IOException: Please correct the above warnings first.
    	at proguard.Initializer.execute(Initializer.java:321)
    	at proguard.ProGuard.initialize(ProGuard.java:211)
    	at proguard.ProGuard.execute(ProGuard.java:86)
    	at proguard.ProGuard.main(ProGuard.java:492)
    Picked up JAVA_TOOL_OPTIONS:  -Dfile.encoding=UTF8
    C:\Program Files (x86)\MSBuild\Xamarin\Android\Xamarin.Android.Common.targets(2110,3): error MSB6006: "java.exe" exited with code 1.
Done executing task "Proguard" -- FAILED.
Done building target "_CompileToDalvikWithDx" in project "MultidexCrashTestCore.Droid.csproj" -- FAILED.
Done building project "MultidexCrashTestCore.Droid.csproj" -- FAILED.

So I research and find some text must be added in proguard.cfg and mark as proguard configuration in xamarin:
-dontskipnonpubliclibraryclassmembers
-ignorewarnings 

Now my project build successfully ,But get a startup running crashed information:
[AndroidRuntime] java.lang.RuntimeException: Unable to instantiate application android.support.multidex.MultiDexApplication: java.lang.ClassNotFoundException: Didn't find class "android.support.multidex.MultiDexApplication" on path: DexPathList[[zip file "/data/app/AnXinMe.RemoteTv.Droid-1.apk"],nativeLibraryDirectories=[/data/app-lib/AnXinMe.RemoteTv.Droid-1, /vendor/lib, /system/lib]]...
[AndroidRuntime] Caused by: java.lang.ClassNotFoundException: Didn't find class "android.support.multidex.MultiDexApplication" on path: DexPathList[[zip file "/data/app/AnXinMe.RemoteTv.Droid-1.apk"],nativeLibraryDirectories=[/data/app-lib/AnXinMe.RemoteTv.Droid-1, /vendor/lib, /system/lib]]
Comment 22 James 2017-01-12 19:17:02 UTC
Atsushi Eno

Could you explain what you mean by "add a new "MultiDexMainDexList" MSBuild action (item) to the Android Application project"?

I'm experiencing this same issue when I deploy my application to any droid device. I must use multi-dex due to many libraries

Note You need to log in before you can comment on or make changes to this bug.