Use a Xamarin library in native iOS/Android apps - c#

We are using xamarin for a while now and developed different apps/libs with it. Now we need to integrate one of the core libraries/component we developed during the last years in native apps. Background: We do a project with a partner who is using native development and we need to integrate our library in his environment/his apps.
So there will be two native apps (iOS/Android) and our core library will be part of them. The question therefore: Is there a way to integrate a xamarin library (or simply C# code, written with xamarin) into the two native apps? Or do we need to completely rewrite the code in Java/Swift?
The library has no third-party libraries except ofc the .NET framework.
Thanks for sharing your experience in this matter!

AFAIK there is no way to take a Xamarin .NET library and use it in a native (Java/Obj-C/Swift) platform app.

Related

what are my options for multiplatform GUI applications in C#?

Keep in mind that although I know how to code, I am NOT a professional developer. moving on:
I am looking to create a simple GUI program for an embedded system that runs on both Linux and windows. The issue is, the person responsible for developing the applet insists on it being written in c#. I can run .net framework code through mono, and the .net core is multiplatform by design, but he was going to use UWP, and that obviously won't work on Linux. I have looked into Avalonia, but it is not compatible with the version of .net he uses. He told me that QT apparently won't work for some complex reason b/c we are just running a local app and nothing web-connected or even from a server. To be very clear, I need cross-platform GUI in c#. I am also not asking what the best option is, just what possible options even exist. I and the dev will go from there.
thx in advance, RUWO
You have some options which depending on your needs might work well, I would go with AvaloinaUI, but here are your options:
Avalonia Is a WPF-inspired cross-platform XAML-based UI framework providing a flexible styling system and supporting a wide range of OSs: Windows (.NET Framework, .NET Core), Linux (also ARM), MacOS. Android and iOS are on the Roadmap.
There is also a functional wrapper for Avalonia https://github.com/AvaloniaCommunity/Avalonia.FuncUI that makes using it from F# a charm.
Gtk#
is a Graphical User Interface Toolkit for mono and .Net. The project binds the gtk+ toolkit and assorted GNOME libraries, enabling fully native graphical Gnome application development using the Mono and .Net development frameworks.
Eto This framework can be used to build applications that run across multiple platforms using their native toolkit, with an easy to use API. This will make your applications look and work as a native application on all platforms, using a single UI codebase.
CoreUI/LibUI Bindings to portable C Library. Simple and portable (but not inflexible) GUI library in C that uses the native GUI technologies of each platform it supports.
QtSharp Mono/.NET bindings for Qt
This project aims to create Mono/.NET libraries that wrap Qt (https://qt-project.org/) thus enabling its usage through C#.
Avalonia is currently heading towards version 1.0 but it's already stable. I am using Avalonia now since about a year, and my experience is pretty good so far. The community around it is growing fast, and the core developers are very active in the official gitter chat.
.NET Maui is now an option as of recently, and is developed by Microsoft.

How to use C# dll in UWP

I have a C# dll compiled in .net framework 2.0 and the library is not been updated by the vendor till now. In one of my desktop application C# i was using that and when i migrated the application to WPF, the same libraries where referred and working fine. Now, the application required new diversion, as it should be upgraded to UWP and the same dll i want to make use in that also. What is the best and easiest methods available in UWP to import.Net Framework 2.0 dll ?
Regards,
Lal
You can create a .NET Standard 2.0 library project that can reference the legacy library and you can then reference this .NET Standard 2.0 project from you UWP app.
In the .NET Standard library, you can write custom types that access the legacy library and provide a "middleware layer" between the UWP app and the legacy library.
What is the best and easiest methods available in UWP to import.Net Framework 2.0 dll ?
You can not direct consume any full .NET Class Library from UWP app, there is some security restrictions. UWP project can reference libraries such as Universal Windows Class Library,.NET Standard library, Windows Runtime Component and so on.
For solving this, since your app is for desktop devices and you already have a WPF app, I recommend you to convert the WPF app to UWP app by using Desktop Bridge. Or you could try to convert the old dll into one of above the libraries that can be referenced by UWP app. If you do only want to consume the .Net framework dll, you may try to create COM Proxy Stubs and work with them as communication layer, here is the official sample.
One solution for this is to make a windows service and use that dll in service. You can reference that service from UWP application in order to make all the API calls.

Can a Cordova plugin make calls to a .Net Framework .dll?? Not WinRT Component (.Net Core)?

I have a .dll that was written to target the .NET Framework. I need to create a Cordova plugin that can make calls to this .dll.
Our Cordova App runs on a Windows 10 Tablet.
Because this .dll targets .NET Framework and not .NetCORE, I cannot take the approach of a WinRT component that's suggested in all of the guidance I've seen.
Is it possible to have a Cordova plugin that makes calls to a .NET Framework .dll and if so can you recommend a correct approach?
Disclaimer: I'm in the weeds with Cordova. I'm learning as I go. An EXAMPLE would be overwhelmingly appreciated.
Thanks
No on both form and function. You'll need to use a .Net library that works with .Net Core for UWP.
Form:
Cordova apps on UWP run in the native JavaScript environment, not in a WebView hosted in a C# app. The only way for a UWP JavaScript app to call .Net functions is via a Windows Runtime Component (WRC).
While you could (in theory) write a version of Cordova for Windows Runtime that uses a .Net hosted WebView I'm not aware of any existing ones. (The Windows Phone 8 versions Hassan Ali linked do use a Silverlight WebBrowserControl, but don't run on Windows 10 tablets).
Function:
Even if you did change the Cordova host to .Net so it could call .Net directly without a WRC that would still run in the UWP context.
UWP apps can use only NetCore, not the full .Net Framework, whether they are direct .Net apps or call .Net inside a WRC.
Apache Cordova is a platform for building native mobile applications
using HTML, CSS and JavaScript
So no, you can't call .NET assemblies directly on the client. You have to put them in a plugin. You can find some samples for Windows Phone here. Another sample in this SO question.

Can a C# program be cross-platform?

I'm a newbie to programming, and I'm considering using C# to write a VERY simple program that simply edits a text file.
Will it work on Macs and Linux? What will work?
I want to know what makes a program cross-platform?
C# can be compiled for and ran on multiple platforms (Windows, Linux, macOS) by using .NET Core.
Previously, cross-platform development using C# could only be done by using Mono which is a third-party implementation however it is now recommended to use .NET Core as it is developed by Microsoft.
Now C# is fully cross platform and has variety of frameworks and run times.
Java is a language + framework. But C# is just a modern language. C# language features are very powerful, easy to learn. No confusion between framework and language.
C# can be used in following frameworks
.Net core (Multi platform supports Linux, Windows and Mac), mostly used to develop restful services, web applications and enterprise systems
.Net Framework (Windows only), Same as .net core, but has more windows only features
Unity - One of most used game engine to develop games for PC, Sony, Xbox devices etc..
Xamarin - To develop native Mobile apps (Android, IOS, Mac)
.Net standard - Create a library in .net standard use in all above applications
Java - Code once, Ship same file to all platforms
C++, C, Rust - Code once, Compile for specific platform
C# - It is just a language, pick your framework according to requirement.
Most popular applications like Chrome, Firefox uses C++, Rust and they are compiled for each platform. But still they share the majority of code between these platforms. Some games use C++ to share the code between IOS and Android.
For new developers its good to start with NodeJS and C#. Both are easy and can do any type of applications.
It's hard to answer something like that to somebody, which states that he just starts programming, but I'll try to give you an (somewhat simplified) overview: C# is a language, which is compiled into an executable program. The language itself is portable between plattforms, as long as you have a compiler on each target plattform. On Windows you have the "default" .Net implementation and on Linux/Mac you have Mono. To do something useful - like editing files - you have to use some libraries. There is a standard library which is available on each plattform. As long as you use only that functionality, your program will be cross plattform. Obviously is will not be cross plattform, as soon as you use some library specific to a certain plattform. Editing files is part of the standard library, so you can implement such simple tools in a cross plattform way. When choosing a book, you should look for books which focus on the "raw" language and not on Visual Studio or other specific tools.
A new open source release from Microsoft called CoreCLR is cross-platform and can now be used for this
The CoreCLR repo contains the complete runtime implementation for .NET Core. It includes RyuJIT, the .NET GC, native interop and many other components. It is cross-platform, with multiple OS and CPU ports in progress.
-from the CoreCLR repo
I would not recommend c# as the top choice for multiplatform coding. I would recommend python instead it is very easy to run even as a script and works perfectly on all platforms. If you insist on c# be prepared to deal with the same problem explained by Justin Ethier. Python on the other hand, is the same for all platforms, it is super powerful fast and even has wrappers ready to connect to other languages.
C# is cross-platform thanks to .NET Core, but without a cross-platform User Interface library you can only make very basic console programs with it. In order to make cross-platform apps for Windows, Mac and Linux you need a cross-platform User Interface library like Nevron Open Vision
Yes, C# is fully cross-platform thanks to .NET Core.
.NET Core is a free and open-source, managed computer software framework for Windows, Linux, and macOS operating systems. It is the cross-platform successor to the .NET Framework which only run on Windows. The project is primarily developed and supported by Microsoft (through the .NET Foundation).
C# is cross platform and you can run your program in Windows/Linux and Mac. For Linux, though, you need to run it using mono

Can I use a Windows -> Class Library inside a WP7 application?

I'm creating a library application that will act as a wrapper for an exposed API. This library ideally should work on any desktop application, but truth be told I'm intending to use this on the WP7 once I'm done creating the library.
Would this work?
From silverlight.net:
Silverlight is the application development platform for Windows Phone 7. High performance gaming is also supported through the XNA Framework.
You can't reference a .NET assembly which was compiled against the full .NET Framework in a Silverlight application.
Develop your library for Silverlight and all should be fine.

Categories

Resources