Bug 43548 - Somewhat difficult to interpret error ""GenerateJavaStubs" task failed unexpectedly ... Sequence contains no elements" if an Android app project by accident does not have any subclasses of `Activity`
Summary: Somewhat difficult to interpret error ""GenerateJavaStubs" task failed unexpe...
Alias: None
Product: Android
Classification: Xamarin
Component: General (show other bugs)
Version: 7.0 (C8)
Hardware: PC All
: --- minor
Target Milestone: ---
Assignee: Jonathan Pryor
Depends on:
Reported: 2016-08-19 20:19 UTC by Brendan Zagaeski (Xamarin Support)
Modified: 2016-08-20 00:55 UTC (History)
1 user (show)

See Also:
Tags: BZRC6S1_C5SR5S1 papercut
Is this bug a regression?: Yes
Last known good build: Xamarin.Android (Cycle 5 – Service Release 5)

Example diagnostic MSBuild output (215.22 KB, text/plain)
2016-08-19 20:19 UTC, Brendan Zagaeski (Xamarin Support)
Detailed version information (1.67 KB, text/plain)
2016-08-19 20:20 UTC, Brendan Zagaeski (Xamarin Support)

Description Brendan Zagaeski (Xamarin Support) 2016-08-19 20:19:36 UTC
Created attachment 17130 [details]
Example diagnostic MSBuild output

Somewhat difficult to interpret error ""GenerateJavaStubs" task failed unexpectedly ... Sequence contains no elements" if an Android app project by accident does not have any subclasses of `Activity`

If desired, this bug report can be de-prioritized for now to await user reports that show that this point of confusion does in fact arise with some frequency in real-world use.  I am filing it now as one way to document the error condition.

## Regression status: "regression" in Cycle 6 compared to Cycle 5 – Service Release 5

In some ways it's nice that that Cycle 6 "fails faster" in this scenario than Cycle 5 (at build time rather than at application launch time).  But the build time error message in Cycle 6 is significantly more difficult to understand than the launch time error in Cycle 5.

BAD:   Xamarin.Android (Cycle 8 Beta 1)
BAD:   Xamarin.Android (Cycle 6)
GOOD:  Xamarin.Android  (Cycle 5 – Service Release 5)

## Steps to replicate (for example in Xamarin Studio on Mac)

1. Create a new "Android > App > Android App".

2. Remove the `Activity` subclass and the `OnCreate()` override from the `MainActivity` class in `MainActivity.cs` to simulate a scenario where a user might accidentally exclude the `MainActivity.cs` file from compilation.

3. Attempt to build and debug the application on an Android device or emulator.

Or build the `SignAndroidPackage` target for the project via the command line:
xbuild /t:Build /t:SignAndroidPackage AndroidApp1/AndroidApp1.csproj

## BAD Results (with Cycle 6 and above)

The build fails with an error message that is somewhat challenging to interpret:

> /Library/Frameworks/Mono.framework/External/xbuild/Xamarin/Android/Xamarin.Android.Common.targets: error : Error executing task GenerateJavaStubs: Sequence contains no elements
> 		Error executing task GenerateJavaStubs: System.InvalidOperationException: Sequence contains no elements
>   at System.Linq.Enumerable.Max (System.Collections.Generic.IEnumerable`1[T] source) [0x0006a] in <4a648327db854c86ab0ece073e38f4b3>:0 
>   at System.Linq.Enumerable.Max[TSource] (System.Collections.Generic.IEnumerable`1[T] source, System.Func`2[T,TResult] selector) [0x00007] in <4a648327db854c86ab0ece073e38f4b3>:0 
>   at Java.Interop.Tools.JavaCallableWrappers.TypeNameMapGenerator.WriteBinaryMapping (System.IO.Stream o, System.Collections.Generic.Dictionary`2[TKey,TValue] mapping) [0x00015] in <3bec6a0f8b3945ab8cd1742c43134d59>:0 
>   at Java.Interop.Tools.JavaCallableWrappers.TypeNameMapGenerator.WriteJavaToManaged (System.IO.Stream output) [0x00070] in <3bec6a0f8b3945ab8cd1742c43134d59>:0 
>   at Xamarin.Android.Tasks.GenerateJavaStubs.UpdateWhenChanged (System.String path, System.Action`1[T] generator) [0x00014] in <7b8cf0a088cb4e499a73d931c1c995f9>:0 
>   at Xamarin.Android.Tasks.GenerateJavaStubs.WriteTypeMappings (System.Collections.Generic.List`1[T] types) [0x00078] in <7b8cf0a088cb4e499a73d931c1c995f9>:0 
>   at Xamarin.Android.Tasks.GenerateJavaStubs.Run () [0x0016e] in <7b8cf0a088cb4e499a73d931c1c995f9>:0 
>   at Xamarin.Android.Tasks.GenerateJavaStubs.Execute () [0x001d8] in <7b8cf0a088cb4e499a73d931c1c995f9>:0 
>   at Microsoft.Build.BuildEngine.TaskEngine.Execute () [0x00000] in <b1524340ac7e4c06b22fac1b2db62c08>:0 
>   at Microsoft.Build.BuildEngine.BuildTask.Execute () [0x0008f] in <b1524340ac7e4c06b22fac1b2db62c08>:0 

## "BETTER" Results (with Cycle 5)

Xamarin Studio displays an error message dialog after the build completes (when attempting to launch the app on device).

> No Launchable Activity Found
> You will need to manually launch your app or watch face in order to
> debug it. If you can launch it, do so now or cancel to setup a launch
> activity.
> This dialog will close automatically once your app has launched.

The main nice thing about this message is "No Launchable Activity Found" since that hints directly at the root problem that there is no subclass of `Activity` in the project.

## Additional version info (brief)

Xamarin Studio Version 6.1 (build 5345)
Mono 4.6.0 (mono-4.6.0-branch/d0fc1a6) (64-bit)
OS X 10.11.6
Comment 1 Brendan Zagaeski (Xamarin Support) 2016-08-19 20:20:03 UTC
Created attachment 17131 [details]
Detailed version information

Note You need to log in before you can comment on or make changes to this bug.