Bug 2135 - Cannot create package when [Application] is not in a namespace
Summary: Cannot create package when [Application] is not in a namespace
Alias: None
Product: Android
Classification: Xamarin
Component: MSBuild ()
Version: 2.0
Hardware: PC Windows
: --- normal
Target Milestone: ---
Assignee: Bugzilla
Depends on:
Reported: 2011-11-21 17:16 UTC by Jonathan Pobst
Modified: 2012-11-02 13:20 UTC (History)
2 users (show)

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:

Description Jonathan Pobst 2011-11-21 17:16:21 UTC
From https://bugzilla.novell.com/show_bug.cgi?id=691839.


Attempting to create a BaseActivity class with a custom Application class seems
to break packaging. 

Reproducible: Always

Steps to Reproduce:
Including these classes in the project throws an exception during packaging.

public abstract class CustomApplication : Application

public class BaseActivity : Activity
    public new CustomApplication Application
        get { return ( (CustomApplication)base.Application ); }
Actual Results:  
Throws the following exception in build log:

monodroid : error 1: System.NullReferenceException: Object reference not set to
an instance of an object [Z:\svn\PPR\combined\Device\Android\PP\PP.csproj]
    at MonoDroid.Utils.ProcessRocks+<ReadStandardOutput>c__Iterator5.MoveNext
() [0x00000] in <filename unknown>:0 
    at Monodroid.Toolbox.InvokeCommand (IEnumerable`1 commandLine) [0x00000] in
<filename unknown>:0 
    at Monodroid.Toolbox.InvokeJavac (System.String src_path) [0x00000] in
<filename unknown>:0 
    at Monodroid.Droidinator.CreateDalvikBytecode
(System.Collections.Generic.List`1 javaTypes, System.Collections.Generic.List`1
assemblies) [0x00000] in <filename unknown>:0 
    at Monodroid.Droidinator.CreateApk () [0x00000] in <filename unknown>:0 
    at Monodroid.MainClass.Main (System.String[] argv) [0x00000] in <filename
Comment 1 Jonathan Pobst 2011-11-21 17:16:30 UTC
With 2.0, we have the error reporting working better so that you can see the
actual error:

The "GenerateJavaStubs" task failed unexpectedly.
 System.InvalidOperationException: The Name property must be a fully qualified
'package.TypeName' value, and no package was found for 'CustomApplication'.

    at Xamarin.Android.Tasks.JavaTypeInfo..ctor(TypeDefinition type, String
outerType) in C:\Users\Jonathan\Documents\Visual Studio
2010\Projects\monodroid\tools\msbuild\Generator\JavaTypeInfo.cs:line 63
    at Xamarin.Android.Tasks.JavaTypeInfo..ctor(TypeDefinition type) in
C:\Users\Jonathan\Documents\Visual Studio
2010\Projects\monodroid\tools\msbuild\Generator\JavaTypeInfo.cs:line 26
    at Xamarin.Android.Tasks.Generator.CreateJavaSources(List`1 javaTypes,
String outputPath) in C:\Users\Jonathan\Documents\Visual Studio
2010\Projects\monodroid\tools\msbuild\Generator\Generator.cs:line 14
    at Xamarin.Android.Tasks.GenerateJavaStubs.Execute() in
C:\Users\Jonathan\Documents\Visual Studio
2010\Projects\monodroid\tools\msbuild\Tasks\GenerateJavaStubs.cs:line 64

The problem is that we build the package name using Namespace.ApplicationName,
and you don't have this in a namespace.  The workaround is to put the
CustomApplication inside a namespace.

As to fixing the bug, I don't know if there is something we can do
automatically like grab the DefaultNamespace, or we just need to add a better
error message explaining that a namespace is required.
Comment 2 Jonathan Pryor 2012-11-02 13:20:21 UTC
The "problem" is that AndroidManifest.xml CANNOT reference types that exist in the global Java package. Android.App.Application subclasses must be listed in AndroidManifest.xml.

We could solve this by putting all types in the global namespace into the application package's name, which would work, but it's added complexity for a minor corner case.

The real solution: put your Application subclass into a C# namespace, then things Just Work.