Every mobile application requires access to native functionality. When developing native mobile apps with Xamarin, developers are able to integrate deeply into iOS and Android since Xamarin exposes every API directly in C# to access these features. To help streamline and simplify development when needing to add native features to apps we are pleased to introduce Xamarin.Essentials, a new library that abstracts these native APIs into a set of cross-platform APIs. This means that you now have access to over 30 native features from single APIs that can be called directly from your shared business logic.
Features That Apps Need
With Xamarin.Essentials we worked directly with the development community to see what features are commonly used and should be in the initial release. This includes some fantastic APIs such as:
- Connectivity: Check connectivity state and detect changes.
- Device Information: Find out information about the user’s device.
- Geolocation: Retrieve the device’s GPS location.
- Secure Storage: Securely store data on device.
- Version Tracking: Track your applications version and build numbers.
These are just a few of the awesome features included in Xamarin.Essentials. Be sure to browse through our full documentation to see everything that is packed into this library.
Finely Tuned & Optimized
One question that I often get when talking about Xamarin.Essentials is since it includes so many features and APIs won’t it bloat my application. The answer is absolutely not! We developed Xamarin.Essentials to be fully “linker safe” across each platform. What this means is if you only use one feature from Xamarin.Essentials such as Geolocation that when you build your application in release mode, the Xamarin linker will strip away any unused code from Xamarin.Essentials. Another advantage of using Xamarin.Essentials is that it is a single assembly which can help reduce application startup time in some situations.
As a test case I recently upgraded the GeoContacts app from several plugin libraries to Xamarin.Essentials. It reduced the number of assemblies from 47 to 35 and even reduced the application size from 22.7MB to 22.2MB when fully built and packaged. If you are using several plugins for Xamarin and looking to make the switch to Xamarin.Essentials I wrote a handy transition guide on my blog.
Amazing Community Contributions
Xamarin.Essentials is fully open source on GitHub and we have seen some great enhancements through community contributions. These include several that in the GA release such as enhancements to Preferences, WiFi signal strength, debug information, multiple SMS recipient support, barometer, and many more. We have even seen additional helper libraries pop up around Xamarin.Essentials including Ryan Davis’s project to generate interfaces.
If you have a great idea for an API that you want to see in Xamarin.Essentials head over to the GitHub and start a discussion today.
Getting started with Xamarin.Essentials is simple as installing a NuGet package and adding a few lines of initialization code in select projects. Please read through our full getting started documentation for a step by step guide on full setup. In the future setup will be even easier as we will be integrating the library into every Xamarin template with Visual Studio 2019.
If you want to test out Xamarin.Essentials today on your Android you can download our sample app from App Center and give it a spin.
Essential API of the Week
Each week on my video series, The Xamarin Show, I cover a new topic in the world of Xamarin and have guests to show off their amazing libraries that they have been creating. To kick off the new year I will be starting another weekly edition of The Xamarin Show covering a different API of Xamarin.Essentials that I call “Essential API of the Week”. Be sure to subscribe on Channel 9 or on YouTube so you get notified when the first entry is release on January 8th, 2019! We hope that you love Xamarin.Essentials and look forward to hearing your feedback and continue to add even more cross-platform native features to the library.