From 51151d727a0438dd049ad2678f9039d8f255d7b2 Mon Sep 17 00:00:00 2001 From: Jonathan Pryor Date: Fri, 16 Aug 2024 14:19:03 -0400 Subject: [PATCH] [Xamarin.Android.Build.Tasks] Rethink default property values (#9155) Context: 5d1ac0a5dfa12e92fc45b384237e929576a418e4 Context: https://github.com/dotnet/android-tools/commit/a6a23bb5c59be8164e115db9ddf750c583c7b3c9 Context: https://learn.microsoft.com/en-us/visualstudio/mac/what-happened-to-vs-for-mac?view=vsmac-2022 Commit 5d1ac0a5 had a brilliant idea: > Of particular note is xamarin/xamarin-android-tools@a6a23bb: > [ed note: now dotnet/android-tools@a6a23bb] > > In order to ensure that both Xamarin.Android and the macOS installer > use the same default version numbers for Android SDK components, we are > now using `Xamarin.Android.Tools.Versions.props` to contain default > version number information. This file is maintained in the > xamarin/xamarin-android-tools repo and will be imported via > `external/xamarin-android-tools`: In the intervening four years (!), we've learned something, and the environment has changed. What we've learned is that this approach is "bump-heavy": in order to update the default value of e.g. `$(AndroidSdkPlatformVersion)`, we'd need to update: 1. dotnet/android-tools 2. xamarin/androidtools 3. Plus other repos that depend on (1) or (2) that are used by (4) 4. xamarin/monodroid 5. dotnet/android This is, to put it mildly, cumbersome. Additionally, it's no longer necessary: Visual Studio for Mac will be retired on 2024-Aug-31, so there is no longer a need to have a common file shared between the .NET for Android SDK and Visual Studio for Mac. Instead of considering `Xamarin.Android.Tools.Versions.props` as the canonical source of truth: 1. Update `Xamarin.Android.Common.targets` to now optionally include a new `Xamarin.Installer.Common.props` file, if present. This will allow e.g. xamarin/android-sdk-installer to eventually provide default property values which are tied to the in-use "Xamarin Manifest" for package installation, e.g. `$(AndroidCommandLineToolsVersion)`, `$(JavaSdkVersion)`. 2. Update `Xamarin.Android.Common.props.in` so that the following properties are set *before* importing `Xamarin.Android.Tools.Versions.props`: * `$(AndroidCommandLineToolsVersion)` * `$(AndroidNdkVersion)` * `$(AndroidSdkBuildToolsVersion)` * `$(AndroidSdkEmulatorVersion)` * `$(AndroidSdkPlatformVersion)` * `$(AndroidSdkPlatformToolsVersion)` * `$(JavaSdkVersion)` This will allow us to update these values when this repo ads support for these versions. Finally, the ["Xamarin" manifest][0] is used by the `InstallAndroidDependencies` target from xamarin/android-sdk-installer, and contains only a select number of Android SDK and JDK versions. Until android-sdk-installer provides `Xamarin.Installer.Common.props`, the versions we use need to be in harmony with the Xamarin manifest, so that the `InstallAndroidDependencies` tests can pass. Partially revert 0aede13b and provision JDK 17.0.8 instead of 17.0.11, as 17.0.8 is in the Xamarin manifest. Explicitly set `$(AndroidNdkVersion)`=26.3.11579264, as that's the latest version in the manifest. [0]: https://aka.ms/AndroidManifestFeed/d17-12 --- build-tools/scripts/Ndk.projitems.in | 1 + build-tools/scripts/XABuildConfig.cs.in | 1 + .../xaprepare/ConfigAndData/Configurables.cs | 6 +++--- .../Configuration.OperatingSystem.props.in | 1 + .../xaprepare/Steps/Step_GenerateFiles.cs | 3 +++ .../AndroidDependenciesTests.cs | 7 +------ .../Xamarin.Android.Build.Tasks.targets | 18 +++++++++++++++++- .../Xamarin.Android.Common.props.in | 12 ++++++++++-- .../Xamarin.Android.Common.targets | 3 +++ 9 files changed, 40 insertions(+), 12 deletions(-) diff --git a/build-tools/scripts/Ndk.projitems.in b/build-tools/scripts/Ndk.projitems.in index 50cce76bec0..93c7ef1ced1 100644 --- a/build-tools/scripts/Ndk.projitems.in +++ b/build-tools/scripts/Ndk.projitems.in @@ -2,6 +2,7 @@ @NDK_RELEASE@ + @NDK_PKG_REVISION@ @NDK_ARMEABI_V7_API@ @NDK_ARMEABI_V7_API_NET@ @NDK_ARM64_V8A_API@ diff --git a/build-tools/scripts/XABuildConfig.cs.in b/build-tools/scripts/XABuildConfig.cs.in index 1dc9f717dc7..f6424409659 100644 --- a/build-tools/scripts/XABuildConfig.cs.in +++ b/build-tools/scripts/XABuildConfig.cs.in @@ -11,6 +11,7 @@ namespace Xamarin.Android.Tools public const string XamarinAndroidVersion = "@XAMARIN_ANDROID_VERSION@"; public const string XamarinAndroidCommitHash = "@XAMARIN_ANDROID_COMMIT_HASH@"; public const string XamarinAndroidBranch = "@XAMARIN_ANDROID_BRANCH@"; + public const string AndroidSdkBuildToolsVersion = "@SDK_BUILD_TOOLS_VERSION@"; public const int AndroidMinimumDotNetApiLevel = @ANDROID_DEFAULT_MINIMUM_DOTNET_API_LEVEL@; public const int AndroidLatestStableApiLevel = @ANDROID_LATEST_STABLE_API_LEVEL@; public const int AndroidLatestUnstableApiLevel = @ANDROID_LATEST_UNSTABLE_API_LEVEL@; diff --git a/build-tools/xaprepare/xaprepare/ConfigAndData/Configurables.cs b/build-tools/xaprepare/xaprepare/ConfigAndData/Configurables.cs index 448d744c14a..e827f32e337 100644 --- a/build-tools/xaprepare/xaprepare/ConfigAndData/Configurables.cs +++ b/build-tools/xaprepare/xaprepare/ConfigAndData/Configurables.cs @@ -17,9 +17,9 @@ partial class Configurables { const string BinutilsVersion = "L_18.1.6-8.0.0"; - const string MicrosoftOpenJDK17Version = "17.0.11"; - const string MicrosoftOpenJDK17Release = "17.0.11.9"; - const string MicrosoftOpenJDK17RootDirName = "jdk-17.0.11+9"; + const string MicrosoftOpenJDK17Version = "17.0.8"; + const string MicrosoftOpenJDK17Release = "17.0.8.7"; + const string MicrosoftOpenJDK17RootDirName = "jdk-17.0.8+7"; static Context ctx => Context.Instance; diff --git a/build-tools/xaprepare/xaprepare/Resources/Configuration.OperatingSystem.props.in b/build-tools/xaprepare/xaprepare/Resources/Configuration.OperatingSystem.props.in index 7b5a2e7bac5..b099fa8e7bc 100644 --- a/build-tools/xaprepare/xaprepare/Resources/Configuration.OperatingSystem.props.in +++ b/build-tools/xaprepare/xaprepare/Resources/Configuration.OperatingSystem.props.in @@ -6,6 +6,7 @@ @OS_RELEASE@ @HOST_CPUS@ @ARCHITECTURE_BITS@ + @JAVA_SDK_VERSION@ @JavaSdkDirectory@ @javac@ @jar@ diff --git a/build-tools/xaprepare/xaprepare/Steps/Step_GenerateFiles.cs b/build-tools/xaprepare/xaprepare/Steps/Step_GenerateFiles.cs index e4f7d26b610..8543f505d5a 100644 --- a/build-tools/xaprepare/xaprepare/Steps/Step_GenerateFiles.cs +++ b/build-tools/xaprepare/xaprepare/Steps/Step_GenerateFiles.cs @@ -156,6 +156,7 @@ GeneratedFile Get_Configuration_OperatingSystem_props (Context context) { "@OS_RELEASE@", context.OS.Release ?? String.Empty }, { "@HOST_CPUS@", context.OS.CPUCount.ToString () }, { "@ARCHITECTURE_BITS@", context.OS.Is64Bit ? "64" : "32" }, + { "@JAVA_SDK_VERSION@", Configurables.Defaults.MicrosoftOpenJDK17Version.ToString () }, { "@JavaSdkDirectory@", context.OS.JavaHome }, { "@javac@", context.OS.JavaCPath }, { "@java@", context.OS.JavaPath }, @@ -185,6 +186,7 @@ GeneratedFile Get_XABuildConfig_cs (Context context) { "@NDK_X86_API@", BuildAndroidPlatforms.NdkMinimumAPILegacy32.ToString ().ToString () }, { "@NDK_X86_64_API@", BuildAndroidPlatforms.NdkMinimumAPI.ToString ().ToString () }, { "@XA_SUPPORTED_ABIS@", context.Properties.GetRequiredValue (KnownProperties.AndroidSupportedTargetJitAbis).Replace (':', ';') }, + { "@SDK_BUILD_TOOLS_VERSION@", context.Properties.GetRequiredValue (KnownProperties.XABuildToolsFolder) }, { "@ANDROID_DEFAULT_MINIMUM_DOTNET_API_LEVEL@", context.Properties.GetRequiredValue (KnownProperties.AndroidMinimumDotNetApiLevel) }, { "@ANDROID_DEFAULT_TARGET_DOTNET_API_LEVEL@", context.Properties.GetRequiredValue (KnownProperties.AndroidDefaultTargetDotnetApiLevel) }, { "@ANDROID_LATEST_STABLE_API_LEVEL@", context.Properties.GetRequiredValue (KnownProperties.AndroidLatestStableApiLevel) }, @@ -207,6 +209,7 @@ GeneratedFile Get_Ndk_projitems (Context context) var replacements = new Dictionary (StringComparer.Ordinal) { { "@NDK_RELEASE@", BuildAndroidPlatforms.AndroidNdkVersion }, + { "@NDK_PKG_REVISION@", BuildAndroidPlatforms.AndroidNdkPkgRevision }, { "@NDK_ARMEABI_V7_API@", BuildAndroidPlatforms.NdkMinimumAPILegacy32.ToString () }, { "@NDK_ARMEABI_V7_API_NET@", BuildAndroidPlatforms.NdkMinimumAPI.ToString () }, { "@NDK_ARM64_V8A_API@", BuildAndroidPlatforms.NdkMinimumAPI.ToString () }, diff --git a/src/Xamarin.Android.Build.Tasks/Tests/Xamarin.Android.Build.Tests/AndroidDependenciesTests.cs b/src/Xamarin.Android.Build.Tasks/Tests/Xamarin.Android.Build.Tests/AndroidDependenciesTests.cs index 787f4b65430..e08e17c7c3b 100644 --- a/src/Xamarin.Android.Build.Tasks/Tests/Xamarin.Android.Build.Tests/AndroidDependenciesTests.cs +++ b/src/Xamarin.Android.Build.Tasks/Tests/Xamarin.Android.Build.Tests/AndroidDependenciesTests.cs @@ -217,12 +217,7 @@ public void GetDependencyWhenSDKIsMissingTest ([Values (true, false)] bool creat 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 (); + return XABuildConfig.AndroidSdkBuildToolsVersion; } } } diff --git a/src/Xamarin.Android.Build.Tasks/Xamarin.Android.Build.Tasks.targets b/src/Xamarin.Android.Build.Tasks/Xamarin.Android.Build.Tasks.targets index 0d0578566fa..eabc7205b07 100644 --- a/src/Xamarin.Android.Build.Tasks/Xamarin.Android.Build.Tasks.targets +++ b/src/Xamarin.Android.Build.Tasks/Xamarin.Android.Build.Tasks.targets @@ -196,10 +196,26 @@ DestinationFile="Xamarin.Android.BuildInfo.txt" Replacements="@JAVA_INTEROP_COMMIT@=$(_BuildInfo_JavaInteropCommit);@SQLITE_COMMIT@=$(_BuildInfo_SqliteCommit);@XAMARIN_ANDROID_TOOLS_COMMIT@=$(_BuildInfo_XamarinAndroidToolsCommit);"> + + <_XACommonPropsReplacement Include="@COMMAND_LINE_TOOLS_VERSION@=$(CommandLineToolsFolder)" /> + <_XACommonPropsReplacement Include="@BUNDLETOOL_VERSION@=$(XABundleToolVersion)" /> + <_XACommonPropsReplacement Include="@JAVA_SDK_VERSION@=$(JavaSdkVersion)" /> + + <_XACommonPropsReplacement Include="@NDK_PKG_REVISION@=26.3.11579264" /> + <_XACommonPropsReplacement Include="@NDK_ARM64_V8A_API@=$(AndroidNdkApiLevel_ArmV8a)" /> + <_XACommonPropsReplacement Include="@NDK_ARMEABI_V7_API@=$(AndroidNdkApiLevel_ArmV7a)" /> + <_XACommonPropsReplacement Include="@NDK_X86_64_API@=$(AndroidNdkApiLevel_X86_64)" /> + <_XACommonPropsReplacement Include="@NDK_X86_API@=$(AndroidNdkApiLevel_X86)" /> + <_XACommonPropsReplacement Include="@PACKAGE_VERSION_BUILD@=$(XAVersionCommitCount)" /> + <_XACommonPropsReplacement Include="@PACKAGE_VERSION@=$(ProductVersion)" /> + <_XACommonPropsReplacement Include="@SDK_BUILD_TOOLS_VERSION@=$(XABuildToolsFolder)" /> + <_XACommonPropsReplacement Include="@SDK_PLATFORM_TOOLS_VERSION@=$(XAPlatformToolsVersion)" /> + <_XACommonPropsReplacement Include="@SDK_PLATFORM_VERSION@=android-$(AndroidLatestStableApiLevel)" /> + + Replacements="@(_XACommonPropsReplacement)"> - - + + @SDK_BUILD_TOOLS_VERSION@ + @SDK_PLATFORM_TOOLS_VERSION@ + @SDK_PLATFORM_VERSION@ + + @COMMAND_LINE_TOOLS_VERSION@ + + @NDK_PKG_REVISION@ + @JAVA_SDK_VERSION@ + <_JavaInteropReferences>Java.Interop;System.Runtime Xamarin diff --git a/src/Xamarin.Android.Build.Tasks/Xamarin.Android.Common.targets b/src/Xamarin.Android.Build.Tasks/Xamarin.Android.Common.targets index 11509f6622e..df1bf28d741 100644 --- a/src/Xamarin.Android.Build.Tasks/Xamarin.Android.Common.targets +++ b/src/Xamarin.Android.Build.Tasks/Xamarin.Android.Common.targets @@ -125,6 +125,9 @@ Copyright (C) 2011-2012 Xamarin. All rights reserved. ******************************************* --> + +