Skip to content

Commit 0ab3db0

Browse files
authored
[One .NET] Fix targeting API 33, build API 31 ref pack (#6896)
Fixes: #6914 The Microsoft.Android `@(KnownFrameworkReference)` will now declare targeting and runtime pack metadata that is based on the `$(TargetPlatformVersion)` of the project file. The only exception to this rule is when '$(TargetPlatformVersion)' == '31.0'; in this case the project will use an API 31 ref pack with API 32 runtime packs. The inline `Microsoft.Android.Sdk.BundledVersions.targets` file content has been moved into a separate file to improve the readability of the `@(KnownFrameworkReference)` element. Breakdown of supported `$(TargetFramework)` -> ref/runtime pack used: | `$(TargetFramework)` | Targeting Pack | Runtime Pack | | -------------------- | -------------- | ------------ | | net6.0-android | Microsoft.Android.Ref.31 | Microsoft.Android.Runtime.32 | | net6.0-android31.0 | Microsoft.Android.Ref.31 | Microsoft.Android.Runtime.32 | | net6.0-android32.0 | Microsoft.Android.Ref.32 | Microsoft.Android.Runtime.32 | | net6.0-android33.0 | Microsoft.Android.Ref.33 | Microsoft.Android.Runtime.33 | Tests have been updated accordingly, and they will now use a dynamic test case source that should make sure we don't miss any coverage when making future updates to `$(AndroidDefaultTargetDotnetApiLevel)`, `$(AndroidLatestStableApiLevel)`, and `$(AndroidLatestUnstableApiLevel)`. If an unsupported `$(TargetFramework)` is used in a project file the following errors will now be displayed: "test.csproj" (_GenerateRestoreGraphProjectEntry target) (1:5) -> (ProcessFrameworkReferences target) -> C:\Program Files\dotnet\sdk\6.0.300-preview.22211.2\Sdks\Microsoft.NET.Sdk\targets\Microsoft.NET.Sdk.FrameworkReferenceResolution.targets(90,5): error : NETSDKZZZZ: Error getting pack version: Pack 'Microsoft.Android.Ref.25' was not present in workload manifests. C:\Program Files\dotnet\sdk\6.0.300-preview.22211.2\Sdks\Microsoft.NET.Sdk\targets\Microsoft.NET.Sdk.FrameworkReferenceResolution.targets(90,5): error : NETSDKZZZZ: Error getting pack version: Pack 'Microsoft.Android.Runtime.25.android-arm' was not present in workload manifests. C:\Program Files\dotnet\sdk\6.0.300-preview.22211.2\Sdks\Microsoft.NET.Sdk\targets\Microsoft.NET.Sdk.FrameworkReferenceResolution.targets(90,5): error : NETSDKZZZZ: Error getting pack version: Pack 'Microsoft.Android.Runtime.25.android-arm64' was not present in workload manifests. C:\Program Files\dotnet\sdk\6.0.300-preview.22211.2\Sdks\Microsoft.NET.Sdk\targets\Microsoft.NET.Sdk.FrameworkReferenceResolution.targets(90,5): error : NETSDKZZZZ: Error getting pack version: Pack 'Microsoft.Android.Runtime.25.android-x86' was not present in workload manifests. C:\Program Files\dotnet\sdk\6.0.300-preview.22211.2\Sdks\Microsoft.NET.Sdk\targets\Microsoft.NET.Sdk.FrameworkReferenceResolution.targets(90,5): error : NETSDKZZZZ: Error getting pack version: Pack 'Microsoft.Android.Runtime.25.android-x64' was not present in workload manifests. Additionally, the build has been updated to produce a reference pack for the API level declared in `$(AndroidDefaultTargetDotnetApiLevel)`, if it is not the same as `$(AndroidLatestStableApiLevel)`. This will allow the default `net6.0-android` target framework to use an up to date Mono.Android.dll, instead of an older preview version from NuGet.org.
1 parent b5053d7 commit 0ab3db0

File tree

13 files changed

+149
-83
lines changed

13 files changed

+149
-83
lines changed

build-tools/automation/yaml-templates/setup-test-environment.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ steps:
5656

5757
- template: run-xaprepare.yaml
5858
parameters:
59-
arguments: --s=AndroidTestDependencies --android-sdk-platforms="19,21,26,32"
59+
arguments: --s=AndroidTestDependencies --android-sdk-platforms="19,21,26,32,Tiramisu"
6060
xaSourcePath: ${{ parameters.xaSourcePath }}
6161

6262
- task: DotNetCoreCLI@2

build-tools/create-packs/Directory.Build.targets

Lines changed: 16 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,11 @@
5656
<RemoveDir Directories="$(XamarinAndroidSourcePath)bin\Build$(Configuration)\nuget-unsigned" />
5757
</Target>
5858

59+
<Target Name="_CreateDefaultRefPack"
60+
Condition=" '$(AndroidLatestStableApiLevel)' != '$(AndroidDefaultTargetDotnetApiLevel)' and Exists('$(XAInstallPrefix)xbuild-frameworks\Microsoft.Android\net6.0-android$(AndroidDefaultTargetDotnetApiLevel)\Mono.Android.dll') ">
61+
<Exec Command="dotnet pack @(_GlobalProperties, ' ') -p:AndroidApiLevel=$(AndroidDefaultTargetDotnetApiLevel) &quot;$(MSBuildThisFileDirectory)Microsoft.Android.Ref.proj&quot;" />
62+
</Target>
63+
5964
<Target Name="_CreatePreviewPacks"
6065
Condition=" '$(AndroidLatestStableApiLevel)' != '$(AndroidLatestUnstableApiLevel)' and Exists('$(XAInstallPrefix)xbuild-frameworks\Microsoft.Android\net6.0-android$(AndroidLatestUnstableApiLevel)\Mono.Android.dll') ">
6166
<Exec Command="dotnet pack @(_GlobalProperties, ' ') -p:AndroidApiLevel=$(AndroidLatestUnstableApiLevel) -p:AndroidRID=android-arm -p:AndroidABI=armeabi-v7a-net6 &quot;$(MSBuildThisFileDirectory)Microsoft.Android.Runtime.proj&quot;" />
@@ -66,7 +71,7 @@
6671
</Target>
6772

6873
<Target Name="CreateAllPacks"
69-
DependsOnTargets="DeleteExtractedWorkloadPacks;_SetGlobalProperties;GetXAVersionInfo;_CleanNuGetDirectory;_CreatePreviewPacks">
74+
DependsOnTargets="DeleteExtractedWorkloadPacks;_SetGlobalProperties;GetXAVersionInfo;_CleanNuGetDirectory;_CreatePreviewPacks;_CreateDefaultRefPack">
7075
<Exec Command="dotnet pack @(_GlobalProperties, ' ') -p:AndroidRID=android-arm -p:AndroidABI=armeabi-v7a-net6 &quot;$(MSBuildThisFileDirectory)Microsoft.Android.Runtime.proj&quot;" />
7176
<Exec Command="dotnet pack @(_GlobalProperties, ' ') -p:AndroidRID=android-arm64 -p:AndroidABI=arm64-v8a-net6 &quot;$(MSBuildThisFileDirectory)Microsoft.Android.Runtime.proj&quot;" />
7277
<Exec Command="dotnet pack @(_GlobalProperties, ' ') -p:AndroidRID=android-x86 -p:AndroidABI=x86-net6 &quot;$(MSBuildThisFileDirectory)Microsoft.Android.Runtime.proj&quot;" />
@@ -136,15 +141,20 @@
136141
</Target>
137142

138143
<Target Name="DeleteExtractedWorkloadPacks" >
144+
<ItemGroup>
145+
<_PackApiLevels Include="$(AndroidDefaultTargetDotnetApiLevel)" />
146+
<_PackApiLevels Include="$(AndroidLatestStableApiLevel)" />
147+
<_PackApiLevels Include="$(AndroidLatestUnstableApiLevel)" />
148+
</ItemGroup>
139149
<ItemGroup>
140150
<_PackFoldersToDelete Include="$(DotNetPreviewPath)metadata" />
141151
<_PackFoldersToDelete Include="$(DotNetPreviewPath)sdk-manifests\$(DotNetPreviewVersionBand)\microsoft.net.sdk.android" />
142152
<_PackFoldersToDelete Include="$(DotNetPreviewPath)sdk-manifests\$(DotNetPreviewVersionBand)\microsoft.net.workload.android" />
143-
<_PackFoldersToDelete Include="$(DotNetPreviewPath)packs\Microsoft.Android.Ref" />
144-
<_PackFoldersToDelete Include="$(DotNetPreviewPath)packs\Microsoft.Android.Runtime.android-arm" />
145-
<_PackFoldersToDelete Include="$(DotNetPreviewPath)packs\Microsoft.Android.Runtime.android-arm64" />
146-
<_PackFoldersToDelete Include="$(DotNetPreviewPath)packs\Microsoft.Android.Runtime.android-x86" />
147-
<_PackFoldersToDelete Include="$(DotNetPreviewPath)packs\Microsoft.Android.Runtime.android-x64" />
153+
<_PackFoldersToDelete Include="$(DotNetPreviewPath)packs\Microsoft.Android.Ref.%(_PackApiLevels.Identity)" />
154+
<_PackFoldersToDelete Include="$(DotNetPreviewPath)packs\Microsoft.Android.Runtime.%(_PackApiLevels.Identity).android-arm" />
155+
<_PackFoldersToDelete Include="$(DotNetPreviewPath)packs\Microsoft.Android.Runtime.%(_PackApiLevels.Identity).android-arm64" />
156+
<_PackFoldersToDelete Include="$(DotNetPreviewPath)packs\Microsoft.Android.Runtime.%(_PackApiLevels.Identity).android-x86" />
157+
<_PackFoldersToDelete Include="$(DotNetPreviewPath)packs\Microsoft.Android.Runtime.%(_PackApiLevels.Identity).android-x64" />
148158
<_PackFoldersToDelete Include="$(DotNetPreviewPath)packs\Microsoft.Android.Sdk.Darwin" />
149159
<_PackFoldersToDelete Include="$(DotNetPreviewPath)packs\Microsoft.Android.Sdk.Linux" />
150160
<_PackFoldersToDelete Include="$(DotNetPreviewPath)packs\Microsoft.Android.Sdk.Windows" />

build-tools/create-packs/Microsoft.Android.Sdk.proj

Lines changed: 5 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -102,57 +102,11 @@ core workload SDK packs imported by WorkloadManifest.targets.
102102
<BundledVersionsFileName>Microsoft.Android.Sdk.BundledVersions.targets</BundledVersionsFileName>
103103
</PropertyGroup>
104104

105-
<ItemGroup>
106-
<_AndroidNETAppRuntimePackRids Include="android-arm;android-arm64;android-x86;android-x64" />
107-
</ItemGroup>
108-
109-
<PropertyGroup>
110-
<BundledVersionsContent>
111-
<![CDATA[
112-
<!--
113-
***********************************************************************************************
114-
$(BundledVersionsFileName)
115-
WARNING: DO NOT MODIFY this file unless you are knowledgeable about MSBuild and have
116-
created a backup copy. Incorrect changes to this file will make it
117-
impossible to load or build your projects from the command-line or the IDE.
118-
***********************************************************************************************
119-
-->
120-
<Project>
121-
<PropertyGroup>
122-
<AndroidNETSdkVersion>$(AndroidPackVersionLong)</AndroidNETSdkVersion>
123-
<XamarinAndroidVersion>$(AndroidPackVersionLong)</XamarinAndroidVersion>
124-
</PropertyGroup>
125-
<PropertyGroup Condition=" '%24(TargetPlatformVersion)' == '31.0' ">
126-
<_AndroidTargetingPackId>31</_AndroidTargetingPackId>
127-
<_AndroidTargetingPackVersion>31.0.101-preview.11.117</_AndroidTargetingPackVersion>
128-
</PropertyGroup>
129-
<PropertyGroup>
130-
<_AndroidTargetingPackId Condition=" '%24(_AndroidTargetingPackId)' == '' ">$(AndroidLatestStableApiLevel)</_AndroidTargetingPackId>
131-
<_AndroidTargetingPackVersion Condition=" '%24(_AndroidTargetingPackVersion)' == '' ">**FromWorkload**</_AndroidTargetingPackVersion>
132-
<_AndroidRuntimePackId Condition=" '%24(_AndroidRuntimePackId)' == '' ">$(AndroidLatestStableApiLevel)</_AndroidRuntimePackId>
133-
<_AndroidRuntimePackVersion Condition=" '%24(_AndroidRuntimePackVersion)' == '' ">**FromWorkload**</_AndroidRuntimePackVersion>
134-
</PropertyGroup>
135-
<ItemGroup>
136-
<KnownFrameworkReference
137-
Include="Microsoft.Android"
138-
TargetFramework="$(_AndroidNETAppTargetFramework)"
139-
RuntimeFrameworkName="Microsoft.Android"
140-
LatestRuntimeFrameworkVersion="%24(_AndroidRuntimePackVersion)"
141-
TargetingPackName="Microsoft.Android.Ref.%24(_AndroidTargetingPackId)"
142-
TargetingPackVersion="%24(_AndroidTargetingPackVersion)"
143-
RuntimePackNamePatterns="Microsoft.Android.Runtime.%24(_AndroidRuntimePackId).**RID**"
144-
RuntimePackRuntimeIdentifiers="@(_AndroidNETAppRuntimePackRids, '%3B')"
145-
Profile="Android"
146-
/>
147-
</ItemGroup>
148-
</Project>
149-
]]>
150-
</BundledVersionsContent>
151-
</PropertyGroup>
152-
153-
<WriteLinesToFile File="$(XamarinAndroidSourcePath)src\Xamarin.Android.Build.Tasks\Microsoft.Android.Sdk\targets\$(BundledVersionsFileName)"
154-
Lines="$(BundledVersionsContent)"
155-
Overwrite="true" />
105+
<ReplaceFileContents
106+
SourceFile="$(XamarinAndroidSourcePath)src\Xamarin.Android.Build.Tasks\Microsoft.Android.Sdk\in\Microsoft.Android.Sdk.BundledVersions.in.targets"
107+
DestinationFile="$(XamarinAndroidSourcePath)src\Xamarin.Android.Build.Tasks\Microsoft.Android.Sdk\targets\$(BundledVersionsFileName)"
108+
Replacements="@ANDROID_PACK_VERSION_LONG@=$(AndroidPackVersionLong);@ANDROID_LATEST_STABLE_API_LEVEL@=$(AndroidLatestStableApiLevel)" >
109+
</ReplaceFileContents>
156110
</Target>
157111

158112
</Project>

build-tools/scripts/DotNet.targets

Lines changed: 10 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,16 @@
55
<Target Name="PackDotNet">
66
<MSBuild Projects="$(_Root)build-tools\xa-prep-tasks\xa-prep-tasks.csproj" />
77
<MSBuild Projects="$(_Root)Xamarin.Android.sln" Properties="DisableApiCompatibilityCheck=true" />
8+
<MSBuild
9+
Condition=" '$(AndroidDefaultTargetDotnetApiLevel)' != '$(AndroidLatestStableApiLevel)' "
10+
Projects="$(_Root)src\Mono.Android\Mono.Android.csproj"
11+
Properties="TargetFramework=net6.0;AndroidApiLevel=$(AndroidDefaultTargetDotnetApiLevel);AndroidPlatformId=$(AndroidDefaultTargetDotnetApiLevel);DisableApiCompatibilityCheck=true"
12+
/>
13+
<MSBuild
14+
Condition=" '$(AndroidLatestUnstableApiLevel)' != '$(AndroidLatestStableApiLevel)' "
15+
Projects="$(_Root)src\Mono.Android\Mono.Android.csproj"
16+
Properties="TargetFramework=net6.0;AndroidApiLevel=$(AndroidLatestUnstableApiLevel);AndroidPlatformId=$(AndroidLatestUnstablePlatformId);DisableApiCompatibilityCheck=true"
17+
/>
818
<MSBuild Projects="$(_Root)build-tools\create-packs\Microsoft.Android.Sdk.proj" Targets="CreateAllPacks" />
919
<MSBuild Projects="$(_Root)build-tools\create-packs\Microsoft.Android.Sdk.proj" Targets="ExtractWorkloadPacks" />
1020
<!-- Clean up old, previously restored packages -->
@@ -47,17 +57,4 @@
4757
/>
4858
<RemoveDir Directories="$(_TempDirectory)" />
4959
</Target>
50-
<Target Name="BuildDotNetPreviewApiLevel">
51-
<ItemGroup>
52-
<_DotNetPreviewProperties Include="TargetFramework=net6.0" />
53-
<_DotNetPreviewProperties Include="AndroidApiLevel=$(AndroidLatestUnstableApiLevel)" />
54-
<_DotNetPreviewProperties Include="AndroidPlatformId=$(AndroidLatestUnstablePlatformId)" />
55-
<_DotNetPreviewProperties Include="AndroidFrameworkVersion=$(AndroidLatestUnstableFrameworkVersion)" />
56-
<_DotNetPreviewProperties Include="AndroidPreviousFrameworkVersion=$(AndroidLatestStableFrameworkVersion)" />
57-
</ItemGroup>
58-
<MSBuild
59-
Projects="$(XamarinAndroidSourcePath)src\Mono.Android\Mono.Android.csproj"
60-
Properties="@(_DotNetPreviewProperties)"
61-
/>
62-
</Target>
6360
</Project>

build-tools/scripts/XABuildConfig.cs.in

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ namespace Xamarin.Android.Tools
1313
public const string XamarinAndroidBranch = "@XAMARIN_ANDROID_BRANCH@";
1414
public const int NDKMinimumApiAvailable = @NDK_MINIMUM_API_AVAILABLE@;
1515
public const int AndroidLatestStableApiLevel = @ANDROID_LATEST_STABLE_API_LEVEL@;
16+
public const int AndroidLatestUnstableApiLevel = @ANDROID_LATEST_UNSTABLE_API_LEVEL@;
1617
public const int AndroidDefaultTargetDotnetApiLevel = @ANDROID_DEFAULT_TARGET_DOTNET_API_LEVEL@;
1718
public static readonly Version NDKVersion = new Version (@NDK_VERSION_MAJOR@, @NDK_VERSION_MINOR@, @NDK_VERSION_MICRO@);
1819

build-tools/xaprepare/xaprepare/Application/KnownProperties.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ static class KnownProperties
77
public const string AndroidCmakeVersionPath = "AndroidCmakeVersionPath";
88
public const string AndroidDefaultTargetDotnetApiLevel = "AndroidDefaultTargetDotnetApiLevel";
99
public const string AndroidLatestStableApiLevel = "AndroidLatestStableApiLevel";
10+
public const string AndroidLatestUnstableApiLevel = "AndroidLatestUnstableApiLevel";
1011
public const string AndroidLatestStableFrameworkVersion = "AndroidLatestStableFrameworkVersion";
1112
public const string AndroidMxeFullPath = "AndroidMxeFullPath";
1213
public const string AndroidNdkDirectory = "AndroidNdkDirectory";

build-tools/xaprepare/xaprepare/Application/Properties.Defaults.cs.in

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ namespace Xamarin.Android.Prepare
1111
properties.Add (KnownProperties.AndroidCmakeVersionPath, StripQuotes (@"@AndroidCmakeVersionPath@"));
1212
properties.Add (KnownProperties.AndroidDefaultTargetDotnetApiLevel, StripQuotes ("@AndroidDefaultTargetDotnetApiLevel@"));
1313
properties.Add (KnownProperties.AndroidLatestStableApiLevel, StripQuotes ("@AndroidLatestStableApiLevel@"));
14+
properties.Add (KnownProperties.AndroidLatestUnstableApiLevel, StripQuotes ("@AndroidLatestUnstableApiLevel@"));
1415
properties.Add (KnownProperties.AndroidLatestStableFrameworkVersion, StripQuotes ("@AndroidLatestStableFrameworkVersion@"));
1516
properties.Add (KnownProperties.AndroidMxeFullPath, StripQuotes (@"@AndroidMxeFullPath@"));
1617
properties.Add (KnownProperties.AndroidNdkDirectory, StripQuotes (@"@AndroidNdkDirectory@"));

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -168,6 +168,7 @@ GeneratedFile Get_XABuildConfig_cs (Context context)
168168
{ "@XA_SUPPORTED_ABIS@", context.Properties.GetRequiredValue (KnownProperties.AndroidSupportedTargetJitAbis).Replace (':', ';') },
169169
{ "@ANDROID_DEFAULT_TARGET_DOTNET_API_LEVEL@", context.Properties.GetRequiredValue (KnownProperties.AndroidDefaultTargetDotnetApiLevel) },
170170
{ "@ANDROID_LATEST_STABLE_API_LEVEL@", context.Properties.GetRequiredValue (KnownProperties.AndroidLatestStableApiLevel) },
171+
{ "@ANDROID_LATEST_UNSTABLE_API_LEVEL@", context.Properties.GetRequiredValue (KnownProperties.AndroidLatestUnstableApiLevel) },
171172
{ "@XAMARIN_ANDROID_VERSION@", context.Properties.GetRequiredValue (KnownProperties.ProductVersion) },
172173
{ "@XAMARIN_ANDROID_COMMIT_HASH@", context.BuildInfo.XACommitHash },
173174
{ "@XAMARIN_ANDROID_BRANCH@", context.BuildInfo.XABranch },

build-tools/xaprepare/xaprepare/xaprepare.targets

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@
4545
<Replacement Include="@AndroidCmakeVersionPath@=$(AndroidCmakeVersionPath)" />
4646
<Replacement Include="@AndroidDefaultTargetDotnetApiLevel@=$(AndroidDefaultTargetDotnetApiLevel)" />
4747
<Replacement Include="@AndroidLatestStableApiLevel@=$(AndroidLatestStableApiLevel)" />
48+
<Replacement Include="@AndroidLatestUnstableApiLevel@=$(AndroidLatestUnstableApiLevel)" />
4849
<Replacement Include="@AndroidMxeFullPath@=$(AndroidMxeFullPath)" />
4950
<Replacement Include="@AndroidNdkDirectory@=$(AndroidNdkDirectory)" />
5051
<Replacement Include="@AndroidNdkVersion@=$(AndroidNdkVersion)" />

src/Mono.Android/Mono.Android.csproj

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -386,8 +386,8 @@
386386
<Target Name="GetTargetPath" />
387387

388388
<Import Project="Sdk.targets" Sdk="Microsoft.NET.Sdk" />
389-
<!-- Only build the 'net6.0' version of 'Mono.Android.dll' for the latest stable Android version or higher. -->
390-
<PropertyGroup Condition=" '$(TargetFramework)' != 'monoandroid10' And '$(AndroidApiLevel)' &lt; '$(AndroidLatestStableApiLevel)' ">
389+
<!-- Only build the 'net6.0' version of 'Mono.Android.dll' for the default API level that is supported or higher. -->
390+
<PropertyGroup Condition=" '$(TargetFramework)' != 'monoandroid10' And '$(AndroidApiLevel)' &lt; '$(AndroidDefaultTargetDotnetApiLevel)' ">
391391
<BuildDependsOn></BuildDependsOn>
392392
</PropertyGroup>
393393

0 commit comments

Comments
 (0)