Skip to content

Commit

Permalink
[Xamarin.Android.Build.Tasks] Add XA1031 error for `AndroidHttpClient…
Browse files Browse the repository at this point in the history
…HandlerType`

Fixes dotnet#7326

We should check the value of the `AndroidHttpClientHandlerType` property
during the build process. This property can have a number of
different values depending on what version of Xamarin.Android is being
used.

Under Classic a valid value is `Xamarin.Android.Net.AndroidClientHandler`,
however under .NET 6+ the valid values are

- `Xamarin.Android.Net.AndroidMessageHandler`.
- `System.Net.Http.SocketsHttpHandler, System.Net.Http`.

We should raise an error if the user is using an invalid
value.
  • Loading branch information
dellis1972 committed Dec 7, 2022
1 parent 2a16828 commit 389ac6e
Show file tree
Hide file tree
Showing 16 changed files with 503 additions and 167 deletions.
3 changes: 3 additions & 0 deletions Documentation/guides/messages/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,9 @@ or 'Help->Report a Problem' in Visual Studio for Mac.
+ [XA1027](xa1027.md): The 'EnableProguard' MSBuild property is set to 'true' and the 'AndroidLinkTool' MSBuild property is empty, so 'AndroidLinkTool' will default to 'proguard'.
+ [XA1028](xa1028.md): The 'AndroidEnableProguard' MSBuild property is set to 'true' and the 'AndroidLinkTool' MSBuild property is empty, so 'AndroidLinkTool' will default to 'proguard'.
+ [XA1029](xa1029.md): The 'AotAssemblies' MSBuild property is deprecated. Edit the project file in a text editor to remove this property, and use the 'RunAOTCompilation' MSBuild property instead.
+ [XA1031](xa1031.md): The 'AndroidHttpClientHandlerType' has an invalid value.
+ [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.

## XA2xxx: Linker

Expand Down
20 changes: 20 additions & 0 deletions Documentation/guides/messages/xa1031.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
---
title: Xamarin.Android error XA1031
description: XA1031 error code
ms.date: 10/10/2022
---
# Xamarin.Android error XA1031

## Example messages

```
The 'AndroidHttpClientHandlerType' property value 'Foo.Bar.HttpHander, MyApp' must derive from 'System.Net.Http.HttpMessageHandler'.
Please change the value to an assembly-qualifed type name which inherits from '{1}' or remove the property completely.
```

## Solution

Edit your csproj directly and change the 'AndroidHttpClientHandlerType' to
a valid value.

Valid values can be found at `~/android/deploy-test/building-apps/build-properties.md#AndroidHttpClientHandlerType`.
19 changes: 19 additions & 0 deletions Documentation/guides/messages/xa1032.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
---
title: Xamarin.Android error XA1032
description: XA1032 error code
ms.date: 10/10/2022
---
# Xamarin.Android error XA1032

## Example messages

```
Failed to resolve '{0}' from '{1}'. Please check your `AndroidHttpClientHandlerType` setting.
```

## Solution

Edit your csproj directly and change the 'AndroidHttpClientHandlerType' to
a valid value.

Valid values can be found at `~/android/deploy-test/building-apps/build-properties.md#AndroidHttpClientHandlerType`.
19 changes: 19 additions & 0 deletions Documentation/guides/messages/xa1033.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
---
title: Xamarin.Android error XA1033
description: XA1033 error code
ms.date: 10/10/2022
---
# Xamarin.Android error XA1033

## Example messages

```
Could not resolve '{0}'. Please check your `AndroidHttpClientHandlerType` setting.
```

## Solution

Edit your csproj directly and change the 'AndroidHttpClientHandlerType' to
a valid value.

Valid values can be found at `~/android/deploy-test/building-apps/build-properties.md#AndroidHttpClientHandlerType`.
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ projects, these properties are set in Xamarin.Android.Legacy.targets.
_CollectJavaSourceForBinding;
_CompileBindingJava;
$(BuildDependsOn);
_CheckAndroidHttpClientHandlerType;
_CompileDex;
$(_AfterCompileDex);
</BuildDependsOn>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,7 @@
<HttpActivityPropagationSupport Condition="'$(HttpActivityPropagationSupport)' == ''">false</HttpActivityPropagationSupport>
<InvariantGlobalization Condition="'$(InvariantGlobalization)' == ''">false</InvariantGlobalization>
<StartupHookSupport Condition="'$(StartupHookSupport)' == ''">false</StartupHookSupport>
<UseNativeHttpHandler Condition=" $(AndroidHttpClientHandlerType.Contains ('System.Net.Http.SocketsHttpHandler')) And '$(UseNativeHttpHandler)' == '' ">false</UseNativeHttpHandler>
<UseNativeHttpHandler Condition="'$(UseNativeHttpHandler)' == ''">true</UseNativeHttpHandler>
<_AggressiveAttributeTrimming Condition="'$(_AggressiveAttributeTrimming)' == ''">true</_AggressiveAttributeTrimming>
<NullabilityInfoContextSupport Condition="'$(NullabilityInfoContextSupport)' == ''">false</NullabilityInfoContextSupport>
Expand Down
Loading

0 comments on commit 389ac6e

Please sign in to comment.