-
Notifications
You must be signed in to change notification settings - Fork 564
[Xamarin.Android.Build.Tasks] Give a proper warning when JDK 1.8 is required but not installed #698
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
|
This fixes a problem, but isn't elegant. For example, see the System Requirements section of our release notes:
We know this. The problem with this PR is that it adds a new
then their currently working system will no longer work after upgrade. We will instead flag an error. This is, shall we say, not desirable. :-) What should instead be done is we should do in code what we currently have in the release notes: associate a minimum required JDK version which each There is one problem with the above approach: It is entirely plausible that, at some point in time, Android's |
| } catch (Exception ex) { | ||
| Log.LogWarningFromException (ex); | ||
| Log.LogWarning ($"Failed to get the Java SDK version. Please ensure you have Java {minRequiredJavaVersion} or above installed."); | ||
| return; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This doesn't Dispose() of the Process instance. You should wrap the new Process() in a using block to ensure we don't keep a process handle open longer than necessary.
|
Additionally, in the case of Bug #51507, this PR is not relevant at all. ...probably because the commentary is wrong or otherwise non-sensical. :-/ The original issue in that bug is:
This error isn't coming from This error is coming from the I forget which build-tools version is required to support JDK 1.8 bytecode. :-( Given that, it seems that it might be a reasonable idea (?) to associate a build-tools version alongside a JDK version for each API level, to ensure that we can reasonably handle the project. |
|
Just so we don't lose track, the |
| SequencePointsMode="$(_AndroidSequencePointsMode)" | ||
| BuildingInsideVisualStudio="$(BuildingInsideVisualStudio)" | ||
| JavaSdkPath="$(JavaSdkDirectory)" | ||
| MonoAndroidBinPath="$(MonoAndroidBinDirectory)" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This and the following line should not be present.
| Version required = requiredJavaForFrameworkVersion > requiredJavaForBuildTools ? requiredJavaForFrameworkVersion : requiredJavaForBuildTools; | ||
|
|
||
| var proc = new Process (); | ||
| proc.StartInfo.FileName = Path.Combine (JavaSdkPath, "bin", OS.IsWindows ? "java.exe" : "java"); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Perhaps this should be using MonoAndroidHelper.RunProcess()? That should be a bit simpler.
| { | ||
| Version buildTools; | ||
| if (!Version.TryParse (buildToolsVersion, out buildTools)) { | ||
| return new Version (1, 7); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why default to Java 1.7 if we can't parse buildToolsVersion? Shouldn't we default to LatestSupportedJavaVersion?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
where is LatestSupportedJavaVersion defined? I can't see it anywhere?
…equired but not installed Fixes https://bugzilla.xamarin.com/show_bug.cgi?id=51507 If a user has an older verison of Java installed they currently get this kind of helpful error message. "Unsupported major.minor version 52.0" While for the experienced user this might mean "Ah I need Java 1.8". For the new users this is confusing. This commit adds a new property in the Xamarin.Android.Common.props called `$(MinimumRequiredJavaVersion)` This will define the Minimum required version of Java we need. It can be overridden on the command line or in the project is needed. If this mimimum version is NOT met, we will error out. While it might be nicers to issue a warning, this will eventually end up with the above error anyway. So we might as well tell the user exactly what is wrong.
#698) Fixes: https://bugzilla.xamarin.com/show_bug.cgi?id=51507 If a user has an older verison of Java installed they currently get this kind of helpful error message. Unsupported major.minor version 52.0 While for the experienced user this might mean "Ah I need Java 1.8". For the new users this is confusing. This commit adds a new property in the Xamarin.Android.Common.props called $(MinimumRequiredJavaVersion) This will define the Minimum required version of Java we need. It can be overridden on the command line or in the project is needed. If this mimimum version is NOT met, we will error out. While it might be nicers to issue a warning, this will eventually end up with the above error anyway. So we might as well tell the user exactly what is wrong.
Fixes: https://devdiv.visualstudio.com/DevDiv/_workitems/edit/1139590 Context: dotnet/java-interop@afbc5b3 Changes: dotnet/java-interop@dcaf794...afbc5b3 * dotnet/java-interop@afbc5b32: [C++] Get rid of compiler warnings (#703) * dotnet/java-interop@e295b498: [generator] Fix localization error. (#702) * dotnet/java-interop@5a0e37e0: [generator] Support 'managedOverride' metadata (#701) * dotnet/java-interop@f6c12ba3: [Xamarin.Android.Tools.Bytecode] Hide Kotlin synthetic constructors (#700) * dotnet/java-interop@0334f424: [generator] Hide Java.Lang.Object infrastructure (#698) * dotnet/java-interop@c0fcc435: [jcw-gen] Make MSBuild warning/error strings localizable. (#695) Fixes a handful of warnings reported by GCC and clang when building for different platforms. `-Wshadow` warnings: monodroid-glue.cc:1609:8: warning: declaration shadows a static data member of 'xamarin::android::internal::MonodroidRuntime' [-Wshadow] void *api_dso_handle = nullptr; ^ monodroid-glue.cc:102:25: note: previous declaration is here void *MonodroidRuntime::api_dso_handle = nullptr; Fix by renaming the local variable. No functionality changes result from this fix. MinGW builds report: xa-internal-api.cc: In member function ‘virtual mono_bool xamarin::android::internal::MonoAndroidInternalCalls_Impl::monodroid_get_network_interface_up_state(const char*, mono_bool*)’: xa-internal-api.cc:24:86: warning: unused parameter ‘ifname’ [-Wunused-parameter] 24 | MonoAndroidInternalCalls_Impl::monodroid_get_network_interface_up_state (const char *ifname, mono_bool *is_up) | ~~~~~~~~~~~~^~~~~~ xa-internal-api.cc:24:105: warning: unused parameter ‘is_up’ [-Wunused-parameter] 24 | MonoAndroidInternalCalls_Impl::monodroid_get_network_interface_up_state (const char *ifname, mono_bool *is_up) | ~~~~~~~~~~~^~~~~ xa-internal-api.cc: In member function ‘virtual mono_bool xamarin::android::internal::MonoAndroidInternalCalls_Impl::monodroid_get_network_interface_supports_multicast(const char*, mono_bool*)’: xa-internal-api.cc:34:96: warning: unused parameter ‘ifname’ [-Wunused-parameter] 34 | MonoAndroidInternalCalls_Impl::monodroid_get_network_interface_supports_multicast (const char *ifname, mono_bool *supports_multicast) | ~~~~~~~~~~~~^~~~~~ xa-internal-api.cc:34:115: warning: unused parameter ‘supports_multicast’ [-Wunused-parameter] 34 | MonoAndroidInternalCalls_Impl::monodroid_get_network_interface_supports_multicast (const char *ifname, mono_bool *supports_multicast) | ~~~~~~~~~~~^~~~~~~~~~~~~~~~~~ xa-internal-api.cc: In member function ‘virtual int xamarin::android::internal::MonoAndroidInternalCalls_Impl::monodroid_get_dns_servers(void**)’: xa-internal-api.cc:44:66: warning: unused parameter ‘dns_servers_array’ [-Wunused-parameter] 44 | MonoAndroidInternalCalls_Impl::monodroid_get_dns_servers (void **dns_servers_array) | ~~~~~~~^~~~~~~~~~~~~~~~~ xa-internal-api.cc: In member function ‘virtual int xamarin::android::internal::MonoAndroidInternalCalls_Impl::monodroid_getifaddrs(_monodroid_ifaddrs**)’: xa-internal-api.cc:54:82: warning: unused parameter ‘ifap’ [-Wunused-parameter] 54 | MonoAndroidInternalCalls_Impl::monodroid_getifaddrs (struct _monodroid_ifaddrs **ifap) | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~^~~~ xa-internal-api.cc: In member function ‘virtual void xamarin::android::internal::MonoAndroidInternalCalls_Impl::monodroid_freeifaddrs(_monodroid_ifaddrs*)’: xa-internal-api.cc:64:82: warning: unused parameter ‘ifa’ [-Wunused-parameter] 64 | MonoAndroidInternalCalls_Impl::monodroid_freeifaddrs (struct _monodroid_ifaddrs *ifa) | ~~~~~~~~~~~~~~~~~~~~~~~~~~~^~~ Fix by ignoring the unused parameters only during Windows builds by using the C++17 attribute `[[maybe_unused]]` MinGW also reports: embedded-assemblies.cc: In static member function ‘static ssize_t xamarin::android::internal::EmbeddedAssemblies::do_read(int, void*, size_t)’: embedded-assemblies.cc:663:26: warning: conversion from ‘size_t’ {aka ‘long long unsigned int’} to ‘unsigned int’ may change value [-Wconversion] 663 | ret = ::read (fd, buf, count); | It is caused by **read**(2) declared in MinGW headers with the third parameter using an `unsigned int` type instead of the standard `size_t`. Fixed by casting properly on Windows builds.
Fixes https://bugzilla.xamarin.com/show_bug.cgi?id=51507
If a user has an older verison of Java installed they currently get
this kind of helpful error message.
While for the experienced user this might mean "Ah I need Java 1.8".
For the new users this is confusing.
This commit adds a new property in the Xamarin.Android.Common.props
called
This will define the Minimum required version of Java we need.
It can be overridden on the command line or in the project is needed.
If this mimimum version is NOT met, we will error out. While it
might be nicers to issue a warning, this will eventually end up with
the above error anyway. So we might as well tell the user exactly what
is wrong.