Reputation:
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
Upvotes: 16
Views: 12977
Reputation: 3667
I was getting this error on doing a Release build
The "GenerateJavaStubs" task failed unexpectedly.
Nullreference Exception
Restarted VS cleared it up.
Upvotes: 0
Reputation: 31
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.
Upvotes: 0
Reputation: 11
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.
Upvotes: 0
Reputation: 5524
I had this issue because i put activity events under #region block. after removing #region block, everything is working fine in my case.
Upvotes: 0
Reputation: 548
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.
Upvotes: 5
Reputation: 1092
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>
Upvotes: 0
Reputation: 111
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.
Upvotes: 5
Reputation: 31
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);
}
...
}
Upvotes: 3
Reputation: 1
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.
Upvotes: 0
Reputation: 1383
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.
Upvotes: 20