xamarin.android - Android 中最新的 Kentico Delivery Client 和 Release 版本是否存在问题
问题描述
我在使用 Xamarin.Android 中的最新 DeliveryClient 时遇到问题。以下代码片段在 Debug 构建中运行良好。
但是,通过取消选中Android 项目属性中的两个 Packaging 属性项Use Shared Runtime和Use Fast deployment ,我得到了运行时错误。当您归档要安装在设备上的 APK 时,您必须取消选中这些。一旦我这样做了,我会得到下面的堆栈跟踪,这不是很有帮助,但似乎 http 请求只是在某个地方发生并且没有被执行。
这让我想知道是否有人在 Android 发布版本中成功使用了这个最新版本的DeliveryClient 。这在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):发生一个或多个错误。发生一个或多个错误。
在 System.Threading.Tasks.Task.ThrowIfExceptional (System.Boolean includeTaskCanceledExceptions) [0x00011] 在 /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): 在 System.Threading.Tasks.Task.ThrowIfExceptional (System.Boolean includeTaskCanceledExceptions) [0x00011]在 System.Threading 的 /Users/builder/jenkins/workspace/xamarin-android-d15-8/xamarin-android/external/mono/mcs/class/referencesource/mscorlib/system/threading/Tasks/Task.cs:2164 中。 Tasks.Task`1[TResult].GetResultCore (System.Boolean waitCompletionNotification) [0x0002b] 在 /Users/builder/jenkins/workspace/xamarin-android-d15-8/xamarin-android/external/mono/mcs/class/referencesource /mscorlib/system/threading/Tasks/Future.cs:562 在 System.Threading.Tasks.Task1[TResult].get_Result () [0x00000] 在 /Users/builder/jenkins/workspace/xamarin-android-d15-8/xamarin-android/external/mono/mcs/class/referencesource /mscorlib/system/threading/Tasks/Future.cs:532 在 C:\TestApps\AndroidKenticoTest\App1\App1\MainActivity.cs:68 04 中的 App1.MainActivity+<>c__DisplayClass3_0+<b__1>d.MoveNext () [0x00014] -18 18:24:16.579 I/mono-stdout(17908): 在 System.Threading.Tasks.Task1[TResult].GetResultCore (System.Boolean waitCompletionNotification) [0x0002b] 在 /Users/builder/jenkins/workspace/xamarin- android-d15-8/xamarin-android/external/mono/mcs/class/referencesource/mscorlib/system/threading/Tasks/Future.cs:562/Users/builder/jenkins/workspace/xamarin-android-d15-8/xamarin-android/external/mono/mcs/class/referencesource/mscorlib/system/threading/Tasks/Future.cs 中的 get_Result () [0x00000]: 532 在 App1.MainActivity+<>c__DisplayClass3_0+<b__1>d.MoveNext () [0x00014] 在 C:\TestApps\AndroidKenticoTest\App1\App1\MainActivity.cs:68 04-18 18:24:16.579 I/mono-stdout( 17908): 在 System.Threading.Tasks.Task1[TResult].GetResultCore (System.Boolean waitCompletionNotification) [0x0002b] 在 /Users/builder/jenkins/workspace/xamarin-android-d15-8/xamarin-android/external/mono /mcs/class/referencesource/mscorlib/system/threading/Tasks/Future.cs:562/Users/builder/jenkins/workspace/xamarin-android-d15-8/xamarin-android/external/mono/mcs/class/referencesource/mscorlib/system/threading/Tasks/Future.cs 中的 get_Result () [0x00000]: 532 在 App1.MainActivity+<>c__DisplayClass3_0+<b__1>d.MoveNext () [0x00014] 在 C:\TestApps\AndroidKenticoTest\App1\App1\MainActivity.cs:68 04-18 18:24:16.579 I/mono-stdout( 17908): 在 System.Threading.Tasks.Task1[TResult].GetResultCore (System.Boolean waitCompletionNotification) [0x0002b] 在 /Users/builder/jenkins/workspace/xamarin-android-d15-8/xamarin-android/external/mono /mcs/class/referencesource/mscorlib/system/threading/Tasks/Future.cs:56268 04-18 18:24:16.579 I/mono-stdout(17908): 在 System.Threading.Tasks.Task1[TResult].GetResultCore (System.Boolean waitCompletionNotification) [0x0002b] 在 /Users/builder/jenkins/workspace/ xamarin-android-d15-8/xamarin-android/external/mono/mcs/class/referencesource/mscorlib/system/threading/Tasks/Future.cs:56268 04-18 18:24:16.579 I/mono-stdout(17908): 在 System.Threading.Tasks.Task1[TResult].GetResultCore (System.Boolean waitCompletionNotification) [0x0002b] 在 /Users/builder/jenkins/workspace/ xamarin-android-d15-8/xamarin-android/external/mono/mcs/class/referencesource/mscorlib/system/threading/Tasks/Future.cs:562
解决方案
我终于调试了这种行为的根源。在 Xamarin 中,一些反射方法在可移植类库 (PCL)中不可用GetExecutingAssembly()
(或至少不完全支持),并且是这些方法之一。
结果,Kentico Cloud Delivery 的 SDK 私有方法GetSdkVersion()
并GetSdkPackageId()
抛出异常,因为他们使用了这种方法。
作为一种快速解决方法,您可以将 SDK 直接作为项目引用并注释掉GetSdkPackageId()和GetSdkVersion()方法的主体(只返回一些虚拟字符串。)我将创建一个问题并尝试在 SDK 中修复它(以及 Nuget 包)。
更新 1:除了(不完全)GetExecutingAssembly()
在 Xamarin 中的支持之外,似乎在使用非共享运行时(生产模式)时无法获取程序集的有效路径位置。
更新 2:在 GitHub 上创建问题。
更新 3:该问题已在 SDK 中修复,新的补丁版本 10.0.1已发布。请让我知道这对你有没有用。
推荐阅读
- python - 正则表达式修复格式错误的“JSON”数据中的双引号
- r - 用 tidyverse 重构长到宽格式问题
- javascript - 等待 Javascript FileReader 完成
- numpy - 如何以特定方式在numpy中合并数组?
- model - 在视图中显示名称而不是 ID
- python - Xunit 按标签统计
- oracle - 是否有一种编程/系统本地方式来跨实例复制 oracle 角色?
- java - 如何在 Spring Boot 中有条件地返回自定义响应正文和状态?
- batch-file - cwRsync 添加“。” 到文件名和错误“不允许操作”
- spring - 如何使用 prod 配置文件(Spring Boot)在 Elastic Beanstalk 上的端口 5000 上公开应用程序