Search code examples
androidxamarinxamarin.formsskiasharp

System.MissingMethodException: Default constructor not found for type SkiaSharp.Views.Forms.SKCanvasView?


I am trying to Use Skiasharp on Android, and I get this exception, what could be the reason?

Code:

<skia:SKCanvasView x:Name="canvasView"
               PaintSurface="canvasView_PaintSurface"
               EnableTouchEvents="true" 
               VerticalOptions="FillAndExpand"
               Touch="OnTouch"/>

On C# file

private void canvasView_PaintSurface(object sender,SKPaintSurfaceEventArgs args)
        {
            SKSurface sKSurface = args.Surface;
            SKCanvas canvas = sKSurface.Canvas;
            canvas.Clear(SKColors.White);
            drawPerformerPlatforms.setCanvas(canvas);
            scoreViewerField.runFrame();
        }

Solution

  • Setting linking to None is a workaround and not a real solution. The problem in your case is that Linker removing the references to Skia classes. You need to preserve the Skia library during the linking process. Please refer to the following article for more information.

    https://learn.microsoft.com/en-us/xamarin/android/deploy-test/linker