Bug 34209 - Java binding for MultiDexApplication causes Application.Context to be null
Summary: Java binding for MultiDexApplication causes Application.Context to be null
Alias: None
Product: Android
Classification: Xamarin
Component: Bindings ()
Version: unspecified
Hardware: PC Windows
: --- normal
Target Milestone: ---
Assignee: Atsushi Eno
Depends on:
Reported: 2015-09-23 11:57 UTC by Dimitar Dobrev
Modified: 2016-09-21 11:39 UTC (History)
4 users (show)

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

A project to reproduce the problem (24.73 KB, application/zip)
2015-09-23 11:57 UTC, Dimitar Dobrev

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 Dimitar Dobrev 2015-09-23 11:57:14 UTC
Created attachment 13039 [details]
A project to reproduce the problem

In order to work around https://bugzilla.xamarin.com/show_bug.cgi?id=34203, I tried creating my own binding for android-support-multidex. I took the JAR from the Android SDK - extras/android/support/multidex/library/libs. I have attached the project. Using MultiDexApplication as the base class of a custom Application in a Monodroid app causes Application.Context to be null.
Comment 1 Atsushi Eno 2015-09-23 23:01:34 UTC
You cannot simply replace Application class because then it won't initialize mono runtime anymore.
Comment 2 Dimitar Dobrev 2015-09-23 23:06:55 UTC
The MultiDexApplication class generated by my binding expectedly inherits from Application.
Comment 3 xamarin1 2016-02-23 23:30:22 UTC
Hi Dimitar,

Have you been able to work around this problem?
I have exactly the same issue.

Comment 4 Dimitar Dobrev 2016-02-23 23:44:29 UTC
Hello Alex,

My workaround was that a binding for MultiDexApplication is actually useless. As Atsushi Eno has clearly explained at https://bugzilla.xamarin.com/show_bug.cgi?id=34203, Monodroid automatically generates Java code using MultiDexApplication as soon as support for multi-dexing is requested in the project properties. The problem to begin with was that because of a Google's bug which Atsushi Eno found multi-dexing failed with a certain version of the Android SDK, so I tried working around with it with my own binding. This, as you can see, failed, so using his guidance I simply upgraded the Android build tools we use to 23.0.1 where the bug in question has been fixed.
Comment 5 xamarin1 2016-02-24 00:15:43 UTC

Thanks for quick response. I really appreciate this.
I didn't know about MultiDexApplication before. 

In my case I guess there is nothing to do with this then.

I have a jar lib that contains base class MCEApplication: Android.App.Application
Then I create class MyApplication: MCEApplication and its Context is always null.

Thanks a lot anyways!
Comment 6 Bradley Locke 2016-03-31 16:35:17 UTC

So the fix was to add this line to the .csproj file?

<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="4.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">

Comment 7 dean.ellis 2016-09-21 11:39:09 UTC
Looks like the solution to this issue is to use the Sdk Build Tools version 23.0.1
Please reopen if that is not the case.