From 6cd854cb4952038d11cea5c0c7aa035f66614f8e Mon Sep 17 00:00:00 2001 From: Marek Habersack Date: Tue, 9 Jun 2020 05:57:35 +0000 Subject: [PATCH] [ci] Preliminary JDK11 Support (#4567) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Context: https://issuetracker.google.com/issues/150189789 Context: https://developer.android.com/preview/features#signature-scheme-v4 Context: https://developer.android.com/preview/features#incremental Preliminary JDK 11 support. The Android SDK Build-tools r30.0.0-rc4 package currently requires JDK 11 in order to use `apksigner.jar`: Task "AndroidApkSigner" Task Parameter:ApkSignerJar=C:\Users\dlab14\android-toolchain\sdk\build-tools\30.0.0-rc4\lib\apksigner.jar … Task Parameter:ToolPath=C:\Program Files\Android\jdk\microsoft_dist_openjdk_1.8.0.25\bin Task Parameter:ManifestFile=obj\Release\android\AndroidManifest.xml C:\Program Files\Android\jdk\microsoft_dist_openjdk_1.8.0.25\bin\java.exe -jar C:\Users\dlab14\android-toolchain\sdk\build-tools\30.0.0-rc4\lib\apksigner.jar sign --ks "C:\Users\dlab14\AppData\Local\Xamarin\Mono for Android\debug.keystore" --ks-pass pass:android --ks-key-alias androiddebugkey --key-pass pass:android --min-sdk-version 21 --max-sdk-version 29 "C:\A\vs2019xam00000Y-1\_work\1\s\bin\TestRelease\temp\BuildAotApplication AndÜmläüts_x86_64_True_True\bin\Release\UnnamedProject.UnnamedProject-Signed.apk" java.lang.UnsupportedClassVersionError: com/android/apksigner/ApkSignerTool has been compiled by a more recent version of the Java Runtime (class file version 53.0), this version of the Java Runtime only recognizes class file versions up to 52.0 at java.lang.ClassLoader.defineClass1(Native Method) … …\Xamarin.Android.Common.targets(2559,2): error MSB6006: "java.exe" exited with code 1. This could be triggered by using the Android SDK Manager to install Build-tools r30.0.0-rc4, then overriding the `$(AndroidSdkBuildToolsVersion)` MSBuild property in `App.csproj`: 30.0.0-rc4 Many previous commits have added support for JDK 11, e.g. d99facb1, dcee2c84, 4742d50d, 89f3dc15, and 895b7bc5 (among many others). Additionally, c8ab4555 updated the build environment so that *both* JetBrains OpenJDK 1.8 and 11 were installed, though 1.8 was still used. Now it's time to "flip the build environment," and use JDK 11 to build the product, installers, and run (most) unit tests: * Update `azure-pipelines.yaml` and `azure-pipelines-oss.yaml` so that JDK 11 is used to build everything. * Update `xaprepare` so that when `$(JavaSdkDirectory)` isn't overridden, JDK 11 is used by default. * Override the `JI_JAVA_HOME` environment variable when preparing `external/Java.Interop` so that it uses the desired JDK. * Update the default `$(LatestSupportedJavaVersion)` value to 11.0.4, the version of the JDK we install. * Update the `` task so that JDK 11 is required when `$(AndroidSdkBuildToolsVersion)` is >= r30. This will cause an XA0032 error if JDK 1.8 is used to build a project when `$(AndroidSdkBuildToolsVersion)` is >= r30. * `apksigner` from Build-tools r30 creates a new `.idsig` file next to the `.apk`. This is to enable a new `adb install --incremental` feature. Add the `.idsig` file to `@(FileWrites)`. * Update various unit test `.csproj` files to consistently `` the `Configuration.props` file and use properties within it for default values. This in particular allowed building e.g. `samples/HelloWorld` to implicitly use JDK 11. * Increase "expected" times in `tests/msbuild-times-reference/MSBuildDeviceIntegration.csv` as JDK 11 appears to be slower than JDK 1.8 (🙁). * *Disable* support for `@(JavaSourceJar)` when JDK 11 is used. JDK 11 changes the HTML generated by the `javadoc` command, and we need to update our HTML parser to handle it. In the interest of expediency, disable this for now. The Android Designer integration tests continue to use JDK 1.8, as the Designer doesn't currently build under JDK 11. TODO: * Fix `@(JavaSourceJar)` support: https://github.com/xamarin/xamarin-android/issues/4789 * Allow Android Designer to work with JDK 11, run Designer integration tests using JDK 11. * Figure out how to not accidentally bitrot JDK 1.8 support. Co-authored-by: Jonathan Pryor Co-authored-by: Jonathan Peppers Co-authored-by: Jonathan Pobst Co-authored-by: Peter Collins --- Documentation/release-notes/4567.md | 32 +++++++++++ .../automation/azure-pipelines-oss.yaml | 5 +- build-tools/automation/azure-pipelines.yaml | 54 +++++++++++++++---- .../setup-test-environment.yaml | 30 +++++++---- .../xaprepare/ConfigAndData/Configurables.cs | 2 +- .../Step_PrepareExternalJavaInterop.Unix.cs | 1 + .../HelloLibrary/HelloLibrary.csproj | 8 ++- samples/HelloWorld/HelloWorld.csproj | 2 - .../targets/Microsoft.Android.Sdk.props | 2 +- .../Tasks/Legacy/ValidateJavaVersion.cs | 17 +++++- .../BindingBuildTest.cs | 27 ++++++++++ .../Xamarin.Android.Build.Tests/BuildTest.cs | 18 ++++++- .../Tasks/KeyToolTests.cs | 2 +- .../Xamarin.Android.Bindings.targets | 6 ++- .../Xamarin.Android.Common.props.in | 2 +- .../Xamarin.Android.Common.targets | 1 + .../LocalTests.NUnit/LocalTests.NUnit.csproj | 5 +- .../Xamarin.Android.Bcl-Tests.csproj | 5 +- .../BuildTests/CodeBehindBuildTests.csproj | 10 +++- .../CommonSampleLibrary.csproj | 9 +++- .../Xamarin.Android.JcwGen-Tests.csproj | 5 +- .../EmbeddedDSO/EmbeddedDSO.csproj | 6 ++- .../TestRunner.xUnit/TestRunner.xUnit.csproj | 5 +- .../Xamarin.Android.Locale-Tests.csproj | 5 +- .../MSBuildDeviceIntegration.csv | 22 ++++---- 25 files changed, 219 insertions(+), 62 deletions(-) create mode 100644 Documentation/release-notes/4567.md diff --git a/Documentation/release-notes/4567.md b/Documentation/release-notes/4567.md new file mode 100644 index 00000000000..02dbf23bd2c --- /dev/null +++ b/Documentation/release-notes/4567.md @@ -0,0 +1,32 @@ +### Preliminary JDK 11 Support + +Xamarin.Android can now use JDK 11 to build libraries and applications. + +JDK 11 is required in order to use Android SDK Build-tools r30, +currently a release candidate. Future versions of the Android SDK +*may* require JDK 11 for more scenarios. JDK 11 *is not required* +at this point in time. + +Project authors can try switching to JDK 11 now to prepare +potential future JDK 11 requirements. + +To do so: + + 1. Install JDK 11, for example + [JetBrains Runtime](https://confluence.jetbrains.com/display/JBR/JetBrains+Runtime) + + 2. Tell Xamarin.Android to use JDK 11. This can be done within + [Visual Studio](https://docs.microsoft.com/en-us/xamarin/android/troubleshooting/questions/update-jdk?tabs=windows), + or can be done by setting the the `$(JavaSdkDirectory)` MSBuild + property to refer to the root of the JDK installation from (1). + +#### Known Issues + +When JDK 11 is used, the `@(JavaSourceJar)` Build action is not supported, +and binding projects will not parse Javadoc to determine parameter names. +This may result in different parameter names for existing bindings projects. +Authors of bindings projects affected by this change are recommended to +continue to use JDK 8 to build the bindings projects until this issue is +resolved. + +The fix is being tracked as: https://github.com/xamarin/xamarin-android/issues/4789 diff --git a/build-tools/automation/azure-pipelines-oss.yaml b/build-tools/automation/azure-pipelines-oss.yaml index e23d63e643b..338bac45e10 100644 --- a/build-tools/automation/azure-pipelines-oss.yaml +++ b/build-tools/automation/azure-pipelines-oss.yaml @@ -17,7 +17,8 @@ pr: # Predefined variables: https://docs.microsoft.com/en-us/azure/devops/pipelines/build/variables?view=azure-devops&tabs=yaml # https://dev.azure.com/xamarin/public/_apps/hub/ms.vss-ciworkflow.build-ci-hub?_a=edit-build-definition&id=48&view=Tab_Variables variables: - XA.Jdk.Folder: jdk-1.8 + XA.Jdk8.Folder: jdk-1.8 + XA.Jdk11.Folder: jdk-11 XA.Build.MacOSSPool: VSEng-Xamarin-RedmondMacMojaveBuildPool-Android-OSS XA.Build.LinuxOSSPool: Xamarin-Android-Ubuntu-Public @@ -158,7 +159,7 @@ stages: - script: echo "##vso[task.setvariable variable=HOME]$(Agent.HomeDirectory)" displayName: set HOME to agent directory - - script: echo "##vso[task.setvariable variable=PATH]$PATH:$(Agent.HomeDirectory)/android-toolchain/$(XA.Jdk.Folder)/bin" + - script: echo "##vso[task.setvariable variable=PATH]$PATH:$(Agent.HomeDirectory)/android-toolchain/$(XA.Jdk11.Folder)/bin" displayName: append jdk tools to PATH - script: make jenkins V=1 PREPARE_CI_PR=1 PREPARE_AUTOPROVISION=1 CONFIGURATION=$(XA.Build.Configuration) diff --git a/build-tools/automation/azure-pipelines.yaml b/build-tools/automation/azure-pipelines.yaml index 15a8056ff7b..f30d4e924f2 100644 --- a/build-tools/automation/azure-pipelines.yaml +++ b/build-tools/automation/azure-pipelines.yaml @@ -44,7 +44,8 @@ resources: # Global variables variables: - XA.Jdk.Folder: jdk-1.8 + XA.Jdk8.Folder: jdk-1.8 + XA.Jdk11.Folder: jdk-11 NuGetArtifactName: nupkgs InstallerArtifactName: installers TestAssembliesArtifactName: test-assemblies @@ -97,8 +98,8 @@ stages: - checkout: self submodules: recursive - - script: echo "##vso[task.setvariable variable=JAVA_HOME]$HOME/Library/Android/$(XA.Jdk.Folder)" - displayName: set JAVA_HOME + - script: echo "##vso[task.setvariable variable=JI_JAVA_HOME]$HOME/Library/Android/$(XA.Jdk11.Folder)" + displayName: set JI_JAVA_HOME - task: UseDotNet@2 displayName: install .NET Core $(DotNetCorePreviewVersion) @@ -241,6 +242,10 @@ stages: inputs: version: $(DotNetCorePreviewVersion) + - script: | + echo ##vso[task.setvariable variable=JI_JAVA_HOME]%USERPROFILE%\android-toolchain\$(XA.Jdk11.Folder) + displayName: set JI_JAVA_HOME + - task: UseDotNet@2 displayName: install .NET Core $(DotNetCoreVersion) inputs: @@ -900,7 +905,7 @@ stages: if (("$branchName" -ne "master") -and ("$branchName" -notlike "d16*")) { $branchName = "master" } - Set-Location -Path $(System.DefaultWorkingDirectory) + Set-Location -Path $(System.DefaultWorkingDirectory)/designer git checkout $branchName git submodule update -q --init --recursive displayName: Clone and update designer @@ -909,19 +914,31 @@ stages: displayName: provision designer dependencies inputs: github_token: $(GitHub.Token) - provisioning_script: $(System.DefaultWorkingDirectory)/bot-provisioning/dependencies.csx + provisioning_script: $(System.DefaultWorkingDirectory)/designer/bot-provisioning/dependencies.csx provisioning_extra_args: -remove Xamarin.Android -vv DEVDIV_PKGS_NUGET_TOKEN=$(DevDiv.NuGet.Token) SECTOOLS_PKGS_NUGET_TOKEN=$(SecTools.NuGet.Token) - - template: yaml-templates/run-installer.yaml + - template: yaml-templates/setup-test-environment.yaml + parameters: + xaSourcePath: $(System.DefaultWorkingDirectory)/xamarin-android + + - script: echo "##vso[task.setvariable variable=JavaSdkDirectory]$HOME/Library/Android/$(XA.Jdk8.Folder)" + displayName: set JavaSdkDirectory + + - script: echo "##vso[task.setvariable variable=JI_JAVA_HOME]$HOME/Library/Android/$(XA.Jdk8.Folder)" + displayName: reset JI_JAVA_HOME for Designer - template: designer/android-designer-build-mac.yaml@yaml + parameters: + designerSourcePath: $(System.DefaultWorkingDirectory)/designer - template: designer/android-designer-tests.yaml@yaml + parameters: + designerSourcePath: $(System.DefaultWorkingDirectory)/designer - task: CopyFiles@2 displayName: 'Copy binlogs' inputs: - sourceFolder: Xamarin.Designer.Android + sourceFolder: $(System.DefaultWorkingDirectory)/designer/Xamarin.Designer.Android contents: '**/*.binlog' targetFolder: $(Build.ArtifactStagingDirectory)/designer-binlogs overWrite: true @@ -964,7 +981,7 @@ stages: if (("$branchName" -ne "master") -and ("$branchName" -notlike "d16*")) { $branchName = "master" } - Set-Location -Path $(System.DefaultWorkingDirectory) + Set-Location -Path $(System.DefaultWorkingDirectory)\designer git checkout $branchName git submodule update -q --init --recursive displayName: Clone and update designer @@ -973,19 +990,34 @@ stages: displayName: provision designer dependencies inputs: github_token: $(GitHub.Token) - provisioning_script: $(System.DefaultWorkingDirectory)\bot-provisioning\dependencies.csx + provisioning_script: $(System.DefaultWorkingDirectory)\designer\bot-provisioning\dependencies.csx provisioning_extra_args: -vv DEVDIV_PKGS_NUGET_TOKEN=$(DevDiv.NuGet.Token) SECTOOLS_PKGS_NUGET_TOKEN=$(SecTools.NuGet.Token) - - template: yaml-templates\run-installer.yaml + - template: yaml-templates\setup-test-environment.yaml + parameters: + xaSourcePath: $(System.DefaultWorkingDirectory)\xamarin-android + + - script: echo "##vso[task.setvariable variable=JI_JAVA_HOME]$HOME/Library/Android/$(XA.Jdk8.Folder)" + displayName: reset JI_JAVA_HOME for Designer + condition: and(succeeded(), eq(variables['agent.os'], 'Darwin')) + + - script: | + echo ##vso[task.setvariable variable=JI_JAVA_HOME]%USERPROFILE%\android-toolchain\$(XA.Jdk8.Folder) + displayName: reset JI_JAVA_HOME for Designer + condition: and(succeeded(), eq(variables['agent.os'], 'Windows_NT')) - template: designer\android-designer-build-win.yaml@yaml + parameters: + designerSourcePath: $(System.DefaultWorkingDirectory)\designer - template: designer\android-designer-tests.yaml@yaml + parameters: + designerSourcePath: $(System.DefaultWorkingDirectory)\designer - task: CopyFiles@2 displayName: 'Copy binlogs' inputs: - sourceFolder: Xamarin.Designer.Android + sourceFolder: $(System.DefaultWorkingDirectory)/designer/Xamarin.Designer.Android contents: '**/*.binlog' targetFolder: $(Build.ArtifactStagingDirectory)/designer-binlogs overWrite: true diff --git a/build-tools/automation/yaml-templates/setup-test-environment.yaml b/build-tools/automation/yaml-templates/setup-test-environment.yaml index 75160917cf9..a6ca69ee251 100644 --- a/build-tools/automation/yaml-templates/setup-test-environment.yaml +++ b/build-tools/automation/yaml-templates/setup-test-environment.yaml @@ -1,6 +1,7 @@ parameters: configuration: $(XA.Build.Configuration) provisionExtraArgs: -vv -f + xaSourcePath: $(System.DefaultWorkingDirectory) steps: - checkout: self @@ -16,6 +17,15 @@ steps: inputs: version: $(DotNetCorePreviewVersion) +- script: echo "##vso[task.setvariable variable=JI_JAVA_HOME]$HOME/Library/Android/$(XA.Jdk11.Folder)" + displayName: set JI_JAVA_HOME + condition: and(succeeded(), eq(variables['agent.os'], 'Darwin')) + +- script: | + echo ##vso[task.setvariable variable=JI_JAVA_HOME]%USERPROFILE%\android-toolchain\$(XA.Jdk11.Folder) + displayName: set JI_JAVA_HOME + condition: and(succeeded(), eq(variables['agent.os'], 'Windows_NT')) + - task: UseDotNet@2 displayName: install .NET Core $(DotNetCoreVersion) inputs: @@ -35,20 +45,20 @@ steps: - task: MSBuild@1 displayName: build xaprepare inputs: - solution: build-tools/xaprepare/xaprepare.sln + solution: ${{ parameters.xaSourcePath }}/build-tools/xaprepare/xaprepare.sln configuration: ${{ parameters.configuration }} msbuildArguments: /restore - script: > - mono build-tools/xaprepare/xaprepare/bin/${{ parameters.configuration }}/xaprepare.exe --s=UpdateMono --auto-provision=yes --auto-provision-uses-sudo=yes --no-emoji --run-mode=CI && - mono build-tools/xaprepare/xaprepare/bin/${{ parameters.configuration }}/xaprepare.exe --s=Required --auto-provision=yes --auto-provision-uses-sudo=yes --no-emoji --run-mode=CI && - mono build-tools/xaprepare/xaprepare/bin/${{ parameters.configuration }}/xaprepare.exe --s=AndroidToolchain --no-emoji --run-mode=CI + mono ${{ parameters.xaSourcePath }}/build-tools/xaprepare/xaprepare/bin/${{ parameters.configuration }}/xaprepare.exe --s=UpdateMono --auto-provision=yes --auto-provision-uses-sudo=yes --no-emoji --run-mode=CI && + mono ${{ parameters.xaSourcePath }}/build-tools/xaprepare/xaprepare/bin/${{ parameters.configuration }}/xaprepare.exe --s=Required --auto-provision=yes --auto-provision-uses-sudo=yes --no-emoji --run-mode=CI && + mono ${{ parameters.xaSourcePath }}/build-tools/xaprepare/xaprepare/bin/${{ parameters.configuration }}/xaprepare.exe --s=AndroidToolchain --no-emoji --run-mode=CI displayName: install test dependencies condition: and(succeeded(), eq(variables['agent.os'], 'Darwin')) - script: > - $(System.DefaultWorkingDirectory)\build-tools\xaprepare\xaprepare\bin\${{ parameters.configuration }}\xaprepare.exe --s=Required --auto-provision=yes --no-emoji --run-mode=CI && - $(System.DefaultWorkingDirectory)\build-tools\xaprepare\xaprepare\bin\${{ parameters.configuration }}\xaprepare.exe --s=AndroidToolchain --no-emoji --run-mode=CI + ${{ parameters.xaSourcePath }}\build-tools\xaprepare\xaprepare\bin\${{ parameters.configuration }}\xaprepare.exe --s=Required --auto-provision=yes --no-emoji --run-mode=CI && + ${{ parameters.xaSourcePath }}\build-tools\xaprepare\xaprepare\bin\${{ parameters.configuration }}\xaprepare.exe --s=AndroidToolchain --no-emoji --run-mode=CI displayName: install test dependencies condition: and(succeeded(), eq(variables['agent.os'], 'Windows_NT')) @@ -61,17 +71,17 @@ steps: displayName: nuget restore Xamarin.Android.Build.Tasks.sln inputs: command: custom - arguments: restore Xamarin.Android.Build.Tasks.sln -ConfigFile NuGet.config + arguments: restore ${{ parameters.xaSourcePath }}/Xamarin.Android.Build.Tasks.sln -ConfigFile ${{ parameters.xaSourcePath }}/NuGet.config -Verbosity detailed - task: NuGetCommand@2 displayName: nuget restore Xamarin.Android-Tests.sln inputs: command: custom - arguments: restore Xamarin.Android-Tests.sln -ConfigFile NuGet.config + arguments: restore ${{ parameters.xaSourcePath }}/Xamarin.Android-Tests.sln -ConfigFile ${{ parameters.xaSourcePath }}/NuGet.config -Verbosity detailed - task: MSBuild@1 displayName: build Xamarin.Android.Tools.BootstrapTasks.csproj inputs: - solution: build-tools/xamarin.Android.Tools.BootstrapTasks/Xamarin.Android.Tools.BootstrapTasks.csproj + solution: ${{ parameters.xaSourcePath }}/build-tools/xamarin.Android.Tools.BootstrapTasks/Xamarin.Android.Tools.BootstrapTasks.csproj configuration: ${{ parameters.configuration }} - msbuildArguments: /restore /bl:$(System.DefaultWorkingDirectory)/bin/Test${{ parameters.configuration }}/BootstrapTasks.binlog + msbuildArguments: /restore /bl:${{ parameters.xaSourcePath }}/bin/Test${{ parameters.configuration }}/BootstrapTasks.binlog diff --git a/build-tools/xaprepare/xaprepare/ConfigAndData/Configurables.cs b/build-tools/xaprepare/xaprepare/ConfigAndData/Configurables.cs index f3ee0bbd5bd..40334c39e6c 100644 --- a/build-tools/xaprepare/xaprepare/ConfigAndData/Configurables.cs +++ b/build-tools/xaprepare/xaprepare/ConfigAndData/Configurables.cs @@ -54,7 +54,7 @@ public static partial class Defaults { public static readonly char[] PropertyListSeparator = new [] { ':' }; - public static readonly string JdkFolder = "jdk-1.8"; + public static readonly string JdkFolder = "jdk-11"; public static readonly Version JetBrainsOpenJDK11Version = new Version (Configurables.JetBrainsOpenJDK11Version); public static readonly Version JetBrainsOpenJDK11Release = new Version (Configurables.JetBrainsOpenJDK11Release); diff --git a/build-tools/xaprepare/xaprepare/Steps/Step_PrepareExternalJavaInterop.Unix.cs b/build-tools/xaprepare/xaprepare/Steps/Step_PrepareExternalJavaInterop.Unix.cs index ce59185c1fb..b676976e7dc 100644 --- a/build-tools/xaprepare/xaprepare/Steps/Step_PrepareExternalJavaInterop.Unix.cs +++ b/build-tools/xaprepare/xaprepare/Steps/Step_PrepareExternalJavaInterop.Unix.cs @@ -20,6 +20,7 @@ async Task ExecuteOSSpecific (Context context) "prepare", "V=1", $"CONFIGURATION={context.Configuration}", + $"JI_JAVA_HOME={context.OS.JavaHome}", $"JAVA_HOME={context.OS.JavaHome}", $"JI_MAX_JDK={Configurables.Defaults.MaxJDKVersion}", } diff --git a/samples/HelloWorld/HelloLibrary/HelloLibrary.csproj b/samples/HelloWorld/HelloLibrary/HelloLibrary.csproj index 03f205b8c89..0200146e047 100644 --- a/samples/HelloWorld/HelloLibrary/HelloLibrary.csproj +++ b/samples/HelloWorld/HelloLibrary/HelloLibrary.csproj @@ -13,9 +13,15 @@ HelloLibrary 512 false - True portable + + + $(AndroidFrameworkVersion) + true false diff --git a/samples/HelloWorld/HelloWorld.csproj b/samples/HelloWorld/HelloWorld.csproj index 8761ab56ee9..fb2db55208f 100644 --- a/samples/HelloWorld/HelloWorld.csproj +++ b/samples/HelloWorld/HelloWorld.csproj @@ -14,8 +14,6 @@ Properties\AndroidManifest.xml Resources Assets - true - v7.1 d8 portable diff --git a/src/Xamarin.Android.Build.Tasks/Microsoft.Android.Sdk/targets/Microsoft.Android.Sdk.props b/src/Xamarin.Android.Build.Tasks/Microsoft.Android.Sdk/targets/Microsoft.Android.Sdk.props index 3c6c758283e..bf850dd94a2 100644 --- a/src/Xamarin.Android.Build.Tasks/Microsoft.Android.Sdk/targets/Microsoft.Android.Sdk.props +++ b/src/Xamarin.Android.Build.Tasks/Microsoft.Android.Sdk/targets/Microsoft.Android.Sdk.props @@ -5,7 +5,7 @@ true 1.0 - 1.8.0 + 11.0.4 1.8.0 false true diff --git a/src/Xamarin.Android.Build.Tasks/Tasks/Legacy/ValidateJavaVersion.cs b/src/Xamarin.Android.Build.Tasks/Tasks/Legacy/ValidateJavaVersion.cs index 9e54758dad5..352d6697d2c 100644 --- a/src/Xamarin.Android.Build.Tasks/Tasks/Legacy/ValidateJavaVersion.cs +++ b/src/Xamarin.Android.Build.Tasks/Tasks/Legacy/ValidateJavaVersion.cs @@ -48,6 +48,13 @@ protected override bool ValidateJava (string javaExe, Regex versionRegex) Version GetJavaVersionForFramework () { var apiLevel = MonoAndroidHelper.SupportedVersions.GetApiLevelFromFrameworkVersion (TargetFrameworkVersion); + if (apiLevel >= 30) { + // At present, it *looks like* API-R works with Build-tools r29, but + // historically API-X requires Build-tools rX, so if/when API-30 + // requires Build-tools r30, it will require JDK11. + // return new Version (11, 0); + return new Version (1, 8); + } if (apiLevel >= 24) return new Version (1, 8); else if (apiLevel == 23) @@ -58,10 +65,18 @@ Version GetJavaVersionForFramework () Version GetJavaVersionForBuildTools () { + string buildToolsVersionString = AndroidSdkBuildToolsVersion; + if (buildToolsVersionString != null) { + int index = buildToolsVersionString.IndexOf ('-'); + if (index != -1) + buildToolsVersionString = buildToolsVersionString.Substring (0, index); + } Version buildTools; - if (!Version.TryParse (AndroidSdkBuildToolsVersion, out buildTools)) { + if (!Version.TryParse (buildToolsVersionString, out buildTools)) { return Version.Parse (LatestSupportedJavaVersion); } + if (buildTools >= new Version (30, 0, 0)) + return new Version (11, 0); if (buildTools >= new Version (24, 0, 1)) return new Version (1, 8); return Version.Parse (MinimumSupportedJavaVersion); diff --git a/src/Xamarin.Android.Build.Tasks/Tests/Xamarin.Android.Build.Tests/BindingBuildTest.cs b/src/Xamarin.Android.Build.Tasks/Tests/Xamarin.Android.Build.Tests/BindingBuildTest.cs index 3a5e3bb5d6e..00e9be9856a 100644 --- a/src/Xamarin.Android.Build.Tasks/Tests/Xamarin.Android.Build.Tests/BindingBuildTest.cs +++ b/src/Xamarin.Android.Build.Tasks/Tests/Xamarin.Android.Build.Tests/BindingBuildTest.cs @@ -485,11 +485,38 @@ public String greet (String name, java.util.Date date) BinaryContent = () => Convert.FromBase64String (sourcesJarBase64) }); Assert.IsTrue (bindingBuilder.Build (binding), "binding build should have succeeded"); + var jdkVersion = GetJdkVersion (); + if (jdkVersion > new Version (9, 0)) { + Assert.Ignore ("JDK 11 and @(JavaSourceJar) don't currently mix."); + return; + } string xml = bindingBuilder.Output.GetIntermediaryAsText ("docs/Com.Xamarin.Android.Test.Msbuildtest/JavaSourceJarTest.xml"); Assert.IsTrue (xml.Contains (" - name to display."), "missing doc"); } } + static Version GetJdkVersion () + { + var jdkPath = AndroidSdkResolver.GetJavaSdkPath (); + var releasePath = Path.Combine (jdkPath, "release"); + if (!File.Exists (releasePath)) + return null; + foreach (var line in File.ReadLines (releasePath)) { + const string JavaVersionStart = "JAVA_VERSION=\""; + if (!line.StartsWith (JavaVersionStart, StringComparison.OrdinalIgnoreCase)) + continue; + var value = line.Substring (JavaVersionStart.Length, line.Length - JavaVersionStart.Length - 1); + int last = 0; + for (last = 0; last < value.Length; ++last) { + if (char.IsDigit (value, last) || value [last] == '.') + continue; + break; + } + return Version.Parse (last == value.Length ? value : value.Substring (0, last)); + } + return null; + } + [Test] [TestCaseSource (nameof (ClassParseOptions))] public void DesignTimeBuild (string classParser) diff --git a/src/Xamarin.Android.Build.Tasks/Tests/Xamarin.Android.Build.Tests/BuildTest.cs b/src/Xamarin.Android.Build.Tasks/Tests/Xamarin.Android.Build.Tests/BuildTest.cs index ab89431ca04..50b0c564eac 100644 --- a/src/Xamarin.Android.Build.Tasks/Tests/Xamarin.Android.Build.Tests/BuildTest.cs +++ b/src/Xamarin.Android.Build.Tasks/Tests/Xamarin.Android.Build.Tests/BuildTest.cs @@ -3307,13 +3307,14 @@ public void GetDependencyWhenBuildToolsAreMissingTest () $"TargetFrameworkRootPath={referencesPath}", $"AndroidSdkDirectory={androidSdkPath}", }; + string buildToolsVersion = GetExpectedBuildToolsVersion (); using (var builder = CreateApkBuilder (Path.Combine (path, proj.ProjectName), cleanupAfterSuccessfulBuild: false, cleanupOnDispose: false)) { builder.ThrowOnBuildFailure = false; builder.Target = "GetAndroidDependencies"; Assert.True (builder.Build (proj, parameters: parameters), string.Format ("First Build should have succeeded")); StringAssertEx.Contains ("platforms/android-26", builder.LastBuildOutput, "platforms/android-26 should be a dependency."); - StringAssertEx.Contains ("build-tools/29.0.2", builder.LastBuildOutput, "build-tools/29.0.2 should be a dependency."); + StringAssertEx.Contains ($"build-tools/{buildToolsVersion}", builder.LastBuildOutput, $"build-tools/{buildToolsVersion} should be a dependency."); StringAssertEx.Contains ("platform-tools", builder.LastBuildOutput, "platform-tools should be a dependency."); } } @@ -3340,17 +3341,30 @@ public void GetDependencyWhenSDKIsMissingTest ([Values (true, false)] bool creat $"AndroidSdkDirectory={androidSdkPath}", }; + string buildToolsVersion = GetExpectedBuildToolsVersion (); using (var builder = CreateApkBuilder (Path.Combine (path, proj.ProjectName), cleanupAfterSuccessfulBuild: false, cleanupOnDispose: false)) { builder.ThrowOnBuildFailure = false; builder.Target = "GetAndroidDependencies"; Assert.True (builder.Build (proj, parameters: parameters), string.Format ("First Build should have succeeded")); StringAssertEx.Contains ("platforms/android-26", builder.LastBuildOutput, "platforms/android-26 should be a dependency."); - StringAssertEx.Contains ("build-tools/29.0.2", builder.LastBuildOutput, "build-tools/29.0.2 should be a dependency."); + StringAssertEx.Contains ($"build-tools/{buildToolsVersion}", builder.LastBuildOutput, $"build-tools/{buildToolsVersion} should be a dependency."); StringAssertEx.Contains ("platform-tools", builder.LastBuildOutput, "platform-tools should be a dependency."); } } + static readonly XNamespace MSBuildXmlns = "http://schemas.microsoft.com/developer/msbuild/2003"; + + static string GetExpectedBuildToolsVersion () + { + var propsPath = Path.Combine (XABuildPaths.TopDirectory, "src", "Xamarin.Android.Build.Tasks", "Xamarin.Android.Common.props.in"); + var props = XElement.Load (propsPath); + var AndroidSdkBuildToolsVersion = props.Elements (MSBuildXmlns+"PropertyGroup") + .Elements (MSBuildXmlns+"AndroidSdkBuildToolsVersion") + .FirstOrDefault (); + return AndroidSdkBuildToolsVersion?.Value?.Trim (); + } + [Test] public void ValidateUseLatestAndroid () { diff --git a/src/Xamarin.Android.Build.Tasks/Tests/Xamarin.Android.Build.Tests/Tasks/KeyToolTests.cs b/src/Xamarin.Android.Build.Tasks/Tests/Xamarin.Android.Build.Tests/Tasks/KeyToolTests.cs index 0917fd3da31..6e7f49aafcc 100644 --- a/src/Xamarin.Android.Build.Tasks/Tests/Xamarin.Android.Build.Tests/Tasks/KeyToolTests.cs +++ b/src/Xamarin.Android.Build.Tasks/Tests/Xamarin.Android.Build.Tests/Tasks/KeyToolTests.cs @@ -206,7 +206,7 @@ public void CreateDebugKeyStoreWithStrongPassword () Assert.AreEqual (0, warnings.Count, "Task should have no warnings."); Assert.AreEqual (0, task.ExitCode, "ExitCode should have been 0"); string output = string.Join (" ", messages.Select (x => x.Message)); - Assert.IsTrue (output.Contains ("Certificate fingerprint (SHA1):"), "Certificate SHA1 should have been printed."); + Assert.IsTrue (output.Contains ("Certificate fingerprint (SHA"), "Certificate SHA1 or SHA-256 should have been printed."); } } } diff --git a/src/Xamarin.Android.Build.Tasks/Xamarin.Android.Bindings.targets b/src/Xamarin.Android.Build.Tasks/Xamarin.Android.Bindings.targets index c892555512b..385c158efe3 100755 --- a/src/Xamarin.Android.Build.Tasks/Xamarin.Android.Bindings.targets +++ b/src/Xamarin.Android.Build.Tasks/Xamarin.Android.Bindings.targets @@ -265,6 +265,7 @@ Copyright (C) 2012 Xamarin Inc. All rights reserved. @@ -278,6 +279,7 @@ Copyright (C) 2012 Xamarin Inc. All rights reserved. @@ -441,9 +443,9 @@ Copyright (C) 2012 Xamarin Inc. All rights reserved. + Outputs="@(IntermediateAssembly->'$(OutputPath)%(filename).xml')"> false true true - 1.8.0 + 11.0.4 1.6.0 1.0 {abi}{versionCode:D5} diff --git a/src/Xamarin.Android.Build.Tasks/Xamarin.Android.Common.targets b/src/Xamarin.Android.Build.Tasks/Xamarin.Android.Common.targets index 13218f68da6..caa426360c9 100644 --- a/src/Xamarin.Android.Build.Tasks/Xamarin.Android.Common.targets +++ b/src/Xamarin.Android.Build.Tasks/Xamarin.Android.Common.targets @@ -2876,6 +2876,7 @@ because xbuild doesn't support framework reference assemblies. + diff --git a/tests/BCL-Tests/LocalTests.NUnit/LocalTests.NUnit.csproj b/tests/BCL-Tests/LocalTests.NUnit/LocalTests.NUnit.csproj index 9d7fb214e89..4e6cc859724 100644 --- a/tests/BCL-Tests/LocalTests.NUnit/LocalTests.NUnit.csproj +++ b/tests/BCL-Tests/LocalTests.NUnit/LocalTests.NUnit.csproj @@ -8,14 +8,15 @@ Library LocalTests.NUnit LocalTests.NUnit - v8.1 Resources\Resource.designer.cs Resource Resources Assets - true + + $(AndroidFrameworkVersion) + true false diff --git a/tests/BCL-Tests/Xamarin.Android.Bcl-Tests/Xamarin.Android.Bcl-Tests.csproj b/tests/BCL-Tests/Xamarin.Android.Bcl-Tests/Xamarin.Android.Bcl-Tests.csproj index 32c40b79c9c..3d53c373d09 100644 --- a/tests/BCL-Tests/Xamarin.Android.Bcl-Tests/Xamarin.Android.Bcl-Tests.csproj +++ b/tests/BCL-Tests/Xamarin.Android.Bcl-Tests/Xamarin.Android.Bcl-Tests.csproj @@ -9,18 +9,19 @@ Library UnitTestRunner Xamarin.Android.Bcl_Tests - v8.1 True Resources\Resource.designer.cs Resource Properties\AndroidManifest.xml Resources Assets - true false armeabi-v7a;x86 + + $(AndroidFrameworkVersion) + true false diff --git a/tests/CodeBehind/BuildTests/CodeBehindBuildTests.csproj b/tests/CodeBehind/BuildTests/CodeBehindBuildTests.csproj index b45956d5f82..37ec2f759d4 100644 --- a/tests/CodeBehind/BuildTests/CodeBehindBuildTests.csproj +++ b/tests/CodeBehind/BuildTests/CodeBehindBuildTests.csproj @@ -8,17 +8,23 @@ Library Xamarin.Android.Tests.CodeBehindBuildTests CodeBehindBuildTests - v8.1 True Resources\Resource.designer.cs Resource Properties\AndroidManifest.xml Resources Assets - true True portable <_ApkDebugKeyStore>debug.keystore + false + + + + $(AndroidFrameworkVersion) true diff --git a/tests/CodeBehind/CommonSampleLibrary/CommonSampleLibrary.csproj b/tests/CodeBehind/CommonSampleLibrary/CommonSampleLibrary.csproj index 580c08556e3..34e7a43b765 100644 --- a/tests/CodeBehind/CommonSampleLibrary/CommonSampleLibrary.csproj +++ b/tests/CodeBehind/CommonSampleLibrary/CommonSampleLibrary.csproj @@ -8,16 +8,21 @@ Library CommonSampleLibrary Assets - true Resources Resources\Resource.designer.cs Resource CommonSampleLibrary - v8.1 8.0.30703 2.0 portable + + + $(AndroidFrameworkVersion) + true false diff --git a/tests/CodeGen-Binding/Xamarin.Android.JcwGen-Tests/Xamarin.Android.JcwGen-Tests.csproj b/tests/CodeGen-Binding/Xamarin.Android.JcwGen-Tests/Xamarin.Android.JcwGen-Tests.csproj index a253079d8ab..5d0e2cf993b 100644 --- a/tests/CodeGen-Binding/Xamarin.Android.JcwGen-Tests/Xamarin.Android.JcwGen-Tests.csproj +++ b/tests/CodeGen-Binding/Xamarin.Android.JcwGen-Tests/Xamarin.Android.JcwGen-Tests.csproj @@ -17,12 +17,13 @@ Xamarin.Android.JcwGen-Tests Properties\AndroidManifest.xml armeabi-v7a;x86 - v9.0 false - true preview + + $(AndroidFrameworkVersion) + true false diff --git a/tests/EmbeddedDSOs/EmbeddedDSO/EmbeddedDSO.csproj b/tests/EmbeddedDSOs/EmbeddedDSO/EmbeddedDSO.csproj index a30e5a8213d..9a9b29e849a 100644 --- a/tests/EmbeddedDSOs/EmbeddedDSO/EmbeddedDSO.csproj +++ b/tests/EmbeddedDSOs/EmbeddedDSO/EmbeddedDSO.csproj @@ -8,15 +8,14 @@ Library EmbeddedDSO Xamarin.Android.EmbeddedDSO_Test - v8.1 True Resources\Resource.designer.cs Resource Properties\AndroidManifest.xml Resources Assets - true false + false @@ -28,6 +27,9 @@ + + $(AndroidFrameworkVersion) +