I am having an issue with the latest DeliveryClient in Xamarin.Android. The following code snippet runs fine in a Debug build.
However, I get a runtime error by unchecking the two Packaging properties items, Use Shared Runtime and Use Fast deployment in the Android project properties. And you have to uncheck these when you are archiving an APK to be installed on a device. Once I do that, I get the stack trace below, which isn’t very helpful, but it seems the http request is just going off somewhere and not being executed.
This makes me wonder if anyone has used this latest version of the DeliveryClient successfully in an Android Release build. This didn’t happen in earlier versions before the DeliveryClientBuilder.
DeliveryClient client = DeliveryClientBuilder
.WithOptions(builder => builder
.WithProjectId("myProjectId")
.UseProductionApi
.WithMaxRetryAttempts(5)
.Build())
.Build();
Task<string> content = Task.Run(async () =>
{
var res = client.GetItemAsync("hello").Result;
var helloFromKC = res.Item.GetString("message_from_kc");
return helloFromKC;
});
04-18 18:24:16.408 I/mono-stdout(17908): One or more errors occurred. One or more errors occurred.
at System.Threading.Tasks.Task.ThrowIfExceptional (System.Boolean includeTaskCanceledExceptions) [0x00011] in /Users/builder/jenkins/workspace/xamarin-android-d15-8/xamarin-android/external/mono/mcs/class/referencesource/mscorlib/system/threading/Tasks/Task.cs:2164 04-18 18:24:16.578 I/mono-stdout(17908): at System.Threading.Tasks.Task.ThrowIfExceptional (System.Boolean includeTaskCanceledExceptions) [0x00011] in /Users/builder/jenkins/workspace/xamarin-android-d15-8/xamarin-android/external/mono/mcs/class/referencesource/mscorlib/system/threading/Tasks/Task.cs:2164 at System.Threading.Tasks.Task`1[TResult].GetResultCore (System.Boolean waitCompletionNotification) [0x0002b] in /Users/builder/jenkins/workspace/xamarin-android-d15-8/xamarin-android/external/mono/mcs/class/referencesource/mscorlib/system/threading/Tasks/Future.cs:562 at System.Threading.Tasks.Task1[TResult].get_Result () [0x00000] in /Users/builder/jenkins/workspace/xamarin-android-d15-8/xamarin-android/external/mono/mcs/class/referencesource/mscorlib/system/threading/Tasks/Future.cs:532 at App1.MainActivity+<>c__DisplayClass3_0+<b__1>d.MoveNext () [0x00014] in C:\TestApps\AndroidKenticoTest\App1\App1\MainActivity.cs:68 04-18 18:24:16.579 I/mono-stdout(17908): at System.Threading.Tasks.Task1[TResult].GetResultCore (System.Boolean waitCompletionNotification) [0x0002b] in /Users/builder/jenkins/workspace/xamarin-android-d15-8/xamarin-android/external/mono/mcs/class/referencesource/mscorlib/system/threading/Tasks/Future.cs:562
I've finally debugged the source of this behavior. In Xamarin some reflection methods are not available (or at least not fully supported) in Portable Class Library (PCL) and GetExecutingAssembly()
is one of those methods.
As a result, Kentico Cloud Delivery's SDK private methods GetSdkVersion()
and GetSdkPackageId()
throw exception since they used this method.
As a quick workaround, you can reference SDK directly as a project and comment out body of GetSdkPackageId() and GetSdkVersion() methods (just return some dummy string.) I'm going to create an issue and try to fix it in the SDK (and Nuget Package as well).
Update 1: In addition to (not fully) GetExecutingAssembly()
support in Xamarin, it seems it's not possible to get valid path location for the assembly while using not a shared runtime (production mode).
Update 2: Created issue on GitHub.
Update 3: The issue is fixed in the SDK and the new patched version 10.0.1 has been released. Let me know if it works for you.