Skip to content

Commit 51151d7

Browse files
authored
[Xamarin.Android.Build.Tasks] Rethink default property values (#9155)
Context: 5d1ac0a Context: dotnet/android-tools@a6a23bb Context: https://learn.microsoft.com/en-us/visualstudio/mac/what-happened-to-vs-for-mac?view=vsmac-2022 Commit 5d1ac0a had a brilliant idea: > Of particular note is dotnet/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 0aede13 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
1 parent 6be8531 commit 51151d7

File tree

9 files changed

+40
-12
lines changed

9 files changed

+40
-12
lines changed

build-tools/scripts/Ndk.projitems.in

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
<Project DefaultTargets="Build" ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
33
<PropertyGroup>
44
<AndroidNdkVersion Condition=" '$(AndroidNdkVersion)' == '' ">@NDK_RELEASE@</AndroidNdkVersion>
5+
<AndroidNdkPkgRevision Condition=" '$(AndroidNdkPkgRevision)' == '' ">@NDK_PKG_REVISION@</AndroidNdkPkgRevision>
56
<AndroidNdkApiLevel_ArmV7a Condition=" '$(AndroidNdkApiLevel_ArmV7a)' == '' ">@NDK_ARMEABI_V7_API@</AndroidNdkApiLevel_ArmV7a>
67
<AndroidNdkApiLevel_Arm Condition=" '$(AndroidNdkApiLevel_Arm)' == '' ">@NDK_ARMEABI_V7_API_NET@</AndroidNdkApiLevel_Arm>
78
<AndroidNdkApiLevel_ArmV8a Condition=" '$(AndroidNdkApiLevel_ArmV8a)' == '' ">@NDK_ARM64_V8A_API@</AndroidNdkApiLevel_ArmV8a>

build-tools/scripts/XABuildConfig.cs.in

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ namespace Xamarin.Android.Tools
1111
public const string XamarinAndroidVersion = "@XAMARIN_ANDROID_VERSION@";
1212
public const string XamarinAndroidCommitHash = "@XAMARIN_ANDROID_COMMIT_HASH@";
1313
public const string XamarinAndroidBranch = "@XAMARIN_ANDROID_BRANCH@";
14+
public const string AndroidSdkBuildToolsVersion = "@SDK_BUILD_TOOLS_VERSION@";
1415
public const int AndroidMinimumDotNetApiLevel = @ANDROID_DEFAULT_MINIMUM_DOTNET_API_LEVEL@;
1516
public const int AndroidLatestStableApiLevel = @ANDROID_LATEST_STABLE_API_LEVEL@;
1617
public const int AndroidLatestUnstableApiLevel = @ANDROID_LATEST_UNSTABLE_API_LEVEL@;

build-tools/xaprepare/xaprepare/ConfigAndData/Configurables.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,9 @@ partial class Configurables
1717
{
1818
const string BinutilsVersion = "L_18.1.6-8.0.0";
1919

20-
const string MicrosoftOpenJDK17Version = "17.0.11";
21-
const string MicrosoftOpenJDK17Release = "17.0.11.9";
22-
const string MicrosoftOpenJDK17RootDirName = "jdk-17.0.11+9";
20+
const string MicrosoftOpenJDK17Version = "17.0.8";
21+
const string MicrosoftOpenJDK17Release = "17.0.8.7";
22+
const string MicrosoftOpenJDK17RootDirName = "jdk-17.0.8+7";
2323

2424
static Context ctx => Context.Instance;
2525

build-tools/xaprepare/xaprepare/Resources/Configuration.OperatingSystem.props.in

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
<HostOsRelease Condition=" '$(HostOsRelease)' == '' ">@OS_RELEASE@</HostOsRelease>
77
<HostCpuCount Condition=" '$(HostCpuCount)' == '' ">@HOST_CPUS@</HostCpuCount>
88
<HostBits Condition=" '$(HostBits)' == '' ">@ARCHITECTURE_BITS@</HostBits>
9+
<JavaSdkVersion>@JAVA_SDK_VERSION@</JavaSdkVersion>
910
<JavaSdkDirectory Condition=" '$(JavaSdkDirectory)' == '' ">@JavaSdkDirectory@</JavaSdkDirectory>
1011
<JavaCPath Condition=" '$(JavaCPath)' == '' ">@javac@</JavaCPath>
1112
<JarPath Condition=" '$(JarPath)' == '' ">@jar@</JarPath>

build-tools/xaprepare/xaprepare/Steps/Step_GenerateFiles.cs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -156,6 +156,7 @@ GeneratedFile Get_Configuration_OperatingSystem_props (Context context)
156156
{ "@OS_RELEASE@", context.OS.Release ?? String.Empty },
157157
{ "@HOST_CPUS@", context.OS.CPUCount.ToString () },
158158
{ "@ARCHITECTURE_BITS@", context.OS.Is64Bit ? "64" : "32" },
159+
{ "@JAVA_SDK_VERSION@", Configurables.Defaults.MicrosoftOpenJDK17Version.ToString () },
159160
{ "@JavaSdkDirectory@", context.OS.JavaHome },
160161
{ "@javac@", context.OS.JavaCPath },
161162
{ "@java@", context.OS.JavaPath },
@@ -185,6 +186,7 @@ GeneratedFile Get_XABuildConfig_cs (Context context)
185186
{ "@NDK_X86_API@", BuildAndroidPlatforms.NdkMinimumAPILegacy32.ToString ().ToString () },
186187
{ "@NDK_X86_64_API@", BuildAndroidPlatforms.NdkMinimumAPI.ToString ().ToString () },
187188
{ "@XA_SUPPORTED_ABIS@", context.Properties.GetRequiredValue (KnownProperties.AndroidSupportedTargetJitAbis).Replace (':', ';') },
189+
{ "@SDK_BUILD_TOOLS_VERSION@", context.Properties.GetRequiredValue (KnownProperties.XABuildToolsFolder) },
188190
{ "@ANDROID_DEFAULT_MINIMUM_DOTNET_API_LEVEL@", context.Properties.GetRequiredValue (KnownProperties.AndroidMinimumDotNetApiLevel) },
189191
{ "@ANDROID_DEFAULT_TARGET_DOTNET_API_LEVEL@", context.Properties.GetRequiredValue (KnownProperties.AndroidDefaultTargetDotnetApiLevel) },
190192
{ "@ANDROID_LATEST_STABLE_API_LEVEL@", context.Properties.GetRequiredValue (KnownProperties.AndroidLatestStableApiLevel) },
@@ -207,6 +209,7 @@ GeneratedFile Get_Ndk_projitems (Context context)
207209

208210
var replacements = new Dictionary<string, string> (StringComparer.Ordinal) {
209211
{ "@NDK_RELEASE@", BuildAndroidPlatforms.AndroidNdkVersion },
212+
{ "@NDK_PKG_REVISION@", BuildAndroidPlatforms.AndroidNdkPkgRevision },
210213
{ "@NDK_ARMEABI_V7_API@", BuildAndroidPlatforms.NdkMinimumAPILegacy32.ToString () },
211214
{ "@NDK_ARMEABI_V7_API_NET@", BuildAndroidPlatforms.NdkMinimumAPI.ToString () },
212215
{ "@NDK_ARM64_V8A_API@", BuildAndroidPlatforms.NdkMinimumAPI.ToString () },

src/Xamarin.Android.Build.Tasks/Tests/Xamarin.Android.Build.Tests/AndroidDependenciesTests.cs

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -217,12 +217,7 @@ public void GetDependencyWhenSDKIsMissingTest ([Values (true, false)] bool creat
217217

218218
static string GetExpectedBuildToolsVersion ()
219219
{
220-
var propsPath = Path.Combine (XABuildPaths.TopDirectory, "src", "Xamarin.Android.Build.Tasks", "Xamarin.Android.Common.props.in");
221-
var props = XElement.Load (propsPath);
222-
var AndroidSdkBuildToolsVersion = props.Elements (MSBuildXmlns + "PropertyGroup")
223-
.Elements (MSBuildXmlns + "AndroidSdkBuildToolsVersion")
224-
.FirstOrDefault ();
225-
return AndroidSdkBuildToolsVersion?.Value?.Trim ();
220+
return XABuildConfig.AndroidSdkBuildToolsVersion;
226221
}
227222
}
228223
}

src/Xamarin.Android.Build.Tasks/Xamarin.Android.Build.Tasks.targets

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -196,10 +196,26 @@
196196
DestinationFile="Xamarin.Android.BuildInfo.txt"
197197
Replacements="@JAVA_INTEROP_COMMIT@=$(_BuildInfo_JavaInteropCommit);@SQLITE_COMMIT@=$(_BuildInfo_SqliteCommit);@XAMARIN_ANDROID_TOOLS_COMMIT@=$(_BuildInfo_XamarinAndroidToolsCommit);">
198198
</ReplaceFileContents>
199+
<ItemGroup>
200+
<_XACommonPropsReplacement Include="@COMMAND_LINE_TOOLS_VERSION@=$(CommandLineToolsFolder)" />
201+
<_XACommonPropsReplacement Include="@BUNDLETOOL_VERSION@=$(XABundleToolVersion)" />
202+
<_XACommonPropsReplacement Include="@JAVA_SDK_VERSION@=$(JavaSdkVersion)" />
203+
<!-- <_XACommonPropsReplacement Include="@NDK_PKG_REVISION@=$(AndroidNdkPkgRevision)" /> -->
204+
<_XACommonPropsReplacement Include="@NDK_PKG_REVISION@=26.3.11579264" />
205+
<_XACommonPropsReplacement Include="@NDK_ARM64_V8A_API@=$(AndroidNdkApiLevel_ArmV8a)" />
206+
<_XACommonPropsReplacement Include="@NDK_ARMEABI_V7_API@=$(AndroidNdkApiLevel_ArmV7a)" />
207+
<_XACommonPropsReplacement Include="@NDK_X86_64_API@=$(AndroidNdkApiLevel_X86_64)" />
208+
<_XACommonPropsReplacement Include="@NDK_X86_API@=$(AndroidNdkApiLevel_X86)" />
209+
<_XACommonPropsReplacement Include="@PACKAGE_VERSION_BUILD@=$(XAVersionCommitCount)" />
210+
<_XACommonPropsReplacement Include="@PACKAGE_VERSION@=$(ProductVersion)" />
211+
<_XACommonPropsReplacement Include="@SDK_BUILD_TOOLS_VERSION@=$(XABuildToolsFolder)" />
212+
<_XACommonPropsReplacement Include="@SDK_PLATFORM_TOOLS_VERSION@=$(XAPlatformToolsVersion)" />
213+
<_XACommonPropsReplacement Include="@SDK_PLATFORM_VERSION@=android-$(AndroidLatestStableApiLevel)" />
214+
</ItemGroup>
199215
<ReplaceFileContents
200216
SourceFile="Xamarin.Android.Common.props.in"
201217
DestinationFile="Xamarin.Android.Common.props"
202-
Replacements="@PACKAGE_VERSION@=$(ProductVersion);@PACKAGE_VERSION_BUILD@=$(XAVersionCommitCount);@NDK_ARMEABI_V7_API@=$(AndroidNdkApiLevel_ArmV7a);@NDK_ARM64_V8A_API@=$(AndroidNdkApiLevel_ArmV8a);@NDK_X86_API@=$(AndroidNdkApiLevel_X86);@NDK_X86_64_API@=$(AndroidNdkApiLevel_X86_64);@BUNDLETOOL_VERSION@=$(XABundleToolVersion)">
218+
Replacements="@(_XACommonPropsReplacement)">
203219
</ReplaceFileContents>
204220
</Target>
205221
<Target Name="_GenerateSupportedPlatforms"

src/Xamarin.Android.Build.Tasks/Xamarin.Android.Common.props.in

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,14 @@
11
<Project xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
2-
<!-- Android Sdk Tool versions are sourced from this file. This is maintained in the android-tools repo. -->
3-
<Import Project="$(MSBuildThisFileDirectory)\Xamarin.Android.Tools.Versions.props" />
2+
<PropertyGroup>
3+
<AndroidSdkBuildToolsVersion Condition=" '$(AndroidSdkBuildToolsVersion)' == '' ">@SDK_BUILD_TOOLS_VERSION@</AndroidSdkBuildToolsVersion>
4+
<AndroidSdkPlatformToolsVersion Condition="'$(AndroidSdkPlatformToolsVersion)' == ''">@SDK_PLATFORM_TOOLS_VERSION@</AndroidSdkPlatformToolsVersion>
5+
<AndroidSdkPlatformVersion Condition=" '$(AndroidSdkPlatformVersion)' == '' ">@SDK_PLATFORM_VERSION@</AndroidSdkPlatformVersion>
6+
7+
<AndroidCommandLineToolsVersion Condition=" '$(AndroidCommandLineToolsVersion)' == '' ">@COMMAND_LINE_TOOLS_VERSION@</AndroidCommandLineToolsVersion>
8+
<AndroidSdkEmulatorVersion Condition="'$(AndroidSdkEmulatorVersion)' == ''"></AndroidSdkEmulatorVersion>
9+
<AndroidNdkVersion Condition="'$(AndroidNdkVersion)' == ''">@NDK_PKG_REVISION@</AndroidNdkVersion>
10+
<JavaSdkVersion Condition="'$(JavaSdkVersion)' == ''">@JAVA_SDK_VERSION@</JavaSdkVersion>
11+
</PropertyGroup>
412
<PropertyGroup>
513
<_JavaInteropReferences>Java.Interop;System.Runtime</_JavaInteropReferences>
614
<Debugger Condition=" '$(Debugger)' == '' ">Xamarin</Debugger>

src/Xamarin.Android.Build.Tasks/Xamarin.Android.Common.targets

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -125,6 +125,9 @@ Copyright (C) 2011-2012 Xamarin. All rights reserved.
125125
*******************************************
126126
-->
127127

128+
<Import Project="$(MSBuildThisFileDirectory)Xamarin.Installer.Common.props"
129+
Condition="Exists('$(MSBuildThisFileDirectory)Xamarin.Installer.Common.props')"/>
130+
128131
<Import Project="$(MSBuildThisFileDirectory)Xamarin.Android.Common.props"
129132
Condition="Exists('$(MSBuildThisFileDirectory)Xamarin.Android.Common.props')" />
130133

0 commit comments

Comments
 (0)