Android 9 app crashes when execute await function

434
4
Jump to solution
07-05-2019 03:14 AM
Highlighted
New Contributor III

Hi all,
I'am working on Visual Studio 2017 Community 15.9.13 with Xamarin 4.12.3.83 and Xamarin Android SDK 9.1.7.0.
I use ArcGIS runtime SDK for .NEt 100.5.0.

I want to compile and run the "Feature layer selection" or other similar code in the Sample Code section of the ArcGIS for Developer site.

When the target Android version is less then 9.0 (Pie) version, all functions well.
With Android 9.0 version the app is compiled and deployed correctly on my device while it crashes when it tries to execute an await function.

For axample:

...
Uri featureServiceUri = new Uri("http://sampleserver6.arcgisonline.com/arcgis/rest/services/DamageAssessment/FeatureServer/0");
var featureTable = new ServiceFeatureTable(featureServiceUri);
featureLayer = new FeatureLayer(featureTable);
await _featureLayer.LoadAsync(); // at this point the app crashes

...


When I catch the error, these are the Exception properties results:

***
HResult: -2146233088

InnerException: Java.IO.IOException: Cleartext HTTP traffic to sampleserver6.arcgisonline.com not permitted

Message: One or more errors occurred.

Source: mscorlib

StackTrace: at Esri.ArcGISRuntime.Http.ArcGISHttpClientHandler+ArcGISClientHandlerInternal+<>c__DisplayClass14_1.<SendAsync>b__0 (System.Threading.Tasks.Task`1[TResult] t) [0x00033] in C:\daily_r\api_xam\dotnet\api\src\Esri.ArcGISRuntime\Esri.ArcGISRuntime.Shared\Http\ArcGISHttpClientHandler.cs:703
at System.Threading.Tasks.ContinuationResultTaskFromResultTask`2[TAntecedentResult,TResult].InnerInvoke () [0x00024] in <d4a23bbd2f544c30a48c44dd622ce09f>:0
at System.Threading.Tasks.Task.Execute () [0x00000] in <d4a23bbd2f544c30a48c44dd622ce09f>:0
--- End of stack trace from previous location where exception was thrown ---
at Esri.ArcGISRuntime.Http.ArcGISHttpClientHandler+ArcGISClientHandlerInternal+<SendAsync>d__14.MoveNext () [0x008b5] in C:\daily_r\api_xam\dotnet\api\src\Esri.ArcGISRuntime\Esri.ArcGISRuntime.Shared\Http\ArcGISHttpClientHandler.cs:879
--- End of stack trace from previous location where exception was thrown ---
at System.Net.Http.HttpClient+<SendAsyncWorker>d__49.MoveNext () [0x000
ca] in <25ebe1083eaf4329b5adfdd5bbb7aa57>:0
--- End of stack trace from previous location where exception was thrown ---
at Esri.ArcGISRuntime.Internal.RequestRequiredHandler+<IssueRequestAndRespond>d__14.MoveNext () [0x004f9] in C:\daily_r\api_xam\dotnet\api\src\Esri.ArcGISRuntime\Esri.ArcGISRuntime.Shared\Internal\RequestRequiredHandler.cs:245
--- End of stack trace from previous location where exception was thrown ---
at FeatureLayerSelectionTest.MainActivity+<Initialize>d__4.MoveNext () [0x00115] in C:\VisualStudio\Xamarin\Progetti\FeatureLayerSelectionTest\FeatureLayerSelectionTest\MainActivity.cs:82

TargetSite: Void Throw()
***

Can someone help me?

Many thanks

Regards


Massimo

Tags (2)
Reply
0 Kudos
1 Solution

Accepted Solutions
Highlighted
Esri Frequent Contributor

Hi,

Is your await wrapped in a try/catch? Awaitable Tasks in the API will throw exceptions for example for invalid parameters, or for underlying platform issues.

In this case, I suspect it's because your URL is `http` rather than `https`. You can continue to use `http` in Android 9 but you will need to configure your app for that. For more information see https://developer.android.com/training/articles/security-config#CleartextTrafficPermitted.

Cheers

Mike

View solution in original post

Reply
0 Kudos
4 Replies
Highlighted
Esri Frequent Contributor

Hi,

Is your await wrapped in a try/catch? Awaitable Tasks in the API will throw exceptions for example for invalid parameters, or for underlying platform issues.

In this case, I suspect it's because your URL is `http` rather than `https`. You can continue to use `http` in Android 9 but you will need to configure your app for that. For more information see https://developer.android.com/training/articles/security-config#CleartextTrafficPermitted.

Cheers

Mike

View solution in original post

Reply
0 Kudos
Highlighted
New Contributor III

Thanks Mike,

I tried both with try/catch and without it, with the same result (app crash).

As soon as possible I will try to follow your suggestions and inform you about the outcome of the tests.

Regards

Massimo

Reply
0 Kudos
Highlighted
New Contributor III

Michael,

following your suggestion I modified the AndroidManifest.xml file, adding the following line:
android: usesCleartextTraffic = "false"
within the <application> tag.

Now debug and release versions compile and run correctly under Android 9.0 and lower.

I also tried to publish the service with the https protocol, on port 6443, and the app works just as well.

Many thanks again.

Best regards

 Massimo

Reply
0 Kudos
Highlighted
Esri Frequent Contributor

This sounds just like a bug that were in some of the first releases of VS2019: Android would crash when async methods were hit. I'm wondering if that bug also made it in to the VS2017 releases, but then never back-ported?
Does the app also crash there without the debugger attached? (the bug I'm thinking about didn't occur if you weren't debugging).

Here's the issue I'm referring to: https://github.com/xamarin/xamarin-android/issues/2920

Reply
0 Kudos