Skip to content
This repository was archived by the owner on Jul 13, 2026. It is now read-only.

Commit cb41333

Browse files
kdubaujonpryor
authored andcommitted
Get OpenJDK from well-known paths, not just registry (#72)
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.
1 parent 53ffdae commit cb41333

2 files changed

Lines changed: 32 additions & 1 deletion

File tree

‎nuget.version‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
1.0
1+
1.1

‎src/Xamarin.Android.Tools.AndroidSdk/Sdks/AndroidSdkWindows.cs‎

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -134,6 +134,7 @@ IEnumerable<JdkInfo> ToJdkInfos (IEnumerable<string> paths, string locator)
134134

135135
returnToJdkInfos(GetPreferredJdkPaths(),"Preferred Registry")
136136
.Concat(ToJdkInfos(GetOpenJdkPaths(),"OpenJDK"))
137+
.Concat(ToJdkInfos(GetKnownOpenJdkPaths(),"Well-known OpenJDK paths"))
137138
.Concat(ToJdkInfos(GetOracleJdkPaths(),"Oracle JDK"));
138139
}
139140

@@ -163,6 +164,36 @@ private static IEnumerable<string> GetOpenJdkPaths ()
163164
}
164165
}
165166

167+
/// <summary>
168+
/// Locate OpenJDK installations by well known path.
169+
/// </summary>
170+
/// <returns>List of valid OpenJDK paths in version descending order.</returns>
171+
privatestaticIEnumerable<string>GetKnownOpenJdkPaths()
172+
{
173+
stringJdkFolderNamePattern="microsoft_dist_openjdk_";
174+
175+
varpaths=newList<Tuple<string,Version>>();
176+
varrootPaths=newList<string>{
177+
Path.Combine(Environment.ExpandEnvironmentVariables("%ProgramW6432%"),"Android","jdk"),
178+
Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.ProgramFilesX86),"Android","jdk"),
179+
};
180+
181+
foreach(varrootPathinrootPaths){
182+
if(Directory.Exists(rootPath)){
183+
foreach(vardirectoryNameinDirectory.EnumerateDirectories(rootPath,$"{JdkFolderNamePattern}*").ToList()){
184+
varversionString=directoryName.Replace($"{rootPath}\\{JdkFolderNamePattern}",string.Empty);
185+
if(Version.TryParse(versionString,outVersionver)){
186+
paths.Add(newTuple<string,Version>(directoryName,ver));
187+
}
188+
}
189+
}
190+
}
191+
192+
returnpaths.OrderByDescending(v =>v.Item2)
193+
.Where(openJdk =>ProcessUtils.FindExecutablesInDirectory(Path.Combine(openJdk.Item1,"bin"),_JarSigner).Any())
194+
.Select(openJdk =>openJdk.Item1);
195+
}
196+
166197
privatestaticIEnumerable<string>GetOracleJdkPaths()
167198
{
168199
stringsubkey=@"SOFTWARE\JavaSoft\Java Development Kit";

0 commit comments

Comments
 (0)