12. Using the platform’s native tools
(Siloed approaches are long term problems)
Xcode ADT Visual Studio End user
experience
Better productivity and
global developer experience
✗
Building native apps multiple times
when targeting multiple platforms!
…very expensive,
not sustainable…
+
+
-
16. What is Mono?
• Open source implementation of the .NET platform created by
Ximian (ECMA 334/335)
• 2001: Created to bring Windows applications to Linux
• 2003: Acquired by Novell with Ximian
• Matured at Novell in research mode; now a world-class runtime.
17. Bringing .NET to Linux
Windows Linux
Microsoft .NET
.NET Apps
Mono/.NET Core
.NET Apps
18. .NET on Android, iOS
Linux
Mono
iOS
Mono Touch
Android
Mono for Android
iOS
Xamarin.iOS
Android
Xamarin.Andriod
19. Xamarin
• Founded in May 2011
• Xamarin has a perpetual license to all Mono IP: Copyrights, patents
and trademarks
• Focused on mobile app development
26. Black Box
C# in Xamarin
+ Visual Studio
iPhone native (C# and XIB)
Android native (C# and AXML)
Windows Store (C# and XAML)
Native apps and cross-platform
UI (C# and Xamarin.Forms)
Cross-platform with C#
28. Xamarin.iOS does full ahead-of-time
(AOT) compilation to produce an
ARM binary suitable
for Apple’s App Store
Xamarin.Android takes advantage
of just-in-time (JIT) compilation on
the Android device
Native cross-platform apps with Xamarin
Native compilation, native performance
29. C# unique approach powered by .NET and Xamarin
The best of both worlds (UX & TCO)
Great native apps delivered
to the user’s choice of device
Development agility, with
Visual Studio to move at
mobile speed
34. Maximizing code reuse across platforms
Views
How to display information
View models
What information to display
Flow of interaction
Models
Data objects
Business logic
Etc.
Model
View Model
View Device-specific
Portable codeReferences
Databinds
Implemented in
PCL or shared project
37. Sharing code
One of the main reasons to use
Xamarin is the possibility of sharing a
significant portion of your code
across all your supported platforms
38. Sharable Code
Xamarin applications are
native and therefore will
always include some
platform-specific code
30%
70%
iOS
14%
86%
Android
15%
86%
Windows Phone
Platform Specific
Cross Platform
39. Where can I use shared code?
Anytime you are writing code which does not depend on a specific platform
feature, it is potentially sharable, particularly if it:
• Talks to a web service
• Parses a data format
• Uses a database
• Performs processing or logic
Create shared classes + methods and then use them from your platform-
specific code to maximize the shareable surface area
40. Where can I use shared code?
Data Access (Database)
• SQLite support available for iOS, Android and Windows
• Can also store in the cloud – Azure Mobile Services, Amazon, Dropbox, etc.
Web Services
• Use HttpClient for REST services
Xamarin.* Libraries
• Xamarin.Social
• Xamarin.Auth
• Xamarin.Mobile
Open-Source, Cross-Platform APIs available from Github.com/Xamarin
41. When is code not sharable?
If the code you are writing depends on device or platform-specific APIs, or
APIs not available in your project, then you will need to isolate it's use or
provide some kind of abstraction to use it from your shared code
• Access system information
• Use files and folders on the device
• Access personal information
• Use external devices
42. Xamarin Component Store
Can also get reusable components
from the Xamarin Component Store
which is accessible through the
Components folder in each project
43. Available project types
There are two project styles available for sharing code – which one you
select has an impact on how and what kind of code is shared
Shared Project Portable Class Library
Device optimized experience: access to any API, performance, full customization per device, use of native controls, etc.
This preview adds new project templates and tools for you to target the Apache Cordova project within Visual Studio. It is built on top of the existing great HTML, CSS, and JavaScript tooling in Visual Studio, but it integrates it with Apache Cordova. So you have things like Intellisense support for the Cordova API, the ability to build for any targeted platform such as Android and directly from Visual Studio, and the ability to run and debug the app on a device emulator or a remote device.
The cool thing about these tools is that you will naturally know how to use it if you are familiar with web development. It supports TypeScript, which is very handy for these applications that can get very complex. It also supports the most popular JavaScript frameworks that you are probably using already for your mobile web applications such as Angular, JQuery Mobile or Backbone.
Now you have the option to choose the multi-device strategy that is better for you:
Native development with .NET
Hybrid development with HTML and CSS
First is the silo approach.
This is very common, where you see a company or developer creating an app multiple times in different languages with different tools.
Expensive, multiple teams, takes more time.
Biggest issue -> future maintenance in different platforms.
Fully native apps written in C#
Share on average 75% source code across platforms
Even higher with xamarin.forms
C# + .NET Runtime
Native UI
Native Performance
AOT = http://www.mono-project.com/AOT
If you are a Windows developer you will be used to these name spaces.
These are the core .NET base libraries that we know and love.
If you mix in Windows Phone and Windows Store development, you get new namespaces.
Windows. And Microsoft. With platform specific APIs.
Xamarin gives you the best of both worlds with full support for the .NET Framework (your System. Libraries).
Then they create C# bindings for every API in iOS and Android.
As you can see here there are a few, CoreGraphics, CoreMotion, etc.
These are your platform-specific bits to take advantage of everything in iOS.
Then they do the same thing for Android so here you get the Android specifics.
Renderscript, NFC to do cool phone tapping of data transfer.
And text to speech APIs to make your app shine.
Xamarin 3 introduces two great new code sharing techniques for cross-platform apps:
Shared ProjectsShared Projects provide a simple, clean approach to code sharing for cross-platform application developers. Xamarin developers can now use Shared Projects to share code across iOS, Android, and Windows in either Xamarin Studio or Visual Studio.
Portable Class LibrariesPortable Class Libraries are libraries that are consumable across a diverse range of .NET platforms. Xamarin 3 can both produce and consume PCLs from both Xamarin Studio and Visual Studio.
In our demo app we’re using a PCL to share code across all the different platforms, including Windows apps, iOS, and Android.
Shared Projects between many different platforms/projects (more than two) might be a bit confusing because you need to have many different #if precompiler conditions, since the Shared Projects is nothing more than a link to a whole project.