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
…#9224)

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
  • Loading branch information
jonpryor authored Aug 21, 2024
1 parent 45af0b5 commit 8d7eda8
Show file tree
Hide file tree
Showing 8 changed files with 36 additions and 9 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 @@ -15,6 +15,7 @@
<HostCc64 Condition=" '$(HostCc64)' == '' ">@HOST_CC64@</HostCc64>
<HostCxx32 Condition=" '$(HostCxx32)' == '' ">@HOST_CXX32@</HostCxx32>
<HostCxx64 Condition=" '$(HostCxx64)' == '' ">@HOST_CXX64@</HostCxx64>
<JavaSdkVersion>@JAVA_SDK_VERSION@</JavaSdkVersion>
<JavaSdkDirectory Condition=" '$(JavaSdkDirectory)' == '' ">@JavaSdkDirectory@</JavaSdkDirectory>
<JavaCPath Condition=" '$(JavaCPath)' == '' ">@javac@</JavaCPath>
<JarPath Condition=" '$(JarPath)' == '' ">@jar@</JarPath>
Expand Down
2 changes: 2 additions & 0 deletions build-tools/xaprepare/xaprepare/Steps/Step_GenerateFiles.cs
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,7 @@ GeneratedFile Get_Configuration_OperatingSystem_props (Context context)
{ "@HOST_CXX32@", context.OS.CXX32 ?? String.Empty },
{ "@HOST_CXX64@", context.OS.CXX64 ?? String.Empty },
{ "@HOST_HOMEBREW_PREFIX@", context.OS.HomebrewPrefix ?? String.Empty },
{ "@JAVA_SDK_VERSION@", Configurables.Defaults.MicrosoftOpenJDK17Version.ToString () },
{ "@JavaSdkDirectory@", context.OS.JavaHome },
{ "@javac@", context.OS.JavaCPath },
{ "@java@", context.OS.JavaPath },
Expand Down Expand Up @@ -174,6 +175,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 Down
Original file line number Diff line number Diff line change
Expand Up @@ -194,12 +194,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 @@ -183,10 +183,26 @@
DestinationFile="Xamarin.Android.BuildInfo.txt"
Replacements="@MONO_COMMIT@=$(_BuildInfo_MonoCommit);@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 xamarin-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>
<XamarinAndroidVersion Condition=" '$(UsingAndroidNETSdk)' != 'true' ">@PACKAGE_VERSION@-@PACKAGE_VERSION_BUILD@</XamarinAndroidVersion>
<_JavaInteropReferences>Java.Interop;System.Runtime</_JavaInteropReferences>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,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 8d7eda8

Please sign in to comment.