Recently a warning appears in our build logs and Pull Requests on GitHub using SonarCloud/Scanner:
WARN: The version of Java (1.8.0-25) you have used to run this analysis is deprecated and we will stop accepting it from October 2020. Please update to at least Java 11.
We have successfully updated our build server to a new version of Java for most of our projects with no problems at all. However we have a Xamarin.Android project.
Xamarin.Android seems to require a specific version of OpenJdk, the above mentioned 1.8.0 version. If you try a newer version, you get this in the logs:
C:\Program Files (x86)\Microsoft Visual Studio\2019\BuildTools\MSBuild\Xamarin\Android\Xamarin.Android.Common.targets(806, 2): error XA0030: Building with JDK Version 14.0.1
is not supported. Please install JDK version1.8.0
. See https://aka.ms/xamarin/jdk9-errors
The link in the error (https://aka.ms/xamarin/jdk9-errors) seems to indicate that an older version of JDK must be used.
So it looks like from October Xamarin projects will be a problem?
Sorry for the late reply.
I was not aware of this limitation on Xamarin. I guess that you are running your build with Azure DevOps ? If yes, is that on a Microsoft-hosted agent ?
No problem. Our Build Agent runs Visual Studio Build Tools 2019 on an EC2 server running Windows Server 2019. You would probably get the same error if you run a Xamarin.Android project on Visual Studio 2019 on a local dev machine, but change the Java version to 11.
EDIT: Yeah I just confirmed this. A new Xamarin.Android project compiles running the default OpenJdk version provided by Visual Studio, but when you overwrite it with a newer version you get an error.
This compiles (default):
This does not (Java 14):
Thanks. I’ve pushed a small update where the Java version is overriden only when the JAVA_HOME_11_X64 en variable is accessible from the agent, can you try set it up (as you are using a self hosted agent it will not be available i guess) , and verify that the Run Code ANalysis task is with 1.13.0 version. So then you can still compile your Xamarin code with JDK8 and run the analysis with whichever version you have locally (it should be at least Java 11 to get rid of the warning but in your case with java 14 it should be ok)
Let me know.
Awsome, thanks for the prompt action.
Your solution of using the env variable is probably something we can do alright, but we use TeamCity’s Build Agent to trigger the builds. We have sonar-scanner-msbuild to run on the build, roughly similar in syntax to:
dotnet SonarScanner.MSBuild.dll begin
dotnet SonarScanner.MSBuild.dll end
I’m assuming I’d have to wait for a version of MSBuild.dll with the changes?
Ok sorry i though you were running under Azure DevOps (the changes i spoke about above were for our Azure DevOps extension)
How is configured your build ? Do you have the possibility to setup new env variables between each step ?
The Scanner for MSBuild will not be modified for that as it’s just a wrapper around the Scanner itself to pre-fill some configuration files (and hooks into MsBuild), so it doesn’t handle java versions at all.
So some good news on this one. It turns out Xamarin’s msbuild step has a parameter that accepts a SDK directory.
I’ve changed our build step to be
msbuild /p:Configuration=Release /p:JavaSdkDirectory=%env.XAMARIN_JAVA_HOME%
The TeamCity Build now has two parameters:
- env.JAVA_HOME is used by SonarScanner and all of our other projects.
- env.XAMARIN_JAVA_HOME is something I just added now, and is used just by Xamarin (note the backslash must not be present at the end).
The project builds, and no warnings are being generated by Sonar.
Thanks for the help
Very nice ! Thanks for the Tip ! Could be useful for others
This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.