Skip to content

Commit 941e04c

Browse files
authored
[XABT] Prefer SupportedOSPlatformVersion over minSdkVersion (#8026)
Fixes: #8040 I noticed that we were not writing a supported (by us) `//uses-sdk/@android:minSdkVersion` value to the generated `AndroidManifest.xml` file for projects which included a manifest that declared a `targetSdkVersion`. In these cases, we would always write a `//uses-sdk/@android:minSdkVersion` value of `19` to `AndroidManifest.xml`, as that was the minimum API level the Android NDK supported. (This was also a mistake, as *MonoVM* has API-21 as the minimum supported target. This mistake is corrected.) Fix this to always use the value of `$(SupportedOSPlatformVersion)` as the `minSdkVersion` attribute in the `AndroidManifest.xml` file. If this value is not explicitly set in the project file, it will now default to `$(AndroidMinimumSupportedApiLevel)` instead of `$(TargetPlatformVersion)`. The `XA4216` error/warning code has been expanded+repurposed. The warning that would display when the `minSdkVersion` attribute in `AndroidManifest.xml` was less than our minimum supported API level has been converted into an error: error XA4216: The deployment target '19' is not supported (the minimum is '21'). Please increase (or remove) the //uses-sdk/@android:minSdkVersion value in your project file. A similar error is now reported when `$(SupportedOSPlatformVersion)` is less than `$(AndroidMinimumSupportedApiLevel)` error XA4216: The deployment target '19' is not supported (the minimum is '21'). Please increase the $(SupportedOSPlatformVersion) property value in your project file. An error condition has been added for when `//uses-sdk/@android:minSdkVersion` in `AndroidManifest.xml` does not match `$(SupportedOSPlatformVersion)`: error XA1036: AndroidManifest.xml //uses-sdk/@android:minSdkVersion '19' does not match the $(SupportedOSPlatformVersion) value '21.0' in the project file (if there is no $(SupportedOSPlatformVersion) value in the project file, then a default value has been assumed). Either change the value in the AndroidManifest.xml to match the $(SupportedOSPlatformVersion) value, or remove the value in the AndroidManifest.xml (and add a $(SupportedOSPlatformVersion) value to the project file if it doesn't already exist). A few multidex related tests have been updated/removed as they are only valid with a `minSdkVersion` of 20 or lower.
1 parent 827318d commit 941e04c

34 files changed

+355
-204
lines changed

Configuration.props

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222
<TargetFrameworkVersion Condition=" '$(TargetFrameworkVersion)' == '' And '$(UsingMicrosoftNETSdk)' != 'true' And '$(_StandardLibraryPath)' != '' ">v4.7.2</TargetFrameworkVersion>
2323
<TargetFrameworkVersion Condition=" '$(TargetFrameworkVersion)' == '' And '$(UsingMicrosoftNETSdk)' != 'true' ">v4.7.1</TargetFrameworkVersion>
2424
<AndroidJavaRuntimeApiLevel Condition="'$(AndroidJavaRuntimeApiLevel)' == ''">26</AndroidJavaRuntimeApiLevel>
25-
<!-- The min API level supported by Microsoft.Android.Sdk, should refactor/remove when this value is the same as $(AndroidFirstApiLevel) -->
25+
<!-- The min API level supported by Microsoft.Android.Sdk -->
2626
<AndroidMinimumDotNetApiLevel Condition="'$(AndroidMinimumDotNetApiLevel)' == ''">21</AndroidMinimumDotNetApiLevel>
2727
<!-- *Latest* *stable* API level binding that we support; used when building src/Xamarin.Android.Build.Tasks -->
2828
<AndroidLatestStableApiLevel Condition="'$(AndroidLatestStableApiLevel)' == ''">33</AndroidLatestStableApiLevel>

Documentation/guides/messages/README.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -135,6 +135,8 @@ or 'Help->Report a Problem' in Visual Studio for Mac.
135135
+ [XA1032](xa1032.md):Failed to resolve '{0}' from '{1}'. Please check your `AndroidHttpClientHandlerType` setting.
136136
+ [XA1033](xa1033.md): Could not resolve '{0}'. Please check your `AndroidHttpClientHandlerType` setting.
137137
+ [XA1035](xa1035.md): The 'BundleAssemblies' property is deprecated and it has no effect on the application build. Equivalent functionality is implemented by the 'AndroidUseAssemblyStore' and 'AndroidEnableAssemblyCompression' properties.
138+
+ [XA1036](xa1036.md): AndroidManifest.xml //uses-sdk/@android:minSdkVersion '29' does not match the $(SupportedOSPlatformVersion) value '21' in the project file (if there is no $(SupportedOSPlatformVersion) value in the project file, then a default value has been assumed).
139+
Either change the value in the AndroidManifest.xml to match the $(SupportedOSPlatformVersion) value, or remove the value in the AndroidManifest.xml (and add a $(SupportedOSPlatformVersion) value to the project file if it doesn't already exist).
138140

139141
## XA2xxx: Linker
140142

@@ -163,7 +165,7 @@ or 'Help->Report a Problem' in Visual Studio for Mac.
163165
+ XA4213: The type '{type}' must provide a public default constructor
164166
+ [XA4214](xa4214.md): The managed type \`Library1.Class1\` exists in multiple assemblies: Library1, Library2. Please refactor the managed type names in these assemblies so that they are not identical.
165167
+ [XA4215](xa4215.md): The Java type \`com.contoso.library1.Class1\` is generated by more than one managed type. Please change the \[Register\] attribute so that the same Java type is not emitted.
166-
+ [XA4216](xa4216.md): AndroidManifest.xml //uses-sdk/@android:minSdkVersion '{min_sdk?.Value}' is less than API-{XABuildConfig.NDKMinimumApiAvailable}, this configuration is not supported.
168+
+ [XA4216](xa4216.md): The deployment target '19' is not supported (the minimum is '21'). Please increase the $(SupportedOSPlatformVersion) property value in your project file.
167169
+ XA4217: Cannot override Kotlin-generated method '{method}' because it is not a valid Java method name. This method can only be overridden from Kotlin.
168170
+ [XA4218](xa4218.md): Unable to find //manifest/application/uses-library at path: {path}
169171
+ XA4219: Cannot find binding generator for language {language} or {defaultLanguage}.
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
---
2+
title: Xamarin.Android error XA1036
3+
description: XA1036 error code
4+
ms.date: 5/22/2023
5+
---
6+
# Xamarin.Android error XA1036
7+
8+
## Example messages
9+
10+
```
11+
error XA1036: AndroidManifest.xml //uses-sdk/@android:minSdkVersion '29' does not match the $(SupportedOSPlatformVersion) value '21' in the project file (if there is no $(SupportedOSPlatformVersion) value in the project file, then a default value has been assumed).
12+
Either change the value in the AndroidManifest.xml to match the $(SupportedOSPlatformVersion) value, or remove the value in the AndroidManifest.xml (and add a $(SupportedOSPlatformVersion) value to the project file if it doesn't already exist).
13+
```
14+
15+
## Issue
16+
17+
This error indicates that you have a mismatch between the minSdkVersion
18+
element set in your AndroidManifest.xml and the $(SupportedOSPlatformVersion)
19+
property value in your project file.
20+
21+
22+
## Solution
23+
24+
Raise the value of `//uses-sdk/@android:minSdkVersion` in *AndroidManifest.xml*
25+
to match the $(SupportedOSPlatformVersion), or remove `//uses-sdk/@android:minSdkVersion`
26+
from *AndroidManifest.xml* and set $(SupportedOSPlatformVersion) in your project
27+
file if it is unset.
Lines changed: 25 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,39 @@
11
---
2-
title: Xamarin.Android warning XA4216
3-
description: XA4216 warning code
2+
title: Xamarin.Android error XA4216
3+
description: XA4216 error code
44
ms.date: 02/07/2019
55
---
6-
# Xamarin.Android warning XA4216
6+
# Xamarin.Android error XA4216
77

88
## Example messages
99

1010
```
11-
warning XA4216: AndroidManifest.xml //uses-sdk/@android:minSdkVersion '15' is less than API-16, this configuration is not supported.
11+
error XA4216: The deployment target '19' is not supported (the minimum is '21'). Please increase the $(SupportedOSPlatformVersion) property value in your project file.
12+
```
13+
14+
```
15+
error XA4216: The deployment target '19' is not supported (the minimum is '21'). Please increase (or remove) the //uses-sdk/@android:minSdkVersion value in your AndroidManifest.xml.
16+
```
17+
18+
```
19+
warning XA4216: AndroidManifest.xml //uses-sdk/@android:targetSdkVersion '19' is less than API-21, this configuration is not supported.
1220
```
1321

1422
## Issue
1523

16-
This warning indicates your application is targeting an API level that
17-
Xamarin.Android does not support.
24+
This error or warning indicates your application is targeting an unsupported API level.
1825

1926
## Solution
2027

21-
Raise the value of `//uses-sdk/@android:minSdkVersion` or
22-
`//uses-sdk/@android:targetSdkVersion` in *AndroidManifest.xml* to a
23-
higher API level that is supported.
28+
Edit your csproj and increase the '$(SupportedOSPlatformVersion)'
29+
property value to something greater than or equal to the minimum supported version.
30+
31+
or
32+
33+
Edit your AndroidManifest.xml and remove `//uses-sdk/@android:minSdkVersion`,
34+
or increase it to something greater than or equal to the minimum supported version.
35+
36+
or
37+
38+
Edit your AndroidManifest.xml and remove `//uses-sdk/@android:targetSdkVersion`,
39+
or increase it to something greater than or equal to the minimum supported version.

build-tools/scripts/NDKVersionInfo.targets

Lines changed: 0 additions & 15 deletions
This file was deleted.

build-tools/scripts/XABuildConfig.cs.in

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +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 int NDKMinimumApiAvailable = @NDK_MINIMUM_API_AVAILABLE@;
14+
public const int AndroidMinimumDotNetApiLevel = @ANDROID_DEFAULT_MINIMUM_DOTNET_API_LEVEL@;
1515
public const int AndroidLatestStableApiLevel = @ANDROID_LATEST_STABLE_API_LEVEL@;
1616
public const int AndroidLatestUnstableApiLevel = @ANDROID_LATEST_UNSTABLE_API_LEVEL@;
1717
public const int AndroidDefaultTargetDotnetApiLevel = @ANDROID_DEFAULT_TARGET_DOTNET_API_LEVEL@;

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ static class KnownProperties
55
public const string AndroidCmakeUrlPrefix = "AndroidCmakeUrlPrefix";
66
public const string AndroidCmakeVersion = "AndroidCmakeVersion";
77
public const string AndroidCmakeVersionPath = "AndroidCmakeVersionPath";
8+
public const string AndroidMinimumDotNetApiLevel = "AndroidMinimumDotNetApiLevel";
89
public const string AndroidDefaultTargetDotnetApiLevel = "AndroidDefaultTargetDotnetApiLevel";
910
public const string AndroidLatestStableApiLevel = "AndroidLatestStableApiLevel";
1011
public const string AndroidLatestUnstableApiLevel = "AndroidLatestUnstableApiLevel";

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ namespace Xamarin.Android.Prepare
99
properties.Add (KnownProperties.AndroidCmakeUrlPrefix, StripQuotes ("@AndroidCmakeUrlPrefix@"));
1010
properties.Add (KnownProperties.AndroidCmakeVersion, StripQuotes ("@AndroidCmakeVersion@"));
1111
properties.Add (KnownProperties.AndroidCmakeVersionPath, StripQuotes (@"@AndroidCmakeVersionPath@"));
12+
properties.Add (KnownProperties.AndroidMinimumDotNetApiLevel, StripQuotes ("@AndroidMinimumDotNetApiLevel@"));
1213
properties.Add (KnownProperties.AndroidDefaultTargetDotnetApiLevel, StripQuotes ("@AndroidDefaultTargetDotnetApiLevel@"));
1314
properties.Add (KnownProperties.AndroidLatestStableApiLevel, StripQuotes ("@AndroidLatestStableApiLevel@"));
1415
properties.Add (KnownProperties.AndroidLatestUnstableApiLevel, StripQuotes ("@AndroidLatestUnstableApiLevel@"));

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -168,7 +168,6 @@ GeneratedFile Get_XABuildConfig_cs (Context context)
168168
var replacements = new Dictionary<string, string> (StringComparer.Ordinal) {
169169
{ "@NDK_REVISION@", context.BuildInfo.NDKRevision },
170170
{ "@NDK_RELEASE@", BuildAndroidPlatforms.AndroidNdkVersion },
171-
{ "@NDK_MINIMUM_API_AVAILABLE@", context.BuildInfo.NDKMinimumApiAvailable },
172171
{ "@NDK_VERSION_MAJOR@", context.BuildInfo.NDKVersionMajor },
173172
{ "@NDK_VERSION_MINOR@", context.BuildInfo.NDKVersionMinor },
174173
{ "@NDK_VERSION_MICRO@", context.BuildInfo.NDKVersionMicro },
@@ -177,6 +176,7 @@ GeneratedFile Get_XABuildConfig_cs (Context context)
177176
{ "@NDK_X86_API@", BuildAndroidPlatforms.NdkMinimumAPILegacy32.ToString ().ToString () },
178177
{ "@NDK_X86_64_API@", BuildAndroidPlatforms.NdkMinimumAPI.ToString ().ToString () },
179178
{ "@XA_SUPPORTED_ABIS@", context.Properties.GetRequiredValue (KnownProperties.AndroidSupportedTargetJitAbis).Replace (':', ';') },
179+
{ "@ANDROID_DEFAULT_MINIMUM_DOTNET_API_LEVEL@", context.Properties.GetRequiredValue (KnownProperties.AndroidMinimumDotNetApiLevel) },
180180
{ "@ANDROID_DEFAULT_TARGET_DOTNET_API_LEVEL@", context.Properties.GetRequiredValue (KnownProperties.AndroidDefaultTargetDotnetApiLevel) },
181181
{ "@ANDROID_LATEST_STABLE_API_LEVEL@", context.Properties.GetRequiredValue (KnownProperties.AndroidLatestStableApiLevel) },
182182
{ "@ANDROID_LATEST_UNSTABLE_API_LEVEL@", context.Properties.GetRequiredValue (KnownProperties.AndroidLatestUnstableApiLevel) },

build-tools/xaprepare/xaprepare/xaprepare.targets

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@
4343
<Replacement Include="@AndroidCmakeUrlPrefix@=$(AndroidCmakeUrlPrefix)" />
4444
<Replacement Include="@AndroidCmakeVersion@=$(AndroidCmakeVersion)" />
4545
<Replacement Include="@AndroidCmakeVersionPath@=$(AndroidCmakeVersionPath)" />
46+
<Replacement Include="@AndroidMinimumDotNetApiLevel@=$(AndroidMinimumDotNetApiLevel)" />
4647
<Replacement Include="@AndroidDefaultTargetDotnetApiLevel@=$(AndroidDefaultTargetDotnetApiLevel)" />
4748
<Replacement Include="@AndroidLatestStableApiLevel@=$(AndroidLatestStableApiLevel)" />
4849
<Replacement Include="@AndroidLatestUnstableApiLevel@=$(AndroidLatestUnstableApiLevel)" />

0 commit comments

Comments
 (0)