[Xamarin.Android.Build.Tasks] parse JDK release
file directly
#8663
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: #8369
During Android project builds, the
<ValidateJavaVersion/>
MSBuild task currently shells out tojava -version
andjavac -version
to determine if we have a valid & usable JDK.Unfortunately, some customer logs have reported build times that are completely bananas:
java -version
and/orjavac -version
must be quite slow! Reading the source for OpenJDK, it appears thatjava -version
actually starts a JVM to call a single method:That could explain the slowness?
To improve this, let's just parse the file:
With contents:
We can just call
StreamReader.ReadLine()
untilJAVA_VERSION="
is found.I kept the existing logic in place, with an escape hatch if it were ever needed. After a few .NET 9 previews, we could consider removing old logic entirely?
This logic is considerably faster, because we no longer launch a JVM!
Where you can test the "Before" logic by passing
-p:_AndroidUseJavaExeVersion=true
.I assume the customer's log from before (35 calls) would be around 70ms give or take instead of 3 hours and 46 minutes? Even if this estimation was 10x worse, it would still be a huge improvement! 👀