Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[XABT] Prefer SupportedOSPlatformVersion over minSdkVersion #8026

Merged
merged 15 commits into from
Jun 1, 2023
Merged
2 changes: 1 addition & 1 deletion Configuration.props
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
<TargetFrameworkVersion Condition=" '$(TargetFrameworkVersion)' == '' And '$(UsingMicrosoftNETSdk)' != 'true' And '$(_StandardLibraryPath)' != '' ">v4.7.2</TargetFrameworkVersion>
<TargetFrameworkVersion Condition=" '$(TargetFrameworkVersion)' == '' And '$(UsingMicrosoftNETSdk)' != 'true' ">v4.7.1</TargetFrameworkVersion>
<AndroidJavaRuntimeApiLevel Condition="'$(AndroidJavaRuntimeApiLevel)' == ''">26</AndroidJavaRuntimeApiLevel>
<!-- The min API level supported by Microsoft.Android.Sdk, should refactor/remove when this value is the same as $(AndroidFirstApiLevel) -->
<!-- The min API level supported by Microsoft.Android.Sdk -->
<AndroidMinimumDotNetApiLevel Condition="'$(AndroidMinimumDotNetApiLevel)' == ''">21</AndroidMinimumDotNetApiLevel>
<!-- *Latest* *stable* API level binding that we support; used when building src/Xamarin.Android.Build.Tasks -->
<AndroidLatestStableApiLevel Condition="'$(AndroidLatestStableApiLevel)' == ''">33</AndroidLatestStableApiLevel>
Expand Down
4 changes: 3 additions & 1 deletion Documentation/guides/messages/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,8 @@ or 'Help->Report a Problem' in Visual Studio for Mac.
+ [XA1032](xa1032.md):Failed to resolve '{0}' from '{1}'. Please check your `AndroidHttpClientHandlerType` setting.
+ [XA1033](xa1033.md): Could not resolve '{0}'. Please check your `AndroidHttpClientHandlerType` setting.
+ [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.
+ [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).
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).

## XA2xxx: Linker

Expand Down Expand Up @@ -163,7 +165,7 @@ or 'Help->Report a Problem' in Visual Studio for Mac.
+ XA4213: The type '{type}' must provide a public default constructor
+ [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.
+ [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.
+ [XA4216](xa4216.md): AndroidManifest.xml //uses-sdk/@android:minSdkVersion '{min_sdk?.Value}' is less than API-{XABuildConfig.NDKMinimumApiAvailable}, this configuration is not supported.
+ [XA4216](xa4216.md): The deployment target '19' is not supported (the minimum is '21'). Please increase the $(SupportedOSPlatformVersion) property value in your project file.
+ XA4217: Cannot override Kotlin-generated method '{method}' because it is not a valid Java method name. This method can only be overridden from Kotlin.
+ [XA4218](xa4218.md): Unable to find //manifest/application/uses-library at path: {path}
+ XA4219: Cannot find binding generator for language {language} or {defaultLanguage}.
Expand Down
27 changes: 27 additions & 0 deletions Documentation/guides/messages/xa1036.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
---
title: Xamarin.Android error XA1036
description: XA1036 error code
ms.date: 5/22/2023
---
# Xamarin.Android error XA1036

## Example messages

```
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).
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).
```

## Issue

This error indicates that you have a mismatch between the minSdkVersion
element set in your AndroidManifest.xml and the $(SupportedOSPlatformVersion)
property value in your project file.


## Solution

Raise the value of `//uses-sdk/@android:minSdkVersion` in *AndroidManifest.xml*
to match the $(SupportedOSPlatformVersion), or remove `//uses-sdk/@android:minSdkVersion`
from *AndroidManifest.xml* and set $(SupportedOSPlatformVersion) in your project
file if it is unset.
34 changes: 25 additions & 9 deletions Documentation/guides/messages/xa4216.md
Original file line number Diff line number Diff line change
@@ -1,23 +1,39 @@
---
title: Xamarin.Android warning XA4216
description: XA4216 warning code
title: Xamarin.Android error XA4216
description: XA4216 error code
ms.date: 02/07/2019
---
# Xamarin.Android warning XA4216
# Xamarin.Android error XA4216

## Example messages

```
warning XA4216: AndroidManifest.xml //uses-sdk/@android:minSdkVersion '15' is less than API-16, this configuration is not supported.
error XA4216: The deployment target '19' is not supported (the minimum is '21'). Please increase the $(SupportedOSPlatformVersion) property value in your project file.
```

```
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.
```

```
warning XA4216: AndroidManifest.xml //uses-sdk/@android:targetSdkVersion '19' is less than API-21, this configuration is not supported.
```

## Issue

This warning indicates your application is targeting an API level that
Xamarin.Android does not support.
This error or warning indicates your application is targeting an unsupported API level.

## Solution

Raise the value of `//uses-sdk/@android:minSdkVersion` or
`//uses-sdk/@android:targetSdkVersion` in *AndroidManifest.xml* to a
higher API level that is supported.
Edit your csproj and increase the '$(SupportedOSPlatformVersion)'
property value to something greater than or equal to the minimum supported version.

or

Edit your AndroidManifest.xml and remove `//uses-sdk/@android:minSdkVersion`,
or increase it to something greater than or equal to the minimum supported version.

or

Edit your AndroidManifest.xml and remove `//uses-sdk/@android:targetSdkVersion`,
or increase it to something greater than or equal to the minimum supported version.
15 changes: 0 additions & 15 deletions build-tools/scripts/NDKVersionInfo.targets

This file was deleted.

2 changes: 1 addition & 1 deletion build-tools/scripts/XABuildConfig.cs.in
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +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 int NDKMinimumApiAvailable = @NDK_MINIMUM_API_AVAILABLE@;
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@;
public const int AndroidDefaultTargetDotnetApiLevel = @ANDROID_DEFAULT_TARGET_DOTNET_API_LEVEL@;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ static class KnownProperties
public const string AndroidCmakeUrlPrefix = "AndroidCmakeUrlPrefix";
public const string AndroidCmakeVersion = "AndroidCmakeVersion";
public const string AndroidCmakeVersionPath = "AndroidCmakeVersionPath";
public const string AndroidMinimumDotNetApiLevel = "AndroidMinimumDotNetApiLevel";
public const string AndroidDefaultTargetDotnetApiLevel = "AndroidDefaultTargetDotnetApiLevel";
public const string AndroidLatestStableApiLevel = "AndroidLatestStableApiLevel";
public const string AndroidLatestUnstableApiLevel = "AndroidLatestUnstableApiLevel";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ namespace Xamarin.Android.Prepare
properties.Add (KnownProperties.AndroidCmakeUrlPrefix, StripQuotes ("@AndroidCmakeUrlPrefix@"));
properties.Add (KnownProperties.AndroidCmakeVersion, StripQuotes ("@AndroidCmakeVersion@"));
properties.Add (KnownProperties.AndroidCmakeVersionPath, StripQuotes (@"@AndroidCmakeVersionPath@"));
properties.Add (KnownProperties.AndroidMinimumDotNetApiLevel, StripQuotes ("@AndroidMinimumDotNetApiLevel@"));
properties.Add (KnownProperties.AndroidDefaultTargetDotnetApiLevel, StripQuotes ("@AndroidDefaultTargetDotnetApiLevel@"));
properties.Add (KnownProperties.AndroidLatestStableApiLevel, StripQuotes ("@AndroidLatestStableApiLevel@"));
properties.Add (KnownProperties.AndroidLatestUnstableApiLevel, StripQuotes ("@AndroidLatestUnstableApiLevel@"));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -168,7 +168,6 @@ GeneratedFile Get_XABuildConfig_cs (Context context)
var replacements = new Dictionary<string, string> (StringComparer.Ordinal) {
{ "@NDK_REVISION@", context.BuildInfo.NDKRevision },
{ "@NDK_RELEASE@", BuildAndroidPlatforms.AndroidNdkVersion },
{ "@NDK_MINIMUM_API_AVAILABLE@", context.BuildInfo.NDKMinimumApiAvailable },
{ "@NDK_VERSION_MAJOR@", context.BuildInfo.NDKVersionMajor },
{ "@NDK_VERSION_MINOR@", context.BuildInfo.NDKVersionMinor },
{ "@NDK_VERSION_MICRO@", context.BuildInfo.NDKVersionMicro },
Expand All @@ -177,6 +176,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 (':', ';') },
{ "@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) },
{ "@ANDROID_LATEST_UNSTABLE_API_LEVEL@", context.Properties.GetRequiredValue (KnownProperties.AndroidLatestUnstableApiLevel) },
Expand Down
1 change: 1 addition & 0 deletions build-tools/xaprepare/xaprepare/xaprepare.targets
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@
<Replacement Include="@AndroidCmakeUrlPrefix@=$(AndroidCmakeUrlPrefix)" />
<Replacement Include="@AndroidCmakeVersion@=$(AndroidCmakeVersion)" />
<Replacement Include="@AndroidCmakeVersionPath@=$(AndroidCmakeVersionPath)" />
<Replacement Include="@AndroidMinimumDotNetApiLevel@=$(AndroidMinimumDotNetApiLevel)" />
<Replacement Include="@AndroidDefaultTargetDotnetApiLevel@=$(AndroidDefaultTargetDotnetApiLevel)" />
<Replacement Include="@AndroidLatestStableApiLevel@=$(AndroidLatestStableApiLevel)" />
<Replacement Include="@AndroidLatestUnstableApiLevel@=$(AndroidLatestUnstableApiLevel)" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,9 @@
-->
<_GetChildProjectCopyToPublishDirectoryItems>false</_GetChildProjectCopyToPublishDirectoryItems>
<UseMonoRuntime Condition=" '$(UseMonoRuntime)' == '' ">true</UseMonoRuntime>

<!-- Use $(AndroidMinimumSupportedApiLevel) for $(SupportedOSPlatformVersion) if unset -->
<SupportedOSPlatformVersion Condition=" '$(SupportedOSPlatformVersion)' == '' ">$(AndroidMinimumSupportedApiLevel)</SupportedOSPlatformVersion>
jonpryor marked this conversation as resolved.
Show resolved Hide resolved
<!-- $(SupportedOSPlatformVersion) must be '21.0', but we should support integer values like '21' -->
<SupportedOSPlatformVersion Condition=" '$(SupportedOSPlatformVersion)' != '' and !$(SupportedOSPlatformVersion.Contains('.')) ">$(SupportedOSPlatformVersion).0</SupportedOSPlatformVersion>

Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

21 changes: 17 additions & 4 deletions src/Xamarin.Android.Build.Tasks/Properties/Resources.resx
Original file line number Diff line number Diff line change
Expand Up @@ -497,6 +497,13 @@ Please change the value to an assembly-qualifed type name which inherits from '{
<value>The 'BundleAssemblies' property is deprecated and it has no effect on the application build. Equivalent functionality is implemented by the 'AndroidUseAssemblyStore' and 'AndroidEnableAssemblyCompression' properties.</value>
<comment>The following are literal names and should not be translated: 'BundleAssemblies', 'AndroidUseAssemblyStore', 'AndroidEnableAssemblyCompression'</comment>
</data>
<data name="XA1036" xml:space="preserve">
<value>AndroidManifest.xml //uses-sdk/@android:minSdkVersion '{0}' does not match the $(SupportedOSPlatformVersion) value '{1}' 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).</value>
<comment>The following are literal names and should not be translated: AndroidManifest.xml, //uses-sdk/@android:minSdkVersion, $(SupportedOSPlatformVersion)
{0} - The minimum SDK version number
{1} - The SupportedOSPlatformVersion property value</comment>
</data>
<data name="XA2000" xml:space="preserve">
<value>Use of AppDomain.CreateDomain() detected in assembly: {0}. .NET 6 and higher will only support a single AppDomain, so this API will no longer be available in Xamarin.Android once .NET 6 is released.</value>
<comment>The following are literal names and should not be translated: AppDomain.CreateDomain(), AppDomain
Expand Down Expand Up @@ -607,12 +614,18 @@ Please change the value to an assembly-qualifed type name which inherits from '{
<comment>The two spaces indentation at the beginning of this message should be preserved in the translations where possible.
{0} - The generated Java type name
{1} - The managed type name</comment>
</data>
<data name="XA4216_SupportedOSPlatformVersion" xml:space="preserve">
<value>The deployment target '{0}' is not supported (the minimum is '{1}'). Please increase the $(SupportedOSPlatformVersion) property value in your project file.</value>
<comment>The following are literal names and should not be translated: Microsoft.Android, $(SupportedOSPlatformVersion)
{0} - The value of $(SupportedOSPlatformVersion)
{1} - The minimum $(SupportedOSPlatformVersion) supported by this version of the SDK</comment>
</data>
<data name="XA4216_MinSdkVersion" xml:space="preserve">
<value>AndroidManifest.xml //uses-sdk/@android:minSdkVersion '{0}' is less than API-{1}, this configuration is not supported.</value>
<comment>The following are literal names and should not be translated: AndroidManifest.xml, //uses-sdk/@android:minSdkVersion, API-{1}
{0} - The minimum SDK version number
{1} - The API version number</comment>
<value>The deployment target '{0}' is not supported (the minimum is '{1}'). Please increase (or remove) the //uses-sdk/@android:minSdkVersion value in your AndroidManifest.xml.</value>
<comment>The following are literal names and should not be translated: Microsoft.Android, //uses-sdk/@android:minSdkVersion, AndroidManifest.xml
{0} - The value of //uses-sdk/@android:minSdkVersion
{1} - The minimum $(SupportedOSPlatformVersion) supported by this version of the SDK</comment>
</data>
<data name="XA4216_TargetSdkVersion" xml:space="preserve">
<value>AndroidManifest.xml //uses-sdk/@android:targetSdkVersion '{0}' is less than API-{1}, this configuration is not supported.</value>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -329,12 +329,6 @@ void Run (DirectoryAssemblyResolver res, bool useMarshalMethods)
Log.LogCodedError ("XA4215", Properties.Resources.XA4215_Details, kvp.Key, typeName);
}

// NOTE: $(SupportedOSPlatformVersion) will potentially be 21.0
string minSdkVersion = null;
if (Version.TryParse (SupportedOSPlatformVersion, out var version)) {
minSdkVersion = version.Major.ToString ();
}

// Step 3 - Merge [Activity] and friends into AndroidManifest.xml
var manifest = new ManifestDocument (ManifestTemplate) {
PackageName = PackageName,
Expand All @@ -344,7 +338,7 @@ void Run (DirectoryAssemblyResolver res, bool useMarshalMethods)
Resolver = res,
SdkDir = AndroidSdkDir,
TargetSdkVersion = AndroidSdkPlatform,
MinSdkVersion = minSdkVersion,
MinSdkVersion = MonoAndroidHelper.ConvertSupportedOSPlatformVersionToApiLevel (SupportedOSPlatformVersion).ToString (),
Debug = Debug,
MultiDex = MultiDex,
NeedsInternet = NeedsInternet,
Expand Down
Loading