Bug 51507 - Give a proper warning when JDK 1.8 is required but not installed
Summary: Give a proper warning when JDK 1.8 is required but not installed
Alias: None
Product: Android
Classification: Xamarin
Component: MSBuild ()
Version: 7.4 (15.3)
Hardware: PC Mac OS
: High normal
Target Milestone: 15.4
Assignee: dean.ellis
Depends on:
Reported: 2017-01-13 13:51 UTC by Alan McGovern
Modified: 2017-09-27 13:02 UTC (History)
9 users (show)

Tags: bb,NotFixedIn_15.4
Is this bug a regression?: ---
Last known good build:

screenshot of failure (71.65 KB, image/png)
2017-01-13 13:51 UTC, Alan McGovern

Notice (2018-05-24): bugzilla.xamarin.com is now in read-only mode.

Please join us on Visual Studio Developer Community and in the Xamarin and Mono organizations on GitHub to continue tracking issues. Bugzilla will remain available for reference in read-only mode. We will continue to work on open Bugzilla bugs, copy them to the new locations as needed for follow-up, and add the new items under Related Links.

Our sincere thanks to everyone who has contributed on this bug tracker over the years. Thanks also for your understanding as we make these adjustments and improvements for the future.

Please create a new report on Developer Community or GitHub with your current version information, steps to reproduce, and relevant error messages or log files if you are hitting an issue that looks similar to this resolved bug and you do not yet see a matching new report.

Related Links:

Description Alan McGovern 2017-01-13 13:51:01 UTC
Created attachment 19323 [details]
screenshot of failure

If you have modern android SDKs/tools installed, but install JDK 1.7, then your build will fail with this error (see screenshot).

Can we translate that into a pre-requisite check which ensures that java 1.8 is the one being invoked, and then give a descriptive error if an older one (or no java) is found?
Comment 3 Alan McGovern 2017-06-18 17:35:07 UTC
This needs to be detected and reported by Xamarin.Android itself as it is the thing which is enforcing the requirement. The two IDEs should not have to implement minimum JDK version checks as it would be too easy for that to get out of sync with what Xamarin.android requires. 

I'd recommend reassigning this big back to the MSBuild component of Xamarin.Android so the actual build system can correctly report when it's dependencies are too old.
Comment 4 Alan McGovern 2017-06-18 17:36:22 UTC
Anyway, to reproduce this issue you should just install JDK 1.7 instead of JDK 1.8. It's possible the Xamarin.android build system has already fixed this issue over the last 6 months and will correctly detect when java is too old.
Comment 5 Juan Marcelo Tondato 2017-06-19 13:20:33 UTC
Moving the bug to Android for visibility from the right team.
Comment 7 dean.ellis 2017-07-19 10:02:34 UTC
PR up https://github.com/xamarin/xamarin-android/pull/698

I decided a warning was pointless since the compilation will fail anyway. So an error will be raised if we do not find the min required version. 

@Alan I "borrowed" some of your code :P
Comment 8 Jonathan Pryor 2017-07-19 14:01:50 UTC
The description in Comment #0 doesn't match Attachment #19323 [details], which contains the error message:

> java.lang.UnsupportedClassVersionError: com/android/dx/command/Main : Unsupported major.minor version 52.0

That error message is coming from `dx.jar`, from a `dex` tool invocation, from the `< CompileToDalvik/>` task. This can happen when building a project that contains JDK 1.8 bytecode -- e.g. from building under JDK 1.8, or by using a 3rd party library which contains JDK 1.8 bytecode, or targeting API 24+ -- and using an older build-tools version which doesn't support JDK 1.8 bytecode.

Checking the Java version will not help address the above error.

Checking the build-tools version *could*.

What I forget is which build-tools version adds support for JDK 1.8 bytecode. It might be 26.0.0+.
Comment 9 Cody Beyer (MSFT) 2017-08-02 22:16:36 UTC
1.8 was required as of build tools 24.0.1 [1]

I think it is reasonable to check which version is installed and prompt from there

Comment 10 dean.ellis 2017-08-08 15:39:30 UTC
Fixed in xamarin-android/master/099ab6a0
Comment 11 Gaurav Ganorkar 2017-08-23 12:40:25 UTC
I have verified this defect on Master lane but this defect seems to be reproducible on d15-4 latest build

---------------FIXED IN MASTER------------

1-When there is no Java installed , User gets the following helpful message 
Screencast link - https://content.screencast.com/users/Pratik1234/folders/Jing/media/be78ad2d-2304-494a-afb8-83ebd9c1998e/2017-08-23_1731.png

2-When there is Java 1.7 (Old) version is installed , then message displayed as 
Screencast link - https://www.screencast.com/t/kcoq8a9DbM

Xamarin (2bcedc1b2)
Xamarin.Android SDK (HEAD/14c1494d6)
Xamarin.iOS and Xamarin.Mac SDK (35e1985)

Full Build info - https://gist.github.com/mohakbarokar/4a11184dd7ab055e36121705f83dc6ca

---------------NOT FIXED IN d15-4 lane---------

I have verified this issue on the latest d15-4 lane but the issue is still reproducible. I am seeing the same error message attached in bug.

Verified on 
Xamarin (27d400a27)
Xamarin.Android (14c1494)
Xamarin.iOS (35e1985)

Hence keeping this Defect as Resolved Fixed. Once it merge in d15-4 lane then we will re-verify once
Comment 12 Gaurav Ganorkar 2017-09-27 13:02:49 UTC
Verified this issue on the latest d15-4 builds and Issue is Fixed now.

Proper error messages are now shown to user when there is no JDK and Lower version of JDK i.e 1.7 is present

1-When there is no Java installed , User gets the following helpful message 
Screencast link - https://www.screencast.com/t/8Bon9ysm
2-When there is Java 1.7 (Old) version is installed , then message displayed as 
Screencast link -https://www.screencast.com/t/LShziikl

Verified on the build

Microsoft Visual Studio Enterprise 2017 d15rel
Version 15.4.0 Preview 3.0 [26923.0.d15rel]
Microsoft .NET Framework
Version 4.7.02046

Installed Version: Enterprise

Xamarin (1631433ed)
Xamarin.Android SDK (HEAD/58645b22e)
Xamarin.iOS and Xamarin.Mac SDK (9a9f054)

Full build info - https://gist.github.com/parasAmbhore/e9b8312a4504420767d3d03ef8ae6494

Hence marking this defect as Verified FIXED