安卓版本和SDK

Xamarin.Android开发中遇到的问题

开发

1、Resource.Id未包含xxx的定义

打开了一个OK的Id,是位于\obj\Debug\90\designtime\Resource.designer.cs ,打开文件搜索xxx,果然没有。

删除此文件 重新生成项目,并没有重新生成Resource.designer.cs 

解决方法:

删除整个obj文件夹,重新生成项目;

或者重启VS,自动重新生成Resource.designer.cs了,并且含有xxx

2、Button文本默认大写

参考:xamarin forms中的Button文本默认大写

将按钮的属性textAllCaps都改为false。默认没有设置 是true。

3、ADB0020: Android ABI 不匹配。

问题1:你正将应用支持的“armeabi,armeabi-v7a,x86”ABI 部署到 ABI“x86_64”的不兼容设备。应创建匹配其中一个应用 ABI 的仿真程序,或将“x86_64”添加到应用生成的 ABI 列表中

问题原因:应该是选择的模拟器(X86_64)不匹配,需要创建一个“armeabi,armeabi-v7a,x86”是模拟器来调试。

或者看下“使用共享运行时”是否选中

Xamarin.Android开发中遇到的问题

参考:

说说Android项目中的armeabi,armeabi-v7a和x86

Android 关于arm64-v8a、armeabi-v7a、armeabi、x86下的so文件兼容问题

问题2:Please open the Android SDK Manager and install the latest version of 'Android Support Repository' from the 'Extras' section, and then reload your solution.

问题原因:上一步选择X86处理器后,需要安装相应的SDK,和工具中的Android Support Repository

Xamarin.Android开发中遇到的问题

Xamarin.Android开发中遇到的问题

4、方法过时

4.1   [Obsolete("This constructor is obsolete as of version 2.5. Please use PageRenderer(Context) instead.")]

在使用PageRenderer时提示这个构造函数已经过时,发生这种情况的原因是从v2.5版本开始的Xamarin.Forms非常简单,将Xamarin.Forms.Forms的Context属性标记为过时。 因此,要获取渲染器的全局上下文,有必要调用该渲染器的基类,这意味着在构造函数中,您需要执行以下操作: 添加以下代码即可(Please use PageRenderer(Context) instead.)

public WriteEmailPageRenderer(Context context) : base(context)
        {
        }

参考:How do I resolve WebViewRenderer is obsolete

4.2 Context is obsolete as of version 2.5. Please use a local context instead

报过时的写法:Android.Content.Context content = Forms.Context;  或者  Activity activity = (Activity)Forms.Context;

在Dependencies中定义特定平台的功能时,使用Forms.Context会提示已过时,请改为使用本地环境。

解决方案是在不引用Xamarin.Forms.Forms.Context的情况下获取本地上下文

注:Android.Content.Context是应用程序环境全局信息上下文,Activity都是继承自此类。

有两种方式解决:

方式1、在接口中提供Init(),然后在MainActivity中调用:VersionHelper.Init(this);

public class VersionHelper : IVersionHelper
    {
        static Context _context;

        public static void Init(Context context)
        {
            _context = context;
        }
...

方式2、在MainActivity类中创建一个静态属性,并将其设置为MainActivity实例:

Xamarin.Android开发中遇到的问题
public class MainActivity : global::Xamarin.Forms.Platform.Android.FormsAppCompatActivity
{
    internal static MainActivity Instance { get; private set; }

    protected override void OnCreate(Bundle bundle)
    {
        ...
        global::Xamarin.Forms.Forms.Init(this, bundle);
        Instance = this;
        Xamarin.Forms.DependencyService.Register<IVersionHelper, VersionHelper>();
        LoadApplication(new App());
    }
}
View Code

相关文章:

  • 2022-12-23
  • 2021-10-27
  • 2021-09-05
  • 2021-04-05
  • 2021-12-19
  • 2018-09-18
  • 2021-06-13
猜你喜欢
  • 2019-11-23
  • 2021-09-16
  • 2021-09-03
  • 2021-07-24
  • 2021-11-04
  • 2022-12-23
  • 2022-12-23
相关资源
相似解决方案