Skip to content

Commit e78a54f

Browse files
committed
[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. Explicitly set `$(AndroidNdkVersion)`=26.3.11579264, as that's the latest version in the manifest. [0]: https://aka.ms/AndroidManifestFeed/d17-12
1 parent f393502 commit e78a54f

File tree

8 files changed

+36
-9
lines changed

8 files changed

+36
-9
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/Resources/Configuration.OperatingSystem.props.in

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
<HostCc64 Condition=" '$(HostCc64)' == '' ">@HOST_CC64@</HostCc64>
1616
<HostCxx32 Condition=" '$(HostCxx32)' == '' ">@HOST_CXX32@</HostCxx32>
1717
<HostCxx64 Condition=" '$(HostCxx64)' == '' ">@HOST_CXX64@</HostCxx64>
18+
<JavaSdkVersion>@JAVA_SDK_VERSION@</JavaSdkVersion>
1819
<JavaSdkDirectory Condition=" '$(JavaSdkDirectory)' == '' ">@JavaSdkDirectory@</JavaSdkDirectory>
1920
<JavaCPath Condition=" '$(JavaCPath)' == '' ">@javac@</JavaCPath>
2021
<JarPath Condition=" '$(JarPath)' == '' ">@jar@</JarPath>

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -145,6 +145,7 @@ GeneratedFile Get_Configuration_OperatingSystem_props (Context context)
145145
{ "@HOST_CXX32@", context.OS.CXX32 ?? String.Empty },
146146
{ "@HOST_CXX64@", context.OS.CXX64 ?? String.Empty },
147147
{ "@HOST_HOMEBREW_PREFIX@", context.OS.HomebrewPrefix ?? String.Empty },
148+
{ "@JAVA_SDK_VERSION@", Configurables.Defaults.MicrosoftOpenJDK17Version.ToString () },
148149
{ "@JavaSdkDirectory@", context.OS.JavaHome },
149150
{ "@javac@", context.OS.JavaCPath },
150151
{ "@java@", context.OS.JavaPath },
@@ -174,6 +175,7 @@ GeneratedFile Get_XABuildConfig_cs (Context context)
174175
{ "@NDK_X86_API@", BuildAndroidPlatforms.NdkMinimumAPILegacy32.ToString ().ToString () },
175176
{ "@NDK_X86_64_API@", BuildAndroidPlatforms.NdkMinimumAPI.ToString ().ToString () },
176177
{ "@XA_SUPPORTED_ABIS@", context.Properties.GetRequiredValue (KnownProperties.AndroidSupportedTargetJitAbis).Replace (':', ';') },
178+
{ "@SDK_BUILD_TOOLS_VERSION@", context.Properties.GetRequiredValue (KnownProperties.XABuildToolsFolder) },
177179
{ "@ANDROID_DEFAULT_MINIMUM_DOTNET_API_LEVEL@", context.Properties.GetRequiredValue (KnownProperties.AndroidMinimumDotNetApiLevel) },
178180
{ "@ANDROID_DEFAULT_TARGET_DOTNET_API_LEVEL@", context.Properties.GetRequiredValue (KnownProperties.AndroidDefaultTargetDotnetApiLevel) },
179181
{ "@ANDROID_LATEST_STABLE_API_LEVEL@", context.Properties.GetRequiredValue (KnownProperties.AndroidLatestStableApiLevel) },

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
@@ -194,12 +194,7 @@ public void GetDependencyWhenSDKIsMissingTest ([Values (true, false)] bool creat
194194

195195
static string GetExpectedBuildToolsVersion ()
196196
{
197-
var propsPath = Path.Combine (XABuildPaths.TopDirectory, "src", "Xamarin.Android.Build.Tasks", "Xamarin.Android.Common.props.in");
198-
var props = XElement.Load (propsPath);
199-
var AndroidSdkBuildToolsVersion = props.Elements (MSBuildXmlns + "PropertyGroup")
200-
.Elements (MSBuildXmlns + "AndroidSdkBuildToolsVersion")
201-
.FirstOrDefault ();
202-
return AndroidSdkBuildToolsVersion?.Value?.Trim ();
197+
return XABuildConfig.AndroidSdkBuildToolsVersion;
203198
}
204199
}
205200
}

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

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -183,10 +183,26 @@
183183
DestinationFile="Xamarin.Android.BuildInfo.txt"
184184
Replacements="@MONO_COMMIT@=$(_BuildInfo_MonoCommit);@JAVA_INTEROP_COMMIT@=$(_BuildInfo_JavaInteropCommit);@SQLITE_COMMIT@=$(_BuildInfo_SqliteCommit);@XAMARIN_ANDROID_TOOLS_COMMIT@=$(_BuildInfo_XamarinAndroidToolsCommit);">
185185
</ReplaceFileContents>
186+
<ItemGroup>
187+
<_XACommonPropsReplacement Include="@COMMAND_LINE_TOOLS_VERSION@=$(CommandLineToolsFolder)" />
188+
<_XACommonPropsReplacement Include="@BUNDLETOOL_VERSION@=$(XABundleToolVersion)" />
189+
<_XACommonPropsReplacement Include="@JAVA_SDK_VERSION@=$(JavaSdkVersion)" />
190+
<!-- <_XACommonPropsReplacement Include="@NDK_PKG_REVISION@=$(AndroidNdkPkgRevision)" /> -->
191+
<_XACommonPropsReplacement Include="@NDK_PKG_REVISION@=26.3.11579264" />
192+
<_XACommonPropsReplacement Include="@NDK_ARM64_V8A_API@=$(AndroidNdkApiLevel_ArmV8a)" />
193+
<_XACommonPropsReplacement Include="@NDK_ARMEABI_V7_API@=$(AndroidNdkApiLevel_ArmV7a)" />
194+
<_XACommonPropsReplacement Include="@NDK_X86_64_API@=$(AndroidNdkApiLevel_X86_64)" />
195+
<_XACommonPropsReplacement Include="@NDK_X86_API@=$(AndroidNdkApiLevel_X86)" />
196+
<_XACommonPropsReplacement Include="@PACKAGE_VERSION_BUILD@=$(XAVersionCommitCount)" />
197+
<_XACommonPropsReplacement Include="@PACKAGE_VERSION@=$(ProductVersion)" />
198+
<_XACommonPropsReplacement Include="@SDK_BUILD_TOOLS_VERSION@=$(XABuildToolsFolder)" />
199+
<_XACommonPropsReplacement Include="@SDK_PLATFORM_TOOLS_VERSION@=$(XAPlatformToolsVersion)" />
200+
<_XACommonPropsReplacement Include="@SDK_PLATFORM_VERSION@=android-$(AndroidLatestStableApiLevel)" />
201+
</ItemGroup>
186202
<ReplaceFileContents
187203
SourceFile="Xamarin.Android.Common.props.in"
188204
DestinationFile="Xamarin.Android.Common.props"
189-
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)">
205+
Replacements="@(_XACommonPropsReplacement)">
190206
</ReplaceFileContents>
191207
</Target>
192208
<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 xamarin-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
<XamarinAndroidVersion Condition=" '$(UsingAndroidNETSdk)' != 'true' ">@PACKAGE_VERSION@-@PACKAGE_VERSION_BUILD@</XamarinAndroidVersion>
614
<_JavaInteropReferences>Java.Interop;System.Runtime</_JavaInteropReferences>

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

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

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

0 commit comments

Comments
 (0)