Bug 40976 - Custom Application subclass does not extend MultiDexApplication when MultiDex is enabled
Summary: Custom Application subclass does not extend MultiDexApplication when MultiDex...
Alias: None
Product: Android
Classification: Xamarin
Component: Tools and Addins ()
Version: 6.0.0
Hardware: PC Windows
: Normal normal
Target Milestone: 6.1 (C7)
Assignee: Atsushi Eno
: 40515 ()
Depends on:
Reported: 2016-05-09 18:18 UTC by Jon Douglas [MSFT]
Modified: 2016-06-03 15:22 UTC (History)
10 users (show)

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

Reproduction (10.85 KB, application/x-zip-compressed)
2016-05-09 18:18 UTC, Jon Douglas [MSFT]

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:

Description Jon Douglas [MSFT] 2016-05-09 18:18:21 UTC
Created attachment 15947 [details]


Given the current stable( we generate an `Application.java` class that extends `android.support.multidex.MultiDexApplication`. However in the current beta/alpha( / there is not a generated `Application.java` class and there's no trace of anything extending `android.support.multidex.MultiDexApplication`(grep yieled no results). This given scenario happens when enabling multi-dex, and also including a Custom Application class. (One tagged with [Application] and extends `Application`)

(STABLE) Custom Application .java:

public class CustomApp
	extends mono.android.app.Application (This then extends MultiDexApplication as shown below in the Application definition)

(BETA/ALPHA) Custom Application .java:

public class CustomApp
	extends android.app.Application (This does not extend MultiDexApplication)

It seems from stable->beta/alpha this has changed from an `Application.java` class to an `ApplicationRegistration.java` class which registers any custom `Application` class

i.e. (STABLE)

package mono.android.app;

public class Application extends android.support.multidex.MultiDexApplication {

	public Application ()
		Context = this;

	static android.content.Context Context;

	public void onCreate () {
		android.content.IntentFilter timezoneChangedFilter  = new android.content.IntentFilter (
		registerReceiver (new NotifyTimeZoneChanges (), timezoneChangedFilter);

	static class NotifyTimeZoneChanges extends android.content.BroadcastReceiver {
		public void onReceive (android.content.Context context, android.content.Intent intent) {
			mono.android.Runtime.notifyTimeZoneChanged ();


package mono.android.app;

public class ApplicationRegistration {

	public static void registerApplications ()
				// Application and Instrumentation ACWs must be registered first.
		mono.android.Runtime.register ("jennatestmultidex.CustomApp, jennatestmultidex, Version=, Culture=neutral, PublicKeyToken=null", com.companyname.jenna.CustomApp.class, com.companyname.jenna.CustomApp.__md_methods);

Via the release notes - (https://developer.xamarin.com/releases/android/xamarin.android_6/xamarin.android_6.1/#Application_Subclassing). However that custom `Application` class only extends `android.app.Application` and thus MultiDex does not get initialized appropriately like it did in Stable via the extended `android.support.multidex.MultiDexApplication` class.

To give a bit of history to this, Multi-dex was accomplished via a MSBuild task that would make the `Application` class extend `MultiDexApplication` as mentioned in the first paragraph above. This was introduced in Xamarin.Android 5.1: https://developer.xamarin.com/releases/android/xamarin.android_5/xamarin.android_5.1/#Multi-Dex_support

However the new issue with the current beta/alpha( / is that there no trace of an Custom Application class, Application class, or AndroidManifest.xml following one of the three methods google provides for enabling multi-dex:

1. Declare this class as the application in your AndroidManifest.xml.

2. Have your Application extends this class. (This is what Xamarin.Android does in the current stable)

3. Have your Application override attachBaseContext starting with

protected void attachBaseContext(Context base) {

Thus because of this, MultiDex.install(this); is never called on beta/alpha( / builds with a Custom Application class defined.

However one note here is that if one does not use a Custom Application Subclass, then the AndroidManifest.xml generates the proper Application that MultiDexApplication uses.

<application android:allowBackup="true" android:icon="@mipmap/icon" android:label="@string/app_name" android:name="android.support.multidex.MultiDexApplication" android:debuggable="true">

If one does use a custom application, we get the following definition:

<application android:allowBackup="true" android:icon="@mipmap/icon" android:label="@string/app_name" android:name="com.companyname.jenna.CustomApp" android:debuggable="true">

Which then brings us back to square 1 of the Custom Application Subclass not extending android.support.multidex.MultiDexApplication in some way.


Please note this reproduction is very minimal and does not actually need MultiDex enabled, but it should demonstrate the issue at hand. If a project that hits the 64k method limit is needed, I can provide that as well.

1. Build the project. Note: You will run into the scenario of the <application> tag referring to the CustomApp subclass.

  <application android:label="MultiDexTest" android:name="com.foxsports.test.CustomApp" android:allowBackup="true" android:icon="@drawable/icon" android:debuggable="true">

2. If you were to exclude the CustomApp class from the project, you'd see something along these lines:

  <application android:label="MultiDexTest" android:name="android.support.multidex.MultiDexApplication" android:allowBackup="true" android:icon="@drawable/icon" android:debuggable="true">

3. You should be able to then compare my observations above to the generated CustomApp.java class:

public class CustomApp
	extends android.app.Application

*Version Information:

Xamarin.Android ( /
Comment 3 Jonathan Pryor 2016-05-18 21:34:53 UTC
Fixed in monodroid/master/a6545062 and monodroid/cycle7/5cf7429d.
Comment 4 Atsushi Eno 2016-05-19 07:53:53 UTC
*** Bug 40515 has been marked as a duplicate of this bug. ***
Comment 5 jellis 2016-05-19 12:35:28 UTC
thank you for working on this one! can you advise if this change is in the cycle 7 RC2 beta update from 5/18? https://releases.xamarin.com/beta-release-cycle-7-release-candidate-2/

Or will this one be expected in the next update?

Thank you,
Comment 6 Jonathan Pryor 2016-05-19 19:14:16 UTC
This will be fixed in Xamarin.Android or later.

The current beta channel has, so the next beta release should include it.
Comment 7 Peter Collins 2016-05-19 20:07:43 UTC
Verified using the attached project against X.A (c479b9e0). The generated java class for a C# class which inherits from Application will now extend `android.support.multidex.MultiDexApplicationandroid.app.Application` when MulitDex is enabled, or simply extend `android.app.Application` when it is not enabled.
Comment 8 eladmarg 2016-05-20 20:43:21 UTC
any estimation when the next beta will be released?