Skip to content

[build] default $(JavacSource/TargetVersion) to 1.8 for Android code #10050

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

Merged
merged 2 commits into from
Apr 23, 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
1 change: 1 addition & 0 deletions Configuration.props
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,7 @@
<TestsFlavor>$(_TestsProfiledAotName)$(_TestsAotName)</TestsFlavor>
</PropertyGroup>
<PropertyGroup>
<!-- Default to Java 17 for desktop, projects targeting Android should use 1.8 -->
<JavacSourceVersion>17</JavacSourceVersion>
<JavacTargetVersion>17</JavacTargetVersion>
</PropertyGroup>
Expand Down
4 changes: 0 additions & 4 deletions src/Mono.Android/Mono.Android.targets
Original file line number Diff line number Diff line change
Expand Up @@ -162,10 +162,6 @@
<DefineConstants>$(DefineConstants);$([System.String]::Copy('$(_GeneratedDefineConstants)').Replace ('%24(DefineConstants);', ''))</DefineConstants>
</PropertyGroup>
</Target>
<PropertyGroup>
<JavacSourceVersion Condition=" '$(JavacSourceVersion)' == '' And '$(AndroidApiLevel)' != '' And $(AndroidApiLevel) &gt; 23 ">1.8</JavacSourceVersion>
<JavacSourceVersion Condition=" '$(JavacSourceVersion)' == '' ">1.6</JavacSourceVersion>
</PropertyGroup>
Comment on lines -165 to -168
Copy link
Member Author

@jonathanpeppers jonathanpeppers Apr 17, 2025

Choose a reason for hiding this comment

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

Note that this block wasn't doing anything, as $(AndroidApiLevel) is the latest stable in .NET 6+. It's always 36 now in main.

<ItemGroup>
<JavaCallableWrapperSource Include="java\**\*.java" />
</ItemGroup>
Expand Down
4 changes: 4 additions & 0 deletions src/Xamarin.Android.Build.Tasks/Tasks/Javac.cs
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,10 @@ protected override string GenerateCommandLineCommands ()
} else {
cmd.AppendSwitchIfNotNull ("-target ", JavacTargetVersion);
cmd.AppendSwitchIfNotNull ("-source ", JavacSourceVersion);
// Ignore warning when targeting older Java versions
// JAVAC : warning : [options] source value 8 is obsolete and will be removed in a future release
// JAVAC : warning : [options] target value 8 is obsolete and will be removed in a future release
cmd.AppendSwitchIfNotNull ("-Xlint:", "-options");
}

return cmd.ToString ();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1604,7 +1604,7 @@ public void CheckJavaError ()
b.ThrowOnBuildFailure = false;
Assert.IsFalse (b.Build (proj), "Build should have failed.");
var ext = b.IsUnix ? "" : ".exe";
var text = $"TestMe.java(1,8): javac{ext} error JAVAC0000: error: class, interface, enum, or record expected";
var text = $"TestMe.java(1,8): javac{ext} error JAVAC0000: error: class, interface, or enum expected";
Assert.IsTrue (StringAssertEx.ContainsText (b.LastBuildOutput, text), "TestMe.java(1,8) expected");
text = $"TestMe2.java(1,41): javac{ext} error JAVAC0000: error: ';' expected";
Assert.IsTrue (StringAssertEx.ContainsText (b.LastBuildOutput, text), "TestMe2.java(1,41) expected");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,10 @@
<BundleToolVersion Condition="'$(BundleToolVersion)' == ''">@BUNDLETOOL_VERSION@</BundleToolVersion>
<_XamarinAndroidMSBuildDirectory>$(MSBuildThisFileDirectory)</_XamarinAndroidMSBuildDirectory>

<JavacSourceVersion Condition=" '$(JavacSourceVersion)' == '' ">17</JavacSourceVersion>
<JavacTargetVersion Condition=" '$(JavacTargetVersion)' == '' ">17</JavacTargetVersion>
<!-- NOTE: Compile Java code for Android against 1.8 -->
<!-- Invoke-customs are only supported starting with Android O (-min-api 26) -->
<JavacSourceVersion Condition=" '$(JavacSourceVersion)' == '' ">1.8</JavacSourceVersion>
<JavacTargetVersion Condition=" '$(JavacTargetVersion)' == '' ">1.8</JavacTargetVersion>

<!-- Enable nuget package conflict resolution -->
<ResolveAssemblyConflicts>true</ResolveAssemblyConflicts>
Expand Down
4 changes: 4 additions & 0 deletions src/java-runtime/java-runtime.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,10 @@
<TargetFramework>netstandard2.0</TargetFramework>
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
<AppendTargetFrameworkToOutputPath>false</AppendTargetFrameworkToOutputPath>
<!-- NOTE: Compile Java code for Android against 1.8 -->
<!-- Invoke-customs are only supported starting with Android O (-min-api 26) -->
<JavacSourceVersion>1.8</JavacSourceVersion>
<JavacTargetVersion>1.8</JavacTargetVersion>
</PropertyGroup>

<Import Project="..\..\Configuration.props" />
Expand Down
Loading