Xamarin OxyPlot升级缺少函数和文件路径

scyqe7ek  于 2023-08-01  发布在  其他
关注(0)|答案(1)|浏览(131)

我有一个在旧VS(2017)上运行的旧项目,目前正在尝试在vs2022中运行,所以我试图升级。我得到了多个与OxyPlot相关的错误。这里是错误。
第一个错误:

Severity    Code    Description Project File    Line    Suppression State
Error       Invalid value 'armeabi' in $(AndroidSupportedAbis). This ABI is no longer supported. Please update your project properties to remove the old value. If the properties page does not show an 'armeabi' checkbox, un-check and re-check one of the other ABIs and save the changes.   OxyPlot.Xamarin.Android

字符串
第二个错误:

Error       The $(TargetFrameworkVersion) for OxyPlot.Xamarin.Forms.Platform.Android (v9.0) is less than the minimum required $(TargetFrameworkVersion) for Xamarin.Forms (10.0). You need to increase the $(TargetFrameworkVersion) for OxyPlot.Xamarin.Forms.Platform.Android.    OxyPlot.Xamarin.Forms.Platform.Android


因此,我通过将.csproj

`<AndroidSupportedAbis>armeabi</AndroidSupportedAbis>`


<AndroidSupportedAbis>x86_64</AndroidSupportedAbis>


问题似乎很好,但在I cleanrebuild之后出现了另一个错误,如下所示

Severity    Code    Description Project File    Line    Suppression State
Error       invalid file path '...\OxyPlot\OxyPlot.Xamarin.Android\obj\Debug\100\res\main.xml'. OxyPlot.Xamarin.Android


对于第二个错误。我换了project properties -> application -> compile using Adnroid version: (Target Framework) to Android 10.0。在cleanrebuild之后,错误成倍增加并疯狂增长,如下所示:

Severity    Code    Description Project File    Line    Suppression State
Error   CS0234  The type or namespace name 'Android' does not exist in the namespace 'Xamarin.Forms.Platform' (are you missing an assembly reference?)  OxyPlot.Xamarin.Forms.Platform.Android  ...\OxyPlot\OxyPlot.Xamarin.Forms.Platform.Android\PlotViewRenderer.cs  6   Active
Error   CS0246  The type or namespace name 'ExportRendererAttribute' could not be found (are you missing a using directive or an assembly reference?)   OxyPlot.Xamarin.Forms.Platform.Android  ...\OxyPlot\OxyPlot.Xamarin.Forms.Platform.Android\PlotViewRenderer.cs  9   Active
Error   CS0246  The type or namespace name 'ExportRenderer' could not be found (are you missing a using directive or an assembly reference?)    OxyPlot.Xamarin.Forms.Platform.Android  ...\OxyPlot\OxyPlot.Xamarin.Forms.Platform.Android\PlotViewRenderer.cs  9   Active
Error   CS0246  The type or namespace name 'PlotView' could not be found (are you missing a using directive or an assembly reference?)  OxyPlot.Xamarin.Forms.Platform.Android  ...\OxyPlot\OxyPlot.Xamarin.Forms.Platform.Android\PlotViewRenderer.cs  9   Active
Error   CS0234  The type or namespace name 'Android' does not exist in the namespace 'OxyPlot.Xamarin' (are you missing an assembly reference?) OxyPlot.Xamarin.Forms.Platform.Android  ...\OxyPlot\OxyPlot.Xamarin.Forms.Platform.Android\PlotViewRenderer.cs  15  Active
Error   CS0246  The type or namespace name 'ViewRenderer<,>' could not be found (are you missing a using directive or an assembly reference?)   OxyPlot.Xamarin.Forms.Platform.Android  ...\OxyPlot\OxyPlot.Xamarin.Forms.Platform.Android\PlotViewRenderer.cs  20  Active
Error   CS0234  The type or namespace name 'PlotView' does not exist in the namespace 'OxyPlot.Xamarin.Forms' (are you missing an assembly reference?)  OxyPlot.Xamarin.Forms.Platform.Android  ...\OxyPlot\OxyPlot.Xamarin.Forms.Platform.Android\PlotViewRenderer.cs  20  Active
Error   CS0246  The type or namespace name 'PlotView' could not be found (are you missing a using directive or an assembly reference?)  OxyPlot.Xamarin.Forms.Platform.Android  ...\OxyPlot\OxyPlot.Xamarin.Forms.Platform.Android\PlotViewRenderer.cs  20  Active
Error   CS0246  The type or namespace name 'ElementChangedEventArgs<>' could not be found (are you missing a using directive or an assembly reference?) OxyPlot.Xamarin.Forms.Platform.Android  ...\OxyPlot\OxyPlot.Xamarin.Forms.Platform.Android\PlotViewRenderer.cs  51  Active
Error   CS0234  The type or namespace name 'PlotView' does not exist in the namespace 'OxyPlot.Xamarin.Forms' (are you missing an assembly reference?)  OxyPlot.Xamarin.Forms.Platform.Android  ...\OxyPlot\OxyPlot.Xamarin.Forms.Platform.Android\PlotViewRenderer.cs  51  Active


PlotViewRenderer.cs

using Android.Content;
using OxyPlot.Xamarin.Forms;
using OxyPlot.Xamarin.Forms.Platform.Android;

using global::Xamarin.Forms;
using global::Xamarin.Forms.Platform.Android;

// Exports the renderer.
[assembly: ExportRenderer(typeof(PlotView), typeof(PlotViewRenderer))]

namespace OxyPlot.Xamarin.Forms.Platform.Android
{
    using System.ComponentModel;

    using OxyPlot.Xamarin.Android;

    /// <summary>
    /// Provides a custom <see cref="OxyPlot.Xamarin.Forms.PlotView" /> renderer for Xamarin.Android. 
    /// </summary>
    public class PlotViewRenderer : ViewRenderer<Xamarin.Forms.PlotView, PlotView>
    {
        /// <summary>
        /// Initializes static members of the <see cref="PlotViewRenderer"/> class.
        /// </summary>
        static PlotViewRenderer()
        {
            Init();
        }

        /// <summary>
        /// Initializes a new instance of the <see cref="PlotViewRenderer"/> class.
        /// </summary>
        public PlotViewRenderer(Context context) : base(context)
        {
            // Do not delete
        }

        /// <summary>
        /// Initializes the renderer.
        /// </summary>
        /// <remarks>This method must be called before a <see cref="T:PlotView" /> is used.</remarks>
        public static void Init()
        {
            OxyPlot.Xamarin.Forms.PlotView.IsRendererInitialized = true;
        }

        /// <summary>
        /// Raises the element changed event.
        /// </summary>
        /// <param name="e">The event arguments.</param>
        protected override void OnElementChanged(ElementChangedEventArgs<Xamarin.Forms.PlotView> e)
        {
            base.OnElementChanged(e);
            if (e.OldElement != null || this.Element == null)
            {
                return;
            }

            var plotView = new PlotView(this.Context)
            {
                Model = this.Element.Model,
                Controller = this.Element.Controller
            };

            plotView.SetBackgroundColor(this.Element.BackgroundColor.ToAndroid());

            this.SetNativeControl(plotView);
        }

        /// <summary>
        /// Raises the element property changed event.
        /// </summary>
        /// <param name="sender">The sender.</param>
        /// <param name="e">The event arguments.</param>
        protected override void OnElementPropertyChanged(object sender, PropertyChangedEventArgs e)
        {
            base.OnElementPropertyChanged(sender, e);
            if (this.Element == null || this.Control == null)
            {
                return;
            }

            if (e.PropertyName == Xamarin.Forms.PlotView.ModelProperty.PropertyName)
            {
                this.Control.Model = this.Element.Model;
            }

            if (e.PropertyName == Xamarin.Forms.PlotView.ControllerProperty.PropertyName)
            {
                this.Control.Controller = this.Element.Controller;
            }

            if (e.PropertyName == VisualElement.BackgroundColorProperty.PropertyName)
            {
                this.Control.SetBackgroundColor(this.Element.BackgroundColor.ToAndroid());
            }
        }
    }
}


此外,我已经尝试clean project,然后删除bin和obj文件夹,关闭VS和重新打开和重建。仍然存在错误。
你知道吗?先谢谢你。

qybjjes1

qybjjes11#

我已经检查了你提到的nuget包(OxyPlot.Xamarin.Forms)。它太旧了,与.net maui项目不兼容。
所以当你把你的项目从xamarin表单更新到.net maui时,你需要删除它的引用。
也可以参考Using Custom Renderers in .NET MAUI的文档手动迁移PlotView和PlotViewRenderer。

相关问题