In a 3 hours talk, I have covered some pros and cons about going the native way, the HTML\JS\CSS hybrid way, and of course, Xamarin.
Most of the talk focused on Xamarin approach, gory implementation details, cross-platform architecture, code sharing ‘tactics’, MvvmCross, tips and more.
2. Agenda
Mobile Market Review
iOS vs Android vs Windows (PhoneStore)
JavaScript, CSS, HTML 5 alternative
Xamarin approach
The magic behind
Cross-Platform Application Architecture
Code-Sharing ‘tactics’
Components store/open source components
Tips, tricks and others caveats
3. Mobile Platforms
iOS
Android
• Storyboards
• Objective C
• Xcode
• XML-based UI
• Java
• Eclipse/Android
Studio/IntelliJ IDEA
Windows
Phone/Windows
8
• XAML-based UI
• C#, VB, C++,
JavaScript
• Visual Studio
8. Targeting all major platforms
Theoretically, can provide the best UX, but
Comes with a great cost
Acquire specialties with at list three different
technologies
No code sharing
Every feature, bug, needed to be implemented
several times
12. Xamarin
Founded in 2011 by Novell ex-employees
Based on the Mono project – launched on 2001
Brings the .NET Framework to Linux and OS X
Stable, great performance, tooling, huge code base
Xamarin took it to the next step: all major
platforms – iOS, Android, Linux, OS X
13. Why Xamarin?
Write in C#
Write in C#!!
100% platform API coverage
Same-day support for all new API’s
Average of 75% code sharing!
You can keep using Visual Studio
And your favorite extensions
or you can use the free Xamarin Studio
All latest C# goodness – LINQ, asyncawait, TPL
14. Boring, yet important
Officially partnered with Microsoft
MSDN special plans
Over 460,000 developers live, 20,000 paying
customers, 120 consulting partners
Used by more than 20% of Fortune 500 companies
Great documentation and tutorials
Very responsive community and forums
Reuse your company’s current development
investment
17. Where is the magic?
Xamarin.iOS - 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 compilation right on
the Android device
18. Xamarin on iOS (monoTouch)
AOT – Ahead Of Time compilation (no JIT)
Support ARMv6, ARMv7, ARMv7s
Can use the LLVM optimizing compiler
Uses mtouch
Static analysis-based linker
Only dependent components are being compiled and
deployed
Reduce the size of the application dramatically
Can be disabled using flags (No Link, Link SDK Only) or
manually using attributes
From Apple perspective – Xamarin application is
like any other native application on the AppStore
19. Xamarin on Android (monoDroid)
Runs both Dalvik and CLR at the same time
Similar linker as to iOS – reduce the application
size in up to 70%
Can be disabled using flags (No Link, Link SDK
Only) or manually using attributes
Mono JIT-Compiling
Mono’s Simple Generational GC
See tips and tricks
Interaction with the OS is done using JNI (Java
Native Interface) with Managed runtime
wrappers
21. User Interface Designer
Android
AXml editor
All standard android UI controls
Built-in – both Visual Studio and Xamarin Studio
iOS
XCode UI designer
Storyboards also supported
Xamarin works directly with the XIB file
Integrated designer – in Alpha
22. Code sharing ‘tactics’
File-Linking
Using symbolic links to shared files from different
projects
Generally used with conditional compilation
directives
Can be used with partial classes and methods
Can be hard to unit-test
Requires an extra step for building the core project
Portable Class Library (PCL)
23. Portable Class Library
Support various deployment targets
Windows 78 Desktop apps
Windows 8 Store Apps
Windows Phone 78
Xamarin.iOS
Xamarin.Android
Xbox (partial)
Silverlight 45
All by using the same binary!
25. Portable Class Library – cont.
Almost every package on NuGet comes with
PCL
HttpClient
Immutable Collections
SignalR
ODataLib
RESTSharp
Json.Net
MvvmCross
TinyIoC
Protobuf-net
Many more..
26. MvvmCross
By far the best and most robust Mvvm
framework
Supports:
Xamarin.iOS
Xamarin.Android
Windows Phone
Windows Store Apps
WPF
Mac OS X
Navigation, IoC container, bindings, etc.. – One
stop shop
28. Visual Studio Integration
iOS application can be developed in Visual
Studio, but you will still need a Mac
For building the binaries
Running the simulator
Deploy to device
UI using Xcode (Interface Builder)
Works perfectly side-by-side – using remote
build and deployment
F5 on VS, the application is loaded on the iOS
simulatordevice
29. Visual Studio Integration – cont.
Android works within VS as any other C#
project
Simulator needs some tweaks for performance
Intel HAXM
Device deployment is the fastest
30. Xamarin Studio (monoDevelop)
Fully featured, modern IDE
Global type search
Code Navigation
Both Mac and Windows versions
Much more..
NuGet support
Source control
SVN / GIT are supported
Refactoring in Visual Studio is better
Generally, great IDE (really)
32. Xamarin.Mobile
Address book
using Xamarin.Contacts;
var contacts = new AddressBook ();
if (await book.RequestPermission()) {
contacts.OrderBy(c => c.LastName).ForEach(c => Console.WriteLine);}
Geo-Location
using Xamarin.Geolocation;
var locator = new Geolocator { DesiredAccuracy = 50 };
Position position = await locator.GetPositionAsync (timeout: 10000);
// position.Latitude, position.Longitude, etc..
33. PushSharp
Server-side library for sending Push
Notifications
iOS (iPhone/iPad APNS)
Android (C2DM and GCM - Google Cloud
Message)
Windows Phone
Windows 8
Amazon, Blackberry too
http://tinyurl.com/pushsharpsession
34. Interoperability
Use native libraries as if they were written in C#
You can wrap a driver for any specific platform and
use it in Xamarin – specific printer, scanner, etc..
iOS
Objective Sharpie – for semi-automatic wrapper
generation for Objective-C drivers
Android – set build action to AndroidNativeLibrary
and use PInvoke
35. Make your app Xamarin-friendly
Good separation between UI code and BL
E.g. Do not use BitmapImage on your BL
Whatever you do, do not use MEF
Abstract away the IoC implementation
Create abstractions for
system.configuration
iOS - Reflection and mtouch linker issues
Android – Large object graphs on
Java.Lang.Object subclasses
Android – Use the x86 emulator (!)
tips
37. 3rd party components
There is a component for almost every need
Google Play Services
Windows Azure Mobile Services
Facebook SDK
Twitter SDK
PushSharp - TBD
RestSharp
Many more - http://components.xamarin.com/
41. Getting started with Xamarin
Scan your code for conformance:
scan.xamarin.com
Download:
Trial program – 30 days
MSDN Subscription benefit – 90 days
Tons of webinars from the last conference
Great tutorials (really!)
43. Thank you!
If you can do it in Objective-C and Java,
you can do it in C# with Xamarin.
Ofir Makmal - Senior Consultant
Email: Ofirm@sela.co.il
Blog: http://blogs.microsoft.co.il/ofirmakmal
Twitter: @OfirMakmal
LinkedIn: http://www.linkedin.com/in/ofirmakmal
Editor's Notes
Titanium – Cross-platform JS runtime and api – with generated components for native experiencePhoneGap/Cordoba – Cross-platform JS runtime and api - JS, CSS, HTML Hybrid applicationsSencha – JS, CSS, HTML application with no apiCorona – mostly focusing on games, using Lua scripting language
Ximian – Novell – Attachmate
Demo application – SDP\Tasky?
ThreeDemos, and short code structure review.Core:platform-specific abstractions, models, services, ViewModels, BL, IoC, Navigation service, cache, local DB, JSON/serialization, communication, loggingApplication Specific: Bindings, Animations, specific OS functionality