Bug 59031 - multidex Unable to instantiate application android 4.4
Summary: multidex Unable to instantiate application android 4.4
Status: RESOLVED DUPLICATE of bug 59036
Alias: None
Product: Android
Classification: Xamarin
Component: Mono runtime / AOT Compiler ()
Version: 7.4 (15.3)
Hardware: PC Windows
: --- normal
Target Milestone: ---
Assignee: Marek Habersack
URL:
Depends on:
Blocks:
 
Reported: 2017-08-25 07:12 UTC by gcnew
Modified: 2017-09-06 03:31 UTC (History)
3 users (show)

Tags:
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 on Developer Community or GitHub with your current version information, steps to reproduce, and relevant error messages or log files if you are hitting an issue that looks similar to this resolved bug and you do not yet see a matching new report.

Related Links:
Status:
RESOLVED DUPLICATE of bug 59036

Description gcnew 2017-08-25 07:12:36 UTC
When multidex is enabled and I launch app on android 4.4 (it works on android 5) app crashes during runtime with the following exception:
java.lang.RuntimeException: Unable to instantiate application com.company.App: java.lang.ClassNotFoundException: Didn't find class "com.company.App" on path: DexPathList[[zip file "/data/app/com.company.apppackage-2.apk"],nativeLibraryDirectories=[/data/app-lib/com.company.apppackage-2, /system/lib]]
at android.app.LoadedApk.makeApplication(LoadedApk.java:507)
at android.app.ActivityThread.handleBindApplication(ActivityThread.java:4301)
at android.app.ActivityThread.access$1500(ActivityThread.java:135)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1256)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:136)
at android.app.ActivityThread.main(ActivityThread.java:5001)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:515)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:785)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:601)
at dalvik.system.NativeStart.main(Native Method)
Caused by: java.lang.ClassNotFoundException: Didn't find class "com.company.App" on path: DexPathList[[zip file "/data/app/com.company.apppackage-2.apk"],nativeLibraryDirectories=[/data/app-lib/com.company.apppackage-2, /system/lib]]
at dalvik.system.BaseDexClassLoader.findClass(BaseDexClassLoader.java:56)
at java.lang.ClassLoader.loadClass(ClassLoader.java:497)
at java.lang.ClassLoader.loadClass(ClassLoader.java:457)
at android.app.Instrumentation.newApplication(Instrumentation.java:975)
at android.app.LoadedApk.makeApplication(LoadedApk.java:502)
... 11 more
I'm using latest stable xamarin.android windows and the same can be said about mac.
I am using Xamarin 4.6.0.299, android sdk 7.4.0.21, vs 2017 update 15.3.2. I tried building on Windows and on Mac, no difference.
When I add multidex.keep with the content suggested on the other threads nothing changes, the same exception:
com/company/App.class
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
mono/MonoPackageManager.class
mono/MonoPackageManager_Resources.class
mono/MonoRuntimeProvider.class
mono/android/app/NotifyTimeZoneChanges.class
mono/android/app/ApplicationRegistration.class
I tried changing mainDexClasses.bat then reverted it back.
When I remove multidex.keep, compile and look into obj/Debug/multidex.keep I can see that it contains one line of all the classes without delimeters like that
android/support/v7/widget/RecyclerView$6.classcom/google/android/gms/internal/zzbz.classcom/google/android/gms/internal/zzho.classcom/google/android...
No line breaks.
Mac built miltidex.keep contains around 7 lines, last line is similar to windows without line breaks. I don't know if it's ok or not.
I tried splitting them with line breaks and added it to app but it didn't work.
I have custom application with Application attribute. If I don't specify name in manifest multidex application is created instead of my custom app. If I don't specify attribute application name it becomes something like md5... and I cannot specify it in the manifest. I made namespace lowercase, but it didn't work.
Let me know how I can troubleshoot this bug. I spend almost 2 weeks on this bug and no progress was made.
Comment 1 Jon Douglas [MSFT] 2017-08-25 07:45:27 UTC
This is a known issue and I've written on workarounds until this gets fixed. Please also see this duplicate bug for steps on resolving this issue locally.

Seeing that you are "close" to resolving the issue, your next step is to use ClassyShark:

http://www.jon-douglas.com/2017/03/15/apk-tools/

In which you will need to investigate if your application class is making the main dex list.

I'm not sure what you are referring to completely with the naming of the custom application class. To put it simply, you should only be using the [Application] attribute and not doing any manual naming in the AndroidManifest.xml.

Summary:

1. Ensure com.company.App is an actual registered class. i.e. You changed the "Name" attribute in the [Application] class. You can now look in "obj/{Configuration}/android/bin" whether you want to pull in the classes.dex into classyshark.jar and see the proper package name for the custom application class, or dive into the "classes" folder which will also have the same structure.

2. Ensure your custom multidex.keep is being included. Look at your MSBuild Diagnostic Log to see the task with the multidex.keep file as parameters. It should be as simple as searching "multidex.keep" in your build log and seeing the proper path item.

It sounds like your tooling is working fine as it's generating a maindexlist, just not one with your custom application. You will have to override it with a custom multidex.keep in this situation.

I explain how the custom application class works here:

http://www.jon-douglas.com/2016/09/05/xamarin-android-multidex/

I explain how to override your main dex list here:

http://www.jon-douglas.com/2016/09/23/xamarin-android-multidex-keep/

I am marking this issue as a duplicate. If you need additional assistance with this issue, please open up a Stack Overflow question and link to this bugzilla post. I will try my best to answer it in a timely fashion. Thank you for your report!

*** This bug has been marked as a duplicate of bug 55268 ***
Comment 2 Brendan Zagaeski (Xamarin Team, assistant) 2017-09-06 03:31:29 UTC
## Note to Xamarin team

I am correcting the duplication status for tallying purposes based on the timing of the report and the description of the symptom "obj/Debug/multidex.keep ... No line breaks." from Comment 0.  It is _possible_ that the original user from Comment 0 could _also_ be hitting the older issue from Bug 55268, but the first symptom involving the missing line breaks is instead due to Bug 59036, so there is a chance that the fix for that issue alone will be sufficient to resolve the issue for this user.

*** This bug has been marked as a duplicate of bug 59036 ***