Skip to content

Commit

Permalink
[Xamarin.Android.Build.Tasks] Rethink default property values (#9155)
Browse files Browse the repository at this point in the history
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
  • Loading branch information
jonpryor authored Aug 16, 2024
1 parent 6be8531 commit 51151d7
Show file tree
Hide file tree
Showing 9 changed files with 40 additions and 12 deletions.
1 change: 1 addition & 0 deletions build-tools/scripts/Ndk.projitems.in
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
<Project DefaultTargets="Build" ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup>
<AndroidNdkVersion Condition=" '$(AndroidNdkVersion)' == '' ">@NDK_RELEASE@</AndroidNdkVersion>
<AndroidNdkPkgRevision Condition=" '$(AndroidNdkPkgRevision)' == '' ">@NDK_PKG_REVISION@</AndroidNdkPkgRevision>
<AndroidNdkApiLevel_ArmV7a Condition=" '$(AndroidNdkApiLevel_ArmV7a)' == '' ">@NDK_ARMEABI_V7_API@</AndroidNdkApiLevel_ArmV7a>
<AndroidNdkApiLevel_Arm Condition=" '$(AndroidNdkApiLevel_Arm)' == '' ">@NDK_ARMEABI_V7_API_NET@</AndroidNdkApiLevel_Arm>
<AndroidNdkApiLevel_ArmV8a Condition=" '$(AndroidNdkApiLevel_ArmV8a)' == '' ">@NDK_ARM64_V8A_API@</AndroidNdkApiLevel_ArmV8a>
Expand Down
1 change: 1 addition & 0 deletions build-tools/scripts/XABuildConfig.cs.in
Original file line number Diff line number Diff line change
Expand Up @@ -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@;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
<HostOsRelease Condition=" '$(HostOsRelease)' == '' ">@OS_RELEASE@</HostOsRelease>
<HostCpuCount Condition=" '$(HostCpuCount)' == '' ">@HOST_CPUS@</HostCpuCount>
<HostBits Condition=" '$(HostBits)' == '' ">@ARCHITECTURE_BITS@</HostBits>
<JavaSdkVersion>@JAVA_SDK_VERSION@</JavaSdkVersion>
<JavaSdkDirectory Condition=" '$(JavaSdkDirectory)' == '' ">@JavaSdkDirectory@</JavaSdkDirectory>
<JavaCPath Condition=" '$(JavaCPath)' == '' ">@javac@</JavaCPath>
<JarPath Condition=" '$(JarPath)' == '' ">@jar@</JarPath>
Expand Down
3 changes: 3 additions & 0 deletions build-tools/xaprepare/xaprepare/Steps/Step_GenerateFiles.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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 },
Expand Down Expand Up @@ -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) },
Expand All @@ -207,6 +209,7 @@ GeneratedFile Get_Ndk_projitems (Context context)

var replacements = new Dictionary<string, string> (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 () },
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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);">
</ReplaceFileContents>
<ItemGroup>
<_XACommonPropsReplacement Include="@COMMAND_LINE_TOOLS_VERSION@=$(CommandLineToolsFolder)" />
<_XACommonPropsReplacement Include="@BUNDLETOOL_VERSION@=$(XABundleToolVersion)" />
<_XACommonPropsReplacement Include="@JAVA_SDK_VERSION@=$(JavaSdkVersion)" />
<!-- <_XACommonPropsReplacement Include="@NDK_PKG_REVISION@=$(AndroidNdkPkgRevision)" /> -->
<_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)" />
</ItemGroup>
<ReplaceFileContents
SourceFile="Xamarin.Android.Common.props.in"
DestinationFile="Xamarin.Android.Common.props"
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)">
Replacements="@(_XACommonPropsReplacement)">
</ReplaceFileContents>
</Target>
<Target Name="_GenerateSupportedPlatforms"
Expand Down
12 changes: 10 additions & 2 deletions src/Xamarin.Android.Build.Tasks/Xamarin.Android.Common.props.in
Original file line number Diff line number Diff line change
@@ -1,6 +1,14 @@
<Project xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<!-- Android Sdk Tool versions are sourced from this file. This is maintained in the android-tools repo. -->
<Import Project="$(MSBuildThisFileDirectory)\Xamarin.Android.Tools.Versions.props" />
<PropertyGroup>
<AndroidSdkBuildToolsVersion Condition=" '$(AndroidSdkBuildToolsVersion)' == '' ">@SDK_BUILD_TOOLS_VERSION@</AndroidSdkBuildToolsVersion>
<AndroidSdkPlatformToolsVersion Condition="'$(AndroidSdkPlatformToolsVersion)' == ''">@SDK_PLATFORM_TOOLS_VERSION@</AndroidSdkPlatformToolsVersion>
<AndroidSdkPlatformVersion Condition=" '$(AndroidSdkPlatformVersion)' == '' ">@SDK_PLATFORM_VERSION@</AndroidSdkPlatformVersion>

<AndroidCommandLineToolsVersion Condition=" '$(AndroidCommandLineToolsVersion)' == '' ">@COMMAND_LINE_TOOLS_VERSION@</AndroidCommandLineToolsVersion>
<AndroidSdkEmulatorVersion Condition="'$(AndroidSdkEmulatorVersion)' == ''"></AndroidSdkEmulatorVersion>
<AndroidNdkVersion Condition="'$(AndroidNdkVersion)' == ''">@NDK_PKG_REVISION@</AndroidNdkVersion>
<JavaSdkVersion Condition="'$(JavaSdkVersion)' == ''">@JAVA_SDK_VERSION@</JavaSdkVersion>
</PropertyGroup>
<PropertyGroup>
<_JavaInteropReferences>Java.Interop;System.Runtime</_JavaInteropReferences>
<Debugger Condition=" '$(Debugger)' == '' ">Xamarin</Debugger>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,9 @@ Copyright (C) 2011-2012 Xamarin. All rights reserved.
*******************************************
-->

<Import Project="$(MSBuildThisFileDirectory)Xamarin.Installer.Common.props"
Condition="Exists('$(MSBuildThisFileDirectory)Xamarin.Installer.Common.props')"/>

<Import Project="$(MSBuildThisFileDirectory)Xamarin.Android.Common.props"
Condition="Exists('$(MSBuildThisFileDirectory)Xamarin.Android.Common.props')" />

Expand Down

0 comments on commit 51151d7

Please sign in to comment.