Skip to content
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

[build] Support JDK-21 #9672

Merged
merged 2 commits into from
Jan 13, 2025
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-8.10.1-bin.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-8.12-bin.zip
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
17 changes: 15 additions & 2 deletions src/Xamarin.Android.Build.Tasks/Tasks/Javac.cs
Original file line number Diff line number Diff line change
Expand Up @@ -60,12 +60,25 @@ protected override string GenerateCommandLineCommands ()
cmd.AppendSwitchIfNotNull ("-J-Dfile.encoding=", "UTF8");

cmd.AppendFileNameIfNotNull (string.Format ("@{0}", TemporarySourceListFile));
cmd.AppendSwitchIfNotNull ("-target ", JavacTargetVersion);
cmd.AppendSwitchIfNotNull ("-source ", JavacSourceVersion);

if (int.TryParse (JavacSourceVersion, out int sourceVersion) &&
int.TryParse (JavacTargetVersion, out int targetVersion) &&
JavacSupportsRelease ()) {
cmd.AppendSwitchIfNotNull ("--release ", Math.Max (sourceVersion, targetVersion).ToString ());
} else {
cmd.AppendSwitchIfNotNull ("-target ", JavacTargetVersion);
cmd.AppendSwitchIfNotNull ("-source ", JavacSourceVersion);
}

return cmd.ToString ();
}

bool JavacSupportsRelease ()
{
var jdkInfo = new JdkInfo (Path.Combine (ToolPath, ".."));
jonathanpeppers marked this conversation as resolved.
Show resolved Hide resolved
return jdkInfo.Version.Major >= 17;
}

protected override void WriteOptionsToResponseFile (StreamWriter sw)
{
var jars = new List<string> ();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
<ImplicitlyExpandNETStandardFacades>false</ImplicitlyExpandNETStandardFacades>
<CopyNuGetImplementations Condition=" '$(CopyNuGetImplementations)' == ''">true</CopyNuGetImplementations>
<YieldDuringToolExecution Condition="'$(YieldDuringToolExecution)' == ''">true</YieldDuringToolExecution>
<LatestSupportedJavaVersion Condition="'$(LatestSupportedJavaVersion)' == ''">17.0.99</LatestSupportedJavaVersion>
<LatestSupportedJavaVersion Condition="'$(LatestSupportedJavaVersion)' == ''">21.0.99</LatestSupportedJavaVersion>
<AndroidVersionCodePattern Condition=" '$(AndroidUseLegacyVersionCode)' != 'True' And '$(AndroidVersionCodePattern)' == '' ">{abi}{versionCode:D5}</AndroidVersionCodePattern>
<AndroidResourceGeneratorTargetName>UpdateGeneratedFiles</AndroidResourceGeneratorTargetName>
<AndroidUseApkSigner Condition=" '$(AndroidUseApkSigner)' == '' ">True</AndroidUseApkSigner>
Expand Down
17 changes: 16 additions & 1 deletion tools/workload-dependencies/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
var CmdlineToolsVersion = (string?) null;
var BuildToolsVersion = (string?) null;
var JdkVersion = (string?) null;
var JdkMaxVersion = (string?) null;
var NdkVersion = (string?) null;
var PlatformToolsVersion = (string?) null;
var PlatformVersion = (string?) null;
Expand All @@ -37,6 +38,9 @@
{ "jdk-version=",
"The JDK {VERSION} dotnet/android is built against.",
v => JdkVersion = v },
{ "jdk-max-version=",
"The maximum JDK {VERSION} dotnet/android supports.",
v => JdkMaxVersion = v },
{ "ndk-version=",
"The Android NDK {VERSION} dotnet/android is built against.",
v => NdkVersion = v },
Expand Down Expand Up @@ -160,7 +164,7 @@ JProperty CreateJdkProperty (XDocument doc)
{
var v = new Version (JdkVersion ?? "17.0");
var start = new Version (v.Major, v.Minor);
var end = new Version (v.Major+1, 0);
var end = GetMaxJdkVersion (v);
var latestRevision = JdkVersion ?? GetLatestRevision (doc, "jdk");
var contents = new JObject (
new JProperty ("version", $"[{start},{end})"));
Expand All @@ -169,6 +173,17 @@ JProperty CreateJdkProperty (XDocument doc)
return new JProperty ("jdk", contents);
}

string GetMaxJdkVersion (Version v)
{
if (!string.IsNullOrEmpty (JdkMaxVersion)) {
// JdkMaxVersion is `$(LatestSupportedJavaVersion)`, which is still a supported version!
// Return the major version past JdkMaxVersion
var x = new Version (JdkMaxVersion);
return new Version (x.Major+1, 0).ToString ();
}
return new Version (v.Major+1, 0).ToString ();
}

IEnumerable<XElement> GetSupportedElements (XDocument doc, string element)
{
if (doc.Root == null) {
Expand Down
1 change: 1 addition & 0 deletions tools/workload-dependencies/WorkloadDependencies.proj
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@
<_WorkloadDeps Include="--build-tools-version=$(AndroidSdkBuildToolsVersion)" />
<_WorkloadDeps Include="--cmdline-tools-version=$(AndroidCommandLineToolsVersion)" />
<_WorkloadDeps Include="--jdk-version=$(JavaSdkVersion)" />
<_WorkloadDeps Include="--jdk-max-version=$(LatestSupportedJavaVersion)" />
<_WorkloadDeps Include="--ndk-version=$(AndroidNdkVersion)" />
<_WorkloadDeps Include="--platform-tools-version=$(AndroidSdkPlatformToolsVersion)" />
<_WorkloadDeps Include="--platform-version=$(AndroidSdkPlatformVersion)" />
Expand Down
Loading