You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
public ArticleActivity(string path) : base()
{
_path = path;
}
or
public ArticleActivity(string path)
{
_path = path;
}
None of both compiling. The error is GenerateJavaSubs. This thing can be improved in visual studio tooling. At the first place it's not showing detail until I click on detail in errors. It could be better if It's show error on the same code where it's have issue.
The problem is that the error message isn't entirely useful. Build from the command-line, and get:
error MSB4018: The "GenerateJavaStubs" task failed unexpectedly. […/Scratch.Gxa1151/Scratch.Gxa1151/Scratch.Gxa1151.csproj]
error MSB4018: System.InvalidOperationException: The type 'Scratch.Gxa1151.MainActivity' needs to have a public default constructor. […/Scratch.Gxa1151/Scratch.Gxa1151/Scratch.Gxa1151.csproj]
error MSB4018: at Xamarin.Android.Tasks.ManifestDocument.Merge (System.Collections.Generic.List`1[T] subclasses, System.Collections.Generic.List`1[T] selectedWhitelistAssemblies, System.String applicationClass, System.Boolean embed, System.String bundledWearApplicationName, System.Collections.Generic.IEnumerable`1[T] mergedManifestDocuments) [0x004aa] in <acf4a3302c8d4a7eaf06af6dce1aafb2>:0 [… /Scratch.Gxa1151/Scratch.Gxa1151/Scratch.Gxa1151.csproj]
error MSB4018: at Xamarin.Android.Tasks.GenerateJavaStubs.Run (Java.Interop.Tools.Cecil.DirectoryAssemblyResolver res) [0x00491] in <acf4a3302c8d4a7eaf06af6dce1aafb2>:0 [… /Scratch.Gxa1151/Scratch.Gxa1151/Scratch.Gxa1151.csproj]
error MSB4018: at Xamarin.Android.Tasks.GenerateJavaStubs.Execute () [0x00225] in <acf4a3302c8d4a7eaf06af6dce1aafb2>:0 [… /Scratch.Gxa1151/Scratch.Gxa1151/Scratch.Gxa1151.csproj]
error MSB4018: at Microsoft.Build.BackEnd.TaskExecutionHost.Microsoft.Build.BackEnd.ITaskExecutionHost.Execute () [0x00023] in <76dd0031e0df4aa99d9befb4c4585c69>:0 [… /Scratch.Gxa1151/Scratch.Gxa1151/Scratch.Gxa1151.csproj]
error MSB4018: at Microsoft.Build.BackEnd.TaskBuilder+<ExecuteInstantiatedTask>d__26.MoveNext () [0x0022d] in <76dd0031e0df4aa99d9befb4c4585c69>:0 [… /Scratch.Gxa1151/Scratch.Gxa1151/Scratch.Gxa1151.csproj]
The bug is that Activity subclasses with an [Activity] custom attribute -- i.e. any type within AndroidManifest.xml that will be instantiated by Android -- must have a default constructor.
So we're doing the quasi-right thing here: there is an error, and we're reporting it.
The problem is the way we're reporting it: it's useless:
Activity
JonDouglas commentedon Jan 4, 2018
@anirugu Can you upload a full diagnostic build output?
jonpryor commentedon Jan 4, 2018
The problem is that the error message isn't entirely useful. Build from the command-line, and get:
The bug is that
Activitysubclasses with an[Activity]custom attribute -- i.e. any type withinAndroidManifest.xmlthat will be instantiated by Android -- must have a default constructor.So we're doing the quasi-right thing here: there is an error, and we're reporting it.
The problem is the way we're reporting it: it's useless:
What we should report is, in the case of my example (I took the default template, and added a
public MainActivity(string)constructor), report:MainActivitymust contain a default constructor.jonpryor commentedon Jan 4, 2018
Sketching out the fix:
Where we report the error needs to crib the
LookupSource(TypeDefinition)method to obtain the filename and line number of the offending type, so that we can emit a better formed error message.ManifestDocument.csshould also uselog.LogError()instead of throwing the exception.Better report on location of an Activity without default constructor
Better report on location of an Activity without default constructor
Better report on location of an Activity without default constructor (#…
asterixorobelix commentedon Jan 27, 2018
I have been having this issue too. After adding a blank constructor to the Activity, the error went away..
jonpryor commentedon Jan 27, 2018
@asterixorobelix: Any type mentioned in
AndroidManifest.xml-- any type which is created by Android -- must have a default constructor.Bump to xamarin/monodroid/d16-9@06e80c56
Bump to xamarin/monodroid/d16-9@06e80c56 (#5535)