Why should I use portable class libraries with Xamarin? - android

I am currently evaluating Xamarin for my company with the goal to develop iOS and later on maybe Android applications. (Windows Phone or Windows store apps are not a concern for us). We are thinking of putting shared functionality into a common library and according to the Xamarin Docs PCLs are the way to go. However why can’t I just create normal .net class libraries and reference against them?
Mono serves as the base for Xamarin and has in most areas a quite mature implementation of .net Framework which should be both available on Android and on iOS since it is part of Xamarin.
Am I missing some important fact or are PCLs only needed when I also want to develop Windows Store applications?

Regular .NET libraries support a single target framework. The .NET framework used by Xamarin iOS is not the same as the one used by Xamarin Android, or Windows Phone, etc. They all use different subsets and variations of the "full" framework. So a dll compiled against one flavor of the framework will not work with a different target.
PCLs avoid this by allowing you to target multiple frameworks and use the intersection of functions that they all support.

PCLs are one of the two ways of sharing code between platform-specific projects in Xamarin (the other being Shared Projects). They allow you to target multiple platforms, but you end up working with a smaller set of assemblies.

Related

What programming language(s) does both iOS and Android support?

I want to make a mobile app, but I app very new to the field. I am looking for what language I should go for. I know that iOS supports Swift and Objective-C. Android supports a range of languages, but Kotlin or Java are best. However, it seems that C# is supported on both iOS and Android (but I can't find a solid statement). I am also open to (free) converters. In terms of the app, I have these requirements:
Make HTTP/HTTPS requests
Text rendering
Basic Audio Capabilities
Image Rendering
Buttons (optional)
What would be the optimal language? I don't want an opinion as much as I want a simple list. If there is no such language that supports both systems, what would be the easiest two languages to port between? Thanks in advance!
Let prefer Flutter framework (Dart language), by Google. It is quite similar with web development but support multi platforms.
https://flutter.dev/
Generally speaking, there are 3 popular options, with widespread use and community support:
Flutter framework (uses Dart)
React Native (uses JS)
Kotlin Multiplatform (business logic in Kotlin, UI can be drawn natively for the platform)
If you're still not satisfied with these frameworks, other options would be:
Xamarin (uses .NET/C#)
Ionic (uses JS)
There are two good cross platforms for developing application on both ios and android
Flutter
KMM (kotlin multiplateform mobile)
Flutter uses dart language and KMM uses Kotlin language for development.
flutter is evolving rapidly while KMM is getting attraction of developers after the release of android jetpack compose.
It is also possible to use c++ both for Android and iOS.
Meanwhile most of the code can be shared between different platforms, there could be platform specific differences; like hardware accelerated graphics, permission handling or file handling.
Starting points:
Share a library among platforms
Microsoft learn for cross platform app

Using JNI FOR IOS and Android

Is it Reccommended to use JNI and C++ Code to make a shared library code between IOS and Android ?
I'am asking this because i think it not just saves us plenty of wasted time for implementing same logic in both platforms but also we will have the speed of a C++ core Backing the logic-process of our modules.
Update :
I ask my question in another way :
is it recommended to share a C++ Library for core functions of Android And IOS versions of a similar app ? or it would be better to completely migrate the codes to a multiplatform language ?
Since I remember my needs back then, I know that hybrid apps were not an option, Also JNI is not used for making cross-platform apps but the best use is to drive hardware peripherals via native UNIX scripts for Android or run c++ code on Android. So if we omit PhoneGap, Appcelerator, Ionic etc we will be facing several cross-platform technologies that have attracted many developer attentions so far.
Xamarin:
The framework was founded by the same people who have created Mono, an Ecma standard-compliant, .NET Framework-compatible set of tools. Xamarin offers developers a single C# codebase that can be used to produce native apps for all major mobile operating systems.
Unlike many other frameworks, Xamarin has already been used by over 1.4 million developers from around the world. Thanks to Xamarin for Visual Studio, developers can take advantage of the power of Microsoft Visual Studio and all its advanced features, including code completion, IntelliSense, and debugging of apps on a simulator or a device. Xamarin Test Cloud makes it possible to instantly test apps on 2,000 real devices in the cloud. This is by far the best way how to deal with the heavy fragmentation of the Android ecosystem and released bug-free apps that work without any major issues.
But being honest I didn't enjoy my first time face-to-face meeting with Xamarin. There were so many bugs and also speed and performance problems were bothering.
React Native
React Native is developed by Facebook and used by Instagram, Airbnb, Walmart, Tesla, Baidu, and many other Fortune 500 companies. It is an open-source version of Facebook’s React JavaScript framework. Because React Native uses the same UI building blocks as regular iOS and Android apps, it’s impossible to distinguish a React Native app from an app built using Objective-C or Java. As soon as you update the source code, you can see the changes instantly manifest in an app preview window. Should you ever feel the urge to manually optimize certain parts of your application, React Native lets you combine native code with components written in Objective-C, Java, or Swift.
The ones I mentioned above are not the only options, but since now they are the most used frameworks between programmers. But beware that Flutter is being publicly announced by Google in Google IO and maybe it may be going to create a hit soon.

How to cross compile a mobile SDK?

I have a sophisticated NLP engine that I wish to make available on mobile as an SDK for developers to use. The engine is currently a hybrid of multiple languages but we are looking to rationalise it to a single language and codebase. The answer to this question will influence the choice of language.
In particular, I wish for iOS developers to be able to call the engine using Objective C (Or perhaps Swift) and android developers to be able to use the engine in Java.
I do not want to port my engine and maintain two separate codebase for the core NLP algorithms.
While there are many options for cross compiling applications, such as Xamarin, Apportable, or even Phonegap. but none that I could see that would make it easy to cross compile an SDK.
What approach could I take so that my core engine is cross compiled from a unique code base while still providing good Java and Objective C bindings?
I do not want to port my engine and maintain two separate codebase for the core NLP algorithms
Then you need to write it in C or C++ and ensure that your code does not do anything platform-specific.
Then, you can write wrappers for it as needed, such as a JNI wrapper for use with the Android NDK, so Android developers can use your library via your wrapper's Java API.
I am not an iOS developer, and so I do not know what you might need to make a C/C++ library readily consumable via Objective-C (let alone Swift), though I imagine that there are some recipes for doing that.

ICU for Mobile(iOS/Droid) devices

Since both iOS and Android use ICU under the hood and provide some functionalities provided by ICU in their own API, Is ICU important in mobile app development. I am looking for best practices in mobile app development considering a scenario where i want to develop cross platform(iOS, Android) apps. Will there be any benefit in compiling ICU for both iOS and Android ( One i see is similar API's in Code base of app) and using them instead of using ios/android API.
How do app developers who develop both for iOS and Android go about their g18n requirements.
Thanks
I am developing a cross-platform (iOS + Android) app that uses ICU very heavily.
According to the team that create the data for the apps neither the Android or iOS built in versions implement enough of the features for us to use it.
So I have had to compile it for iOS and Android.
In iOS this proved to be relatively easy, I forked: https://github.com/zhm/icu-ios and followed the instructions.
In android I had to use: https://github.com/android/platform_external_icu4c and build it using the NDK.
I had issues building because the default Android.mk files don't work correctly and there are settings in Application.mk that need to be set, neither of which are mentioned in the help files.
On top of that the NDK doesn't let the .dat file be included in the library, so I needed to also mmap that.
I would suggest that on an app-by-app basis you decide if you can live with the built in features or not, because building the full version for Android is not pleasant.

MVVMCross (WP8, Android, iPhone) + Azure Mobile Service

I need to create an app for WP8, Android and iPhone that uses the Azure Mobile Service. I am really impressed by the MvvmCross project so I really want to use it.
Before starting I have some questions:
Can I add the AMS SDK to the .Core project and will it work for all platforms?
Is the a easy way to handle the login views for the authentication providers on the different platforms?
I am a little bit confused by the profiles, which one should I use?
I would really appreciate if anyone can answer my questions,
Michi
Can I add the AMS SDK to the .Core project and will it work for all platforms?
The Core project is a Portable Class Library.
If you want to use Azure Mobile Service SDK in it, it means you need to add it as a reference to the Core PCL, which means the AMS SDK needs to be a PCL also.
Further more, if you need it for all platforms (Windows Store, Phone, iOS, Android) this means the AMS PCL needs to have an implementation which works on all these platforms.
Looking to https://github.com/WindowsAzure/azure-mobile-services, it looks like the PCL is ony for Windows 8 and Windows Phone 8.
There is however a Xamarin component for Azure Mobile Services, but it's not a PCL (if you download it and check it, there's a separate DLL for Android and iOS):
http://components.xamarin.com/view/azure-mobile-services/
http://www.windowsazure.com/en-us/documentation/articles/partner-xamarin-mobile-services-ios-get-started/
If you want to have a portable functionality in the Core to be used by the view-models, what you can do is define an service interface like IMyAMSClientService in the Core and have it implemented on each platform (you implement MyAMSClientService on each platform, in the app project). You will need to think about a mechanism to handle the AMS functionality in an unified way.
Is the a easy way to handle the login views for the authentication
providers on the different platforms?
Like I said above, you can have something like an IMyAMSClientService in the Core. The actual implementation of it will be on each platform and it will do the calls to the AMS SDK.
I am a little bit confused by the profiles, which one should I use?
I assume you refer to PCL profiles?
You don't need to use anymore any hacks to get the Xamarin profiles available when you create a PCL. Did you try to create a PCL? The Xamarin profiles should be there. You need to have Xamarin installed though.

Categories

Resources