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

Commit 3974fc3

Browse files
authored
[Xamarin.Android.Tools.AndroidSdk] JdkInfo + JDK11 + Windows (#88)
Context: dotnet/android#4567 Commit 36d7fee added support for JetBrains OpenJDK 11 detection on macOS and Linux. Lacking was *Windows* support for JetBrains OpenJDK 11, because of course it has to be different. In particular, OpenJDK 11 *moves the `jvm` library* for Windows. We checked for it in `{HomePath}\jre\**\jvm.dll` or `{HomePath}\lib\**\jvm.dll`, but neither of those exist. Instead, OpenJDK 11 has `jvm.dll` in `{HomePath}\bin\server\jvm.dll`, which is also the only `.dll` file in the `.tar.gz` which exports the symbol `JNI_CreateJavaVM`. Update `JdkInfo` so that it looks for `{HomePath}\bin\server\jvm.dll` to populate `JdkInfo.JdkJvmPath`.
1 parent 5552b07 commit 3974fc3

1 file changed

Lines changed: 23 additions & 22 deletions

File tree

‎src/Xamarin.Android.Tools.AndroidSdk/JdkInfo.cs‎

Lines changed: 23 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -14,10 +14,6 @@
1414
namespaceXamarin.Android.Tools
1515
{
1616
publicclassJdkInfo{
17-
staticreadonlystring[]JdkLibraryTopDirs={
18-
"jre",
19-
"lib",
20-
};
2117

2218
publicstringHomePath{get;}
2319

@@ -58,27 +54,14 @@ public JdkInfo (string homePath)
5854
JavaPath=ProcessUtils.FindExecutablesInDirectory(binPath,"java").FirstOrDefault();
5955
JavacPath=ProcessUtils.FindExecutablesInDirectory(binPath,"javac").FirstOrDefault();
6056

61-
string?topDir=null;
62-
foreach(stringdirinJdkLibraryTopDirs){
63-
topDir=Path.Combine(HomePath,dir);
64-
if(!Directory.Exists(topDir)){
65-
topDir=null;
66-
continue;
67-
}
68-
break;
69-
}
70-
71-
if(String.IsNullOrEmpty(topDir))
72-
topDir=Path.Combine(HomePath,JdkLibraryTopDirs[0]);
73-
74-
JdkJvmPath=OS.IsMac
75-
?FindLibrariesInDirectory(topDir!,"jli").FirstOrDefault()
76-
:FindLibrariesInDirectory(topDir!,"jvm").FirstOrDefault();
57+
string?jdkJvmPath=GetJdkJvmPath();
7758

7859
ValidateFile("jar",JarPath);
7960
ValidateFile("java",JavaPath);
8061
ValidateFile("javac",JavacPath);
81-
ValidateFile("jvm",JdkJvmPath);
62+
ValidateFile("jvm",jdkJvmPath);
63+
64+
JdkJvmPath=jdkJvmPath!;
8265

8366
varincludes=newList<string>();
8467
varjdkInclude=Path.Combine(HomePath,"include");
@@ -132,6 +115,24 @@ public bool GetJavaSettingsPropertyValue (string key, [NotNullWhen (true)] out s
132115
returnfalse;
133116
}
134117

118+
string?GetJdkJvmPath()
119+
{
120+
stringjreDir=Path.Combine(HomePath,"jre");
121+
stringlibDir=Path.Combine(HomePath,"lib");
122+
123+
if(OS.IsMac){
124+
returnFindLibrariesInDirectory(jreDir,"jli").FirstOrDefault()??
125+
FindLibrariesInDirectory(libDir,"jli").FirstOrDefault();
126+
}
127+
if(OS.IsWindows){
128+
stringbinServerDir=Path.Combine(HomePath,"bin","server");
129+
returnFindLibrariesInDirectory(jreDir,"jvm").FirstOrDefault()??
130+
FindLibrariesInDirectory(binServerDir,"jvm").FirstOrDefault();
131+
}
132+
returnFindLibrariesInDirectory(jreDir,"jvm").FirstOrDefault()??
133+
FindLibrariesInDirectory(libDir,"jvm").FirstOrDefault();
134+
}
135+
135136
staticIEnumerable<string>FindLibrariesInDirectory(stringdir,stringlibraryName)
136137
{
137138
if(!Directory.Exists(dir))
@@ -140,7 +141,7 @@ static IEnumerable<string> FindLibrariesInDirectory (string dir, string libraryN
140141
returnDirectory.EnumerateFiles(dir,library,SearchOption.AllDirectories);
141142
}
142143

143-
voidValidateFile(stringname,stringpath)
144+
voidValidateFile(stringname,string?path)
144145
{
145146
if(path==null||!File.Exists(path))
146147
thrownewArgumentException($"Could not find required file `{name}` within `{HomePath}`; is this a valid JDK?","homePath");

0 commit comments

Comments
 (0)