Git Product home page Git Product logo

Comments (6)

jonpryor avatar jonpryor commented on May 18, 2024 1

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:

Line Description File Project Path
1794 The "GenerateJavaStubs" task failed unexpectedly. Xamarin.Android.Common.targets Scratch.Gxa1151 ../../../../../../Library/Frameworks/Mono.framework/External/xbuild/Xamarin/Android/Xamarin.Android.Common.targets

What we should report is, in the case of my example (I took the default template, and added a public MainActivity(string) constructor), report:

Line Description File Project Path
8 XAwhatever: The type MainActivity must contain a default constructor. MainActivity.cs Scratch.Gxa1151 MainActivity.cs

from xamarin-android.

jonpryor avatar jonpryor commented on May 18, 2024 1

@asterixorobelix: Any type mentioned in AndroidManifest.xml -- any type which is created by Android -- must have a default constructor.

from xamarin-android.

JonDouglas avatar JonDouglas commented on May 18, 2024

@anirugu Can you upload a full diagnostic build output?

from xamarin-android.

 avatar commented on May 18, 2024

Thanks for reply, I will update you tonight !

from xamarin-android.

jonpryor avatar jonpryor commented on May 18, 2024

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.cs should also use log.LogError() instead of throwing the exception.

from xamarin-android.

asterixorobelix avatar asterixorobelix commented on May 18, 2024

I have been having this issue too. After adding a blank constructor to the Activity, the error went away..

from xamarin-android.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.