The "GenerateJavaStubs" task failed unexpectedly
Asked Answered
G

10

16

I have created one new project in Visual studio and only che in .xml file (put two frame layouts) and when i debug the code i have one error, please told me the solution

Error   1   The "GenerateJavaStubs" task failed unexpectedly.
System.InvalidOperationException: Sequence contains no elements
at System.Linq.Enumerable.Max(IEnumerable`1 source)
at Xamarin.Android.Tools.TypeNameMapGenerator.WriteBinaryMapping(Stream o, Dictionary`2 mapping)
at Xamarin.Android.Tools.TypeNameMapGenerator.WriteJavaToManaged(Stream output)
at Xamarin.Android.Tasks.GenerateJavaStubs.UpdateWhenChanged(String path, Action`1 generator)
at Xamarin.Android.Tasks.GenerateJavaStubs.WriteTypeMappings(List`1 types)
at Xamarin.Android.Tasks.GenerateJavaStubs.Run()
at Xamarin.Android.Tasks.GenerateJavaStubs.Execute()
at Microsoft.Build.BackEnd.TaskExecutionHost.Microsoft.Build.BackEnd.ITaskExecutionHost.Execute()
at Microsoft.Build.BackEnd.TaskBuilder.<ExecuteInstantiatedTask>d__20.MoveNext()    TMS_TabletView.Droid
Greece answered 2/12, 2015 at 10:32 Comment(2)
Can you post your .xml (.axml?) file with the included FrameLayouts?Debag
A similar-looking error was fixed in Xamarin.Android 6.0.2.1: bugzilla.xamarin.com/show_bug.cgi?id=36036 Are you still seeing this issue after updating?Innes
F
20

This still can happen if you use one of Xamarin Plugins that use CrossCurrentActivity, for example Plugins.Share and if you have Application class with [Application] tag. This is because on nuget installation it generates another Application class with same tag and that causes 'GenerateJavaStubs' failure.

Solution is simply delete one of Application classes / merge them into one.

Fundamental answered 13/7, 2016 at 7:43 Comment(2)
This bites me just about every time.Sklar
I was just forced to add this CrossCurrentActivity. But what if I don't have another Application class? But I do have an activity set as launcher to work as an Splash Screen?Britten
I
5

For me this happened after installing the Xamarin Share Plugin (https://www.nuget.org/packages/Plugin.Share). I was setting the theme of my Android app in its assemblyinfo.cs with the line below:

[assembly: Application(Theme = "@style/AppStyle.myApp")]

Simply removing this line resolved the issue, and I then set the theme in MainActivity as you should really anyway.

Impossibly answered 1/6, 2017 at 8:48 Comment(2)
I had [assembly: Application(Debuggable = true)]. Removing this line helped :)Moise
@WojciechKulik did you have any trouble when trying to publish it in release mode ("the apk is debuggable, upload failed") ?Anitraaniweta
A
5

I had the same issue and the error in detail was saying something like; "Path is too long. Bla bla name cannot exceed 248 characters and the other bla bla cannot exceed 260 characters".

And shortening the project name solved my issue.

Apogamy answered 22/1, 2018 at 12:36 Comment(1)
My project name was too long. Made it shorter and everything worked ok.Confidence
P
3

If you have constructor in Activity class, please add default constructor. Or you can remove constructors in class.

This is old source code.

[Activity(Label = "MyActivity", ScreenOrientation = ScreenOrientation.Portrait)]
public class MyActivity : BaseActivity
{
    bool param;

    protected override int LayoutResource
    {
        get
        {
            return Resource.Layout.myactivity;
        }
    }

    public MyActivity(bool param = false)
    {
        this.param = param;
    }

    protected override void OnCreate(Bundle savedInstanceState)
    {
        base.OnCreate(savedInstanceState);
    }

    ...
}

This is updated new source code.

[Activity(Label = "MyActivity", ScreenOrientation = ScreenOrientation.Portrait)]
public class MyActivity : BaseActivity
{
    bool param;

    protected override int LayoutResource
    {
        get
        {
            return Resource.Layout.myactivity;
        }
    }

    public MyActivity()
    {
    }

    public MyActivity(bool param = false)
    {
        this.param = param;
    }

    protected override void OnCreate(Bundle savedInstanceState)
    {
        base.OnCreate(savedInstanceState);
    }

    ...
}
Plasticine answered 8/2, 2017 at 1:34 Comment(0)
E
0

I experienced this problem, and got all the same error messages while creating my very first app on Visual Studio Professional 2015 (with Xamarin). No idea if this will be of any use to anyone else, but we stumbled on something that fixed the problem for us.

In MainActivity.cs, there is some default code when you first open up a "Blank App" project, but we had deleted some of this code, and copied/pasted over it. This is what it initially looks like:

    namespace App3
{
    [Activity(Label = "App3", MainLauncher = true, Icon = "@drawable/icon")]
    public class MainActivity : Activity
    {
        int count = 1;

        protected override void OnCreate(Bundle bundle)
        {
            base.OnCreate(bundle);

            // Set our view from the "main" layout resource
            SetContentView(Resource.Layout.Main);

            // Get our button from the layout resource,
            // and attach an event to it
            Button button = FindViewById<Button>(Resource.Id.MyButton);

            button.Click += delegate { button.Text = string.Format("{0} clicks!", count++); };
        }
    }
}

To fix it: We tried putting back these lines into MainActivity.cs code:

[Activity(Label = "App3", MainLauncher = true, Icon = "@drawable/icon")]
    public class MainActivity : Activity
    {
        int count = 1;

        protected override void OnCreate(Bundle bundle)
        {
            base.OnCreate(bundle);

            // Set our view from the "main" layout resource
            SetContentView(Resource.Layout.Main);

            // Get our button from the layout resource,
            // and attach an event to it
            Button button = FindViewById<Button>(Resource.Id.MyButton);

And then we ran the code and the error went away. Probably just a dumb mistake, and won't always solve the issue, but it worked for us.

Eurhythmics answered 8/8, 2016 at 19:44 Comment(0)
C
0

I had this issue because for some reason my Android Class library got changed into an Android Application type - so VS was looking for Application class in the project.

Solution was to create a blank android class library, and compare project files. I removed any xml tags from the broken project that were "application" specific. like [<]AndroidApplication>true[<]/AndroidApplication>

Claudianus answered 8/7, 2017 at 8:23 Comment(0)
H
0

I had this issue because i put activity events under #region block. after removing #region block, everything is working fine in my case.

Howe answered 19/3, 2018 at 11:22 Comment(0)
M
0

I had this issue because of copying an Android Library to a new project. Visual Studio automatically made me a new resource file, which resulted in having ambiguity problems between the resource file of project 1 and the file of project 2. After solving this, I didn't have a Java Stub error anymore. I don't know if this was the fix, but I didn't do anything else, so it almost has to be although it is a bit weird.

Matelote answered 14/5, 2018 at 9:34 Comment(0)
D
0

None of these answers ended up working for my issue. Here is what did work:

In your Solution Explorer, go to the Android project, right click -> Properties -> Android Options -> Linker -> Linking and choose Sdk Assemblies Only. Also make sure in the Android project -> Properties -> Android Options -> Advanced properties -> Java Max Heap Size is set to 1G.

enter image description here

Dugas answered 7/6, 2018 at 15:7 Comment(0)
A
0

I was getting this error on doing a Release build

The "GenerateJavaStubs" task failed unexpectedly.
Nullreference Exception

Restarted VS cleared it up.

Ammonite answered 15/2, 2019 at 21:50 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.