Skip to content

Conversation

@kdubau
Copy link
Member

@kdubau kdubau commented Jun 7, 2019

kdubau added 4 commits June 7, 2019 09:43
This method will location Microsoft OpenJdk based on
well-known install location. As of AB#735565 we can no
longer rely on regristry keys.

GetJdkInfos will prefer these well-known paths.
@kdubau kdubau requested a review from pjcollins June 7, 2019 14:33
Although I don't think case matters in paths on Windows.
if (CheckRegistryKeyForExecutable (RegistryEx.CurrentUser, regKey, MDREG_JAVA_SDK, wow, "bin", JarSigner))
return RegistryEx.GetValueString (RegistryEx.CurrentUser, regKey, MDREG_JAVA_SDK, wow);
return null;
return GetKnownOpenJdkPaths ().FirstOrDefault ();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is where things Go Bad™: the intended semantics is that if you call AndroidSdkInfo. SetPreferredJavaSdkPath(), then the default/preferred Java SDK path will be what was specified:

AndroidSdkInfo.SetPreferredJavaSdkPath ("/my/new/JDK/location");
var sdk = new AndroidSdkInfo ();
Console.WriteLine(sdk.JavaSdkPath);
// prints "/my/new/JDK/location"

That semantic works because AndroidSdkWindows.SetPreferredJavaSdkPath() and AndroidSdkWindows.PreferedJavaSdkPath were consistent with each other.

This PR breaks that semantic, and turns AndroidSdkWindows.SetPreferredJavaSdkPath() into a no-op, effectively, because the default (preferred) Java SDK may not be what was ever provided to AndroidSdkWindows.SetPreferredJavaSdkPath() (unless through sheer happenstance the default value is passed to AndroidSdkWindows.SetPreferredJavaSdkPath()...).

Hence my 2019-Mar-26 comment on that issue:

The way that VS sets a custom path is by setting a registry key.

If we don't check that registry key first, then the custom path (effectively) does not exist and it cannot be overridden by the user.

Which returns us to the originally posed (and not yet answered to my satisfaction): what are we trying to solve?

Is it reading from the registry which is bad? Or is it just writing? Both?

Should Windows copy Unix and instead use a plain text file to store this information instead of the Registry? Would that be better?

What about migration and compatibility? Visual Studio 2019 (Windows) has Tools > Options... > Xamarin / Android Settings, which allows setting the Java Development Kit Location value. This value in turn (eventually) uses AndroidSdkWindows.SetPreferredJavaSdkPath().

Which means this change breaks the IDE semantics.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good points, sorry I missed SetPreferredJavaSdkPath ...

I will revert so the change doesn't affect this, but at least we'll be able to find based on well-known paths.

@kdubau kdubau force-pushed the kywhi/fix-735565 branch from 93cce4e to cdabcda Compare June 7, 2019 19:56
Copy link
Member

@pjcollins pjcollins left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am confused as to why the change in https://github.com/xamarin/XamarinVS/pull/10406 didn't first require a change to xamarin-android-tools (such as this) and then a reference update in XamarinVS. However, this extension to OpenJDK resolution makes sense to me given the somewhat limited context I have.

@jonpryor jonpryor merged commit cb41333 into master Jun 10, 2019
jonpryor pushed a commit that referenced this pull request Jun 18, 2019
Context: http://work.azdo.io/735565

Turns Out™ that certain anti-virus programs block or otherwise
mitigate access to various Windows Registry keys.  (No idea which
anti-virus, or what the symptoms are; this is just What I've Heard.)

Reduce reliance on the registry by looking for the JDK within the
`%ProgramW6432%\Android\jdk\microsoft_dist_openjdk_*` directories,
in which the `*` suffix is a `System.Version`-parsable value, and
prefer the highest JDK found there.

The Registry value is still preferred, if set.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants