This is Xamarin's bug tracking system. For product support, please use the support links listed in your Xamarin Account.
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 (show other bugs)
Version: 6.0.0
Hardware: PC Windows
: Normal normal
Target Milestone: 6.1 (C7)
Assignee: Atsushi Eno
: 40515 (view as bug list)
Depends on:
Reported: 2016-05-09 18:18 UTC by Jon Douglas
Modified: 2016-06-03 15:22 UTC (History)
10 users (show)

See Also:
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

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


Given the current stable( we generate an `` class that extends ``. However in the current beta/alpha( / there is not a generated `` class and there's no trace of anything extending ``(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 (This then extends MultiDexApplication as shown below in the Application definition)

(BETA/ALPHA) Custom Application .java:

public class CustomApp
	extends (This does not extend MultiDexApplication)

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

i.e. (STABLE)


public class Application extends {

	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) { ();



public class ApplicationRegistration {

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

Via the release notes - ( However that custom `Application` class only extends `` and thus MultiDex does not get initialized appropriately like it did in Stable via the extended `` 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:

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: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 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:allowBackup="true" android:icon="@drawable/icon" android:debuggable="true">

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

public class CustomApp

*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?

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 `` when MulitDex is enabled, or simply extend `` when it is not enabled.
Comment 8 eladmarg 2016-05-20 20:43:21 UTC
any estimation when the next beta will be released?

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