SlideShare a Scribd company logo
Cross-Platform Mobile Development
using Visual Studio and Xamarin
Shravan Kumar Kasagoni
Senior Developer - RealPage
Microsoft MVP – VSDT
Microsoft User Group Hyderabad
@techieshravan
Cross-Platform Mobile Development using Visual Studio and Xamarin
Cross-Platform Mobile Development using Visual Studio and Xamarin
Cross-Platform Mobile Development using Visual Studio and Xamarin
Cross-Platform Mobile Development using Visual Studio and Xamarin
Approaches for device development
Native Hybrid
Tool maturity
Device optimized experience
Updatability
Portability across devices
Cross-Platform Mobile Development using Visual Studio and Xamarin
Black Box
CSS | HTML
JavaScript | TypeScript
Native mobile apps are better…
- Performance
- Richness of UI
Cross-Platform Mobile Development using Visual Studio and Xamarin
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…
+
+
-
C# and Xamarin
to the rescue!
How?
Mono
Framework
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.
Bringing .NET to Linux
Windows Linux
Microsoft .NET
.NET Apps
Mono/.NET Core
.NET Apps
.NET on Android, iOS
Linux
Mono
iOS
Mono Touch
Android
Mono for Android
iOS
Xamarin.iOS
Android
Xamarin.Andriod
Xamarin
• Founded in May 2011
• Xamarin has a perpetual license to all Mono IP: Copyrights, patents
and trademarks
• Focused on mobile app development
Bringing .NET to Android
Android Kernel
Mono Runtime
.NET APIs
Apps
Android Bindings
Dalvik Runtime/ART
android.* java.*MCW
ACW
Bringing .NET to iOS
iOS
Mono Runtime
NO RUNTIMES ALLOWED
Bringing .NET to iOS
iOS
App
.NET APIS iOS Bindings
Application Code
Cross-Platform Mobile Development using Visual Studio and Xamarin
Microsoft supports your choice
Desktop apps
Universal Windows apps
Browser-based applications
Xamarin and Visual Studio
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#
C# + XIB C# + AXML C# + XAML
iPhone Android Windows
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
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
Xamarin designer for Android apps
Xamarin designer for iOS apps
Windows
APIs
100%
coverage
with .NET
iOS
APIs
100%
coverage
with Xamarin
Android
APIs
100%
coverage
with Xamarin
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
Demo
Xamarin + C# + Visual Studio
Sharing code
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
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
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
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
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
Xamarin Component Store
Can also get reusable components
from the Xamarin Component Store
which is accessible through the
Components folder in each project
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
Demo
Shared Projects
Demo
Portable Class Library
Thank You

More Related Content

Cross-Platform Mobile Development using Visual Studio and Xamarin

  • 1. Cross-Platform Mobile Development using Visual Studio and Xamarin
  • 2. Shravan Kumar Kasagoni Senior Developer - RealPage Microsoft MVP – VSDT Microsoft User Group Hyderabad @techieshravan
  • 7. Approaches for device development Native Hybrid Tool maturity Device optimized experience Updatability Portability across devices
  • 9. Black Box CSS | HTML JavaScript | TypeScript
  • 10. Native mobile apps are better… - Performance - Richness of UI
  • 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… + + -
  • 13. C# and Xamarin to the rescue!
  • 14. How?
  • 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
  • 20. Bringing .NET to Android Android Kernel Mono Runtime .NET APIs Apps Android Bindings Dalvik Runtime/ART android.* java.*MCW ACW
  • 21. Bringing .NET to iOS iOS Mono Runtime NO RUNTIMES ALLOWED
  • 22. Bringing .NET to iOS iOS App .NET APIS iOS Bindings Application Code
  • 24. Microsoft supports your choice Desktop apps Universal Windows apps Browser-based applications
  • 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#
  • 27. C# + XIB C# + AXML C# + XAML iPhone Android Windows
  • 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
  • 30. Xamarin designer for Android apps Xamarin designer for iOS apps
  • 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
  • 35. Demo Xamarin + C# + Visual Studio
  • 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

Editor's Notes

  1. Device optimized experience: access to any API, performance, full customization per device, use of native controls, etc.
  2. 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
  3. 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.
  4. 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
  5. AOT = http://www.mono-project.com/AOT
  6. 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.
  7. 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.
  8. 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.
  9. Xamarin 3 introduces two great new code sharing techniques for cross-platform apps: Shared Projects Shared 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 Libraries Portable 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.