gpt4 book ai didi

c# - 目标 sdk 更改后 Xamarin.Android 构建错误

转载 作者:搜寻专家 更新时间:2023-11-01 09:34:12 25 4
gpt4 key购买 nike

在 Xamarin.Forms 解决方案的 Android 项目中的 MainActivity.cs 中出现以下错误:CurrentPlatform 由于其保护级别而无法访问

来自 OnCreate() 内部的以下代码行,仅 CurrentPlaftorm 部分加下划线:Microsoft.WindowsAzure.MobileServices.CurrentPlatform.Init();

直到我将 MonoAndroid 从 v6.0 升级到 v7.0 并进行了所有必要的更新(例如 JDK 1.8)后,我才收到此错误。想知道是否有人可以解释这个错误的含义以及为什么专门针对 CurrentPlatform 调用它。

我尝试在新项目中重新创建此错误,但一旦输入 Microsoft.WindowsAzure.MobileServices。,它就可以毫无问题地使用 CurrentPlatform 选项。

现在,使用 MobileServiceClient 类型从 WindowsAzure 组件调用 LoginAsync() 的一行会在参数上引发两个错误,而这些错误曾经是:

等待 client.LoginAsync(context, "facebook");

但是我现在收到以下两个错误:参数 1:无法从“Android.Content.Context”转换为“Microsoft.WindowsAzure.MobileServices.MobileServiceAuthenticationProvider”参数 2:无法从“string”转换为“Newtonsoft.Json.Linq.JObject”

不知道为什么当我更改 Android Target SDK 时这两个区域的代码会损坏,因为它们只是 Microsoft.WindowsAzure 组件的一部分。

最佳答案

Not sure why these two areas of code broke when I changed my Android Target SDK as they were just part of the Microsoft.WindowsAzure components.

根据您的描述,我推测是Azure Mobile Client SDK版本的问题。你引用了。

  • 对于 Azure Mobile Client SDK 3.1.0 ,您的客户端将从以下路径引用该库:

    Microsoft.Azure.Mobile.Client.3.1.0\lib\monoandroid\Microsoft.WindowsAzure.Mobile.Ext.dll

    您可以利用ILSpy检查 LoginAsync 的扩展方法,如下所示: enter image description here

而对于Azure Mobile Client SDK 4.0.0-alpha-001 ,如果您的 MonoAndroid >= 4.4,则该库将在以下位置引用:

Microsoft.Azure.Mobile.Client.4.0.0-alpha-001\lib\monoandroid44\Microsoft.Azure.Mobile.Client.dll enter image description here

  • 对于 Azure Mobile Client SDK 4.0.0 ,如果您的 MonoAndroid >= 7.1,则该库将在以下位置引用:

    Microsoft.Azure.Mobile.Client\4.0.0\lib\monoandroid71\Microsoft.Azure.Mobile.Client.dll

    我之前的项目目标是 Android 6.0,那么该库将仅引用 Microsoft.Azure.Mobile.Client.4.0.0\lib\netstandard1.4\Microsoft.Azure.Mobile.Client.dll,并且没有通过服务器流身份验证的 LoginAsync 扩展方法。

总之,从您的代码 await client.LoginAsync(context, "facebook"); 来看,您正在使用 Server-managed authentication ,我建议您可以使用 Azure 移动客户端 SDK 3.1.0 而不升级 Android SDK 版本,或者使用最新的 Azure 移动客户端 SDK 4.0.0 并将 Android SDK 版本升级到 7.1 或更高版本。

此外,代码 client.LoginAsync(MobileServiceAuthenticationProvider.Facebo‌​ok,{JObject token}) 使用 Client-managed authentication ,此时,您的应用程序可以独立联系身份提供商,然后在登录 Azure 移动后端时提供返回的 token 。

关于c# - 目标 sdk 更改后 Xamarin.Android 构建错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44770437/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com