Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

[build] Support JDK-21 (#9672) #9714

Merged
merged 1 commit into from
Jan 28, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
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.1.1-bin.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-8.12-bin.zip
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,7 @@ It is shared between "legacy" binding projects and .NET 7+ projects.
Jars="@(_BindingJavaLibrariesToCompile);@(_ReferenceJavaLibs)"
JavacTargetVersion="$(JavacTargetVersion)"
JavacSourceVersion="$(JavacSourceVersion)"
JdkVersion="$(_JdkVersion)"
IntermediateOutputPath="$(IntermediateOutputPath)"
AssemblyIdentityMapFile="$(_AndroidLibrayProjectAssemblyMapFile)"
/>
Expand Down Expand Up @@ -171,6 +172,7 @@ It is shared between "legacy" binding projects and .NET 7+ projects.
Jars="@(_JavaLibrariesToCompile);@(_InstantRunJavaReference);@(_ReferenceJavaLibs)"
JavacTargetVersion="$(JavacTargetVersion)"
JavacSourceVersion="$(JavacSourceVersion)"
JdkVersion="$(_JdkVersion)"
IntermediateOutputPath="$(IntermediateOutputPath)"
AssemblyIdentityMapFile="$(_AndroidLibrayProjectAssemblyMapFile)"
/>
Expand Down
22 changes: 20 additions & 2 deletions src/Xamarin.Android.Build.Tasks/Tasks/Javac.cs
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@ public class Javac : JavaCompileToolTask
public string JavacTargetVersion { get; set; }
public string JavacSourceVersion { get; set; }

public string JdkVersion { get; set; }

public override string DefaultErrorCode => "JAVAC0000";

public override bool RunTask ()
Expand Down Expand Up @@ -61,12 +63,28 @@ 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 ()
{
if (string.IsNullOrEmpty (JdkVersion)) {
return false;
}
var jdkVersion = Version.Parse (JdkVersion);
return jdkVersion.Major >= 17;
}

protected override void WriteOptionsToResponseFile (StreamWriter sw)
{
sw.WriteLine ($"-d \"{ClassesOutputDirectory.Replace (@"\", @"\\")}\"");
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>
<MinimumSupportedJavaVersion Condition="'$(MinimumSupportedJavaVersion)' == ''">1.6.0</MinimumSupportedJavaVersion>
<AndroidVersionCodePattern Condition=" '$(AndroidUseLegacyVersionCode)' != 'True' And '$(AndroidVersionCodePattern)' == '' ">{abi}{versionCode:D5}</AndroidVersionCodePattern>
<AndroidResourceGeneratorTargetName>UpdateGeneratedFiles</AndroidResourceGeneratorTargetName>
Expand Down
Loading