SkiaSharp SKSvg.Load throws MissingMethodException - xamarin

I use SkiaSharp libraries on my Xamarin.Core/Xamarin.iOS project.
I try to load an SVG file from the Core library like the following;
var svg = new SKSvg();
Assembly assembly = type.GetTypeInfo().Assembly;
using (Stream stream = assembly.GetManifestResourceStream($"{assembly.GetName().Name}.Images.watermark_light.svg"))
{
svg.Load(stream);
}
The code throws on the "Load" step saying "System.MissingMethodException: Method not found: SkiaSharp.SKTextBlob SkiaSharp.SKTextBlob.CreatePositioned(string,SkiaSharp.SKFont,System.ReadOnlySpan`1<SkiaSharp.SKPoint>)"
My configuration:
Device: Debug|Simulator
Linker Behaviour: Don't link
Xamarin.iOS 15.4.0.0
xcode13.2: 8fc41ae82
Rider IDE: RD-221.5591.20
OS: MacOS Monterey 12.4 (21F79)
Libraries
SkiaSharp v2.88.1-preview.79
SkiaSharp.Views v2.88.1-preview.79
Svg.Skia v0.5.14
SkiaSharp.Svg v1.60.0
CoreLibrary/Images/watermark_light.svg(svg path)
I tried to add SKTextBlob reference to LinkerPleaseInclude.cs as well. But, it should not be the case when the linker behaviour is set to "Don't link". Also a added --linkskip argument for the relevant namespace. None of them worked. Any ideas about the issue?
Thanks!

Try updating to version 0.5.16 https://www.nuget.org/packages/Svg.Skia/0.5.16

Related

MvvmCross upgrade from 6.4.2 to 8.0.1

I recently upgraded MvvmCross from 6.4.2 to 8.0.1 version.
Both Xamarin.Android and Core projects have same nuget packages versions.
After upgrading in ViewModel in line: IMvxMessenger mvxMessenger = Mvx.IoCProvider.Resolve<IMvxMessenger>();
I get an error Failed to resolve type MvvmCross.Plugin.Messenger.IMvxMessenger
Has anyone already faced such a problem?
I have never used the 6.4.2 version but u can try to add this on initialize/setup
Mvx.IoCProvider.RegisterSingleton<IMvxMessenger>(() => new MvxMessengerHub());
This works on the 7.1.2 version
It is related to this issue documented on GitHub.
https://github.com/MvvmCross/MvvmCross/issues/4286
onurhazar commented on Oct 8:
We are having the same issue when we try to load MvxMessenger plugin.
It throws an exception at app launch (device only)(iOS). As a
workaround, you can override LoadPlugins method in Setup.cs like
below;
public override void LoadPlugins(IMvxPluginManager pluginManager)
{
base.LoadPlugins(pluginManager);
pluginManager.EnsurePluginLoaded<MvvmCross.Plugin.Messenger.Plugin>();
}

Platform Migration: Error when compiling project

A few weeks ago I started a Firebase course with flutter, and I was programming on a Windows computer, and now I've been using a Mac for a few days, to learn how to make firebase with iOS too. However, I have received these errors, and I do not know if I am missing a file, lines of code or if I have obsolete code. I tried some solutions I found on the internet, like deleting the files pubspec.lock, podfile, podfile.lock, reinstalling using pod init and pod install, but none of these solutions managed to solve the problem. I know very little about Swift / Objective-C, and this project is connected (android) on firebase.
/Users/mobileteam/Desktop/pasta_mary/aikoBot/aiko_bot/ios/Pods/FirebaseCrashlytics/Crashlytics/Shared/FIRCLSFABHost.m100:11: warning: 'UI_USER_INTERFACE_IDIOM' is deprecated: first deprecated in iOS 13.0 - Use -[UIDevice userInterfaceIdiom] directly. [-Wdeprecated-declarations]
switch (UI_USER_INTERFACE_IDIOM()) {
^
In module 'UIKit' imported from /Users/mobileteam/Desktop/pasta_mary/aikoBot/aiko_bot/ios/Pods/FirebaseCrashlytics/Crashlytics/Shared/FIRCLSFABHost.m:20:
/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator14.1.sdk/System/Library/Frameworks/UIKit.framework/Headers/UIDevice.h:97:36: note: 'UI_USER_INTERFACE_IDIOM' has been explicitly marked deprecated here
static inline UIUserInterfaceIdiom UI_USER_INTERFACE_IDIOM() API_DEPRECATED("Use -[UIDevice userInterfaceIdiom] directly.", ios(2.0, 13.0), tvos(9.0, 11.0)) {
^
1 warning generated.
/Users/mobileteam/Desktop/pasta_mary/aikoBot/aiko_bot/ios/Runner/AppDelegate.swift:14:18: error: cannot override with a stored property 'window'
override var window: UIWindow?
^
Flutter.FlutterAppDelegate:2:14: note: attempt to override property here
open var window: UIWindow! { get set }
^
note: Using new build system
note: Building targets in parallel
note: Planning build
note: Constructing build description

Microsoft information protection SDK 1.7.133 - Load library failed issue error

I was using MIP SDK 1.6 before and I initialised MIP by providing Path. It was working fine.
I upgraded to 1.7 version and now its failing with the Load library failed error.
{"Message":"An error has occurred.","ExceptionMessage":"LoadLibrary
failed for:
[C:\inetpub\wwwroot\teststs\bin\x64\mip_dotnet.dll]",
"ExceptionType":"System.ComponentModel.Win32Exception","StackTrace":"
at
Microsoft.InformationProtection.Utils.SafeNativeMethods.LoadLibrary(String
dllToLoad)\r\n at
Microsoft.InformationProtection.Utils.Loader.LoadDlls(String
dllFolder, String dllName, String[] dllDependencies)\r\n at
Microsoft.InformationProtection.MIP.Initialize(MipComponent
mipComponent, String path)\r\n
Can anyone please help ?
Can you share how you are building the path and setting it in MipContext? Something like this should still work. I've tested this in a .NET project on MIP SDK 1.7.133.
// Set path to bins folder.
var path = Path.Combine(
Directory.GetParent(Path.GetDirectoryName(new Uri(System.Reflection.Assembly.GetExecutingAssembly().CodeBase).LocalPath)).FullName,
Environment.Is64BitProcess ? "bin\\x64" : "bin\\x86");
// Initialize MIP for File API.
MIP.Initialize(MipComponent.File, path);

Error message "OpenCV: not authorized to capture video (status 0)" in MacOS QT

I know there were already some similar questions and it seems the question is not arose by OpenCV but by MacOS authority rule.
I have read some solutions, like create a Info.plist into source directory. And that works! But for me now only in Debug mode in QTCreator, not in Release mode. That is, when I run the program in Debug mode, everything is just OK. But in Release mode within QTCreator, the error message shows up:
OpenCV: not authorized to capture video (status 0), requesting...
16:12:22: The program has unexpectedly finished.
Some more strange informations. The program, say Test.app which is generated by QTCreator in Release or Debug mode, can be executed by directly double clicking on it or on the executable file residing in Test.app/Contents, after authorized for sure.
Additional System Information:
macOS Catalina Version 10.15.4
Qt 5.14.2
OpenCV 4.3.0
Also the Info.plist
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist SYSTEM "file://localhost/System/Library/DTDs/PropertyList.dtd">
<plist version="0.9">
<dict>
<key>NSCameraUsageDescription</key>
<string>uses camera to see vision targets</string>
</dict>
</plist>
Some codes may be helpful. FYI, the program crashes before the Camera class created.
// camera.cpp
std::shared_ptr<Camera> Camera::Ptr = nullptr;
void Camera::CreateCamera()
{
if(!Ptr)
Ptr.reset(new Camera);
}
Camera::Camera()
: _device(1)
{
}
bool Camera::GrabMerged(cv::Mat &img)
{
if(_device.isOpened())
{
cv::Mat tmp;
_device.read(tmp);
if(tmp.empty())
{
qWarning("[Camera] Grab image failed.");
return false;
}
qInfo("[Camera] merged image info: cols=%d, rows=%d, channels=%d, step0=%luļ¼Œstep1=%lu, type=%d",
tmp.cols, tmp.rows, tmp.channels(), tmp.step[0], tmp.step[1], tmp.type());
cv::cvtColor(tmp, img, cv::COLOR_RGB2BGR);
return true;
}
qCritical("[Camera] Camera is not opened.");
return false;
}
...
// camera.h
class Camera: public QObject
{
...
private:
cv::VideoCapture _device;
...
}
In case helpful for others.
Qt Creator > Projects > Run > Environment > add OPENCV_AVFOUNDATION_SKIP_AUTH 0 , then you will get the MacOS prompt "QtCreator wants to access the camera". I'm running macOS 11.4
Thanks for taking time to push a minimal project that allow to reproduce the error.
After some test, it appears that this project works fine when started from command line or by double-clicking on the app bundle icon (both in Release and Debug mode). In the later case, system ask for permission to use the camera when clinking on the open button. Once permission is granted, we need to click again on the button, this is an expected behavior with OpenCV VideoCapture on macos.
But when I start it from Qt Creator, I had this weird message :
dyld: Symbol not found: __cg_jpeg_resync_to_restart
Referenced from: /System/Library/Frameworks/ImageIO.framework/Versions/A/ImageIO
Expected in: /usr/local/lib/libJPEG.dylib
in /System/Library/Frameworks/ImageIO.framework/Versions/A/ImageIO
18:29:38: The program has unexpectedly finished.
This is not the same as yours but that shows that there is some difference between normal execution and execution from QtCreator.
And in my case, Qt Creator is the culprit.
And after disabling the DYLD_LIBRARY_PATH variable under the Run environment (Projects Settings -> Run -> Environment), it works fine from QtCreator. Hourah !
My settings looks like :
This is with Qt Creator 4.12 / Qt 5.14.2 / OpenCV 4.3.0

How do I bind to a system framework with Xamarin.Mac?

I'm in the proces of making an app for interacting with smartcards.
For that I'd like to use the CryptoTokenKit Framework which is standard on a Mac (located at /System/Library/Frameworks/CryptoTokenKit.framework).
This link says that it's possible to bind frameworks in a Mac project:
https://developer.xamarin.com/guides/cross-platform/macios/native-references/
I've created an ApiDefinition.cs file and a StrucsAndEnums.cs file using the following sharpie command:
sharpie bind -framework ./CryptoTokenKit.framework -sdk macosx10.13 -o ~/CryptoTokenKitBinding
I can't find any info on the internet how to implement the above mentioned files and start using the framework.
Create a Xamarin.Mac binding project within a solution.
Add a NativeReference to:
/System/Library/Frameworks/CryptoTokenKit.framework
Bind it using sharpie:
sharpie bind \
-o CryptoTokenKitFramework \
-namespace CryptoTokenKit \
-sdk macosx10.13 \
-f /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk/System/Library/Frameworks/CryptoTokenKit.framework
There is a mismatch between the binding project template and the output of sharpie, so you can either delete ApiDefinition.cs and add ApiDefinitions.cs or just overwrite the template created one:
mv CryptoTokenKitFramework/ApiDefinitions.cs CryptoTokenKitFramework/ApiDefinition.cs
There will be a number of attributes like (versions will change across them):
[Watch (4,0), TV (11,0), Mac (10,12), iOS (10,0)]
As these are private frameworks on iOS, Watch, TV, so strip those platforms out. Leave the Mac attribute and the original version:
[Mac (10,11)]
Note: PlatformAttribute is obsolete but sharpie is still using it (assuming backwards version compatibility(?)), so you can use Introduced if you really want to clean up the build output:
[Introduced (PlatformName.MacOSX, 10, 11, PlatformArchitecture.Arch64)]
There will be a few [Verify] attributes that have to be reviewed/corrected. i.e. TKSmartCardUserInteraction.Cancel and TKSmartCardSlot.MakeSmartCard should both be methods not properties.
Example / Generated:
// -(TKSmartCard * _Nullable)makeSmartCard;
[NullAllowed, Export ("makeSmartCard")]
[Verify (MethodToProperty)]
TKSmartCard MakeSmartCard { get; }
Corrected:
// -(TKSmartCard * _Nullable)makeSmartCard;
[NullAllowed, Export("makeSmartCard")]
TKSmartCard MakeSmartCard();
Fix the rest of the [Verify] attributes and compiler errors, there are a bunch of bad method signatures, pointers, return types, etc.. that are generated and need corrected.
Note: TO make your life easier, make sure that you are using the latest Sharpie version:
Version: 3.4.0
SHA1: c12859dac8d43121b5a9ed866a0db8409f9df817
URL: https://dl.xamarin.com/objective-sharpie/ObjectiveSharpie-3.4.0.pkg

Resources