-
Notifications
You must be signed in to change notification settings - Fork 544
[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
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Fixes: #9922 Fixes: #9925 In 165cef7, we started compiling with Java 17 by default. This causes warnings in #9922 such as: "/Users/builder/android-toolchain/jdk-21/bin/java" -classpath "/Users/builder/azdo/_work/11/s/xamarin-android/bin/Release/lib/packs/Microsoft.Android.Sdk.Darwin/35.99.0/tools/r8.jar" com.android.tools.r8.D8 --release --no-desugaring --output "obj/Release/release" "/Users/builder/azdo/_work/11/s/xamarin-android/bin/Release/lib/packs/Microsoft.Android.Sdk.Darwin/35.99.0/tools/java_runtime.jar" Warning in /Users/builder/azdo/_work/11/s/xamarin-android/bin/Release/lib/packs/Microsoft.Android.Sdk.Darwin/35.99.0/tools/java_runtime.jar:mono/MonoPackageManager.class at Lmono/MonoPackageManager;LoadApplication(Landroid/content/Context;)V: Invoke-customs are only supported starting with Android O (--min-api 26) This also happens if we go back to Java 9. We can get rid of the warning by desugaring the code to API 21: * #10039 However, we think desugaring in itself could break something (especially for servicing). For now, we think the safest option is: * Target 1.8 for Java code targeting Android. * Desktop Java projects can still target 17. With these changes, tests like `BuildHasNoWarnings()` fail due to build warnings. Next: * When using the `-source` and `-target` switches in the `<Javac/>` MSBuild task, we can pass `-Xlint:-options` to `javac` to prevent warnings about these switches being deprecated. This change is suitable for servicing in .NET 9 and the `BuildHasNoWarnings()` test now passes.
dellis1972
approved these changes
Apr 17, 2025
jonathanpeppers
commented
Apr 17, 2025
Comment on lines
-165
to
-168
<PropertyGroup> | ||
<JavacSourceVersion Condition=" '$(JavacSourceVersion)' == '' And '$(AndroidApiLevel)' != '' And $(AndroidApiLevel) > 23 ">1.8</JavacSourceVersion> | ||
<JavacSourceVersion Condition=" '$(JavacSourceVersion)' == '' ">1.6</JavacSourceVersion> | ||
</PropertyGroup> |
There was a problem hiding this comment.
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.
This was referenced Apr 17, 2025
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Fixes: #9922
Fixes: #9925
In 165cef7, we started compiling with Java 17 by default. This causes warnings in #9922 such as:
This also happens if we go back to Java 9.
We can get rid of the warning by desugaring the code to API 21:
Invoke-customs
warning #10039However, we think desugaring in itself could break something (especially for servicing).
For now, we think the safest option is:
Target 1.8 for Java code targeting Android.
Desktop Java projects can still target 17.
With these changes, tests like
BuildHasNoWarnings()
fail due to build warnings.Next:
-source
and-target
switches in the<Javac/>
MSBuild task, we can pass-Xlint:-options
tojavac
to prevent warnings about these switches being deprecated.This change is suitable for servicing in .NET 9 and the
BuildHasNoWarnings()
test now passes.