Introduction to Cross Platform Development with Xamarin and Visual Studio
1. Introduction to Cross Platform
Development with Xamarin/
Visual Studio
Brad Pillow
PillowSoft LLC
Indianapolis Mobile .NET Developers Group
April 8, 2014
2. Who Am I
• Co-founder of one of the first video-graphics hardware/software companies in
Indianapolis, Truevision Inc. in 1987
• My 15 seconds of Wikipedia fame: creator of the TGA file format
• Originally developed in C, then we switched to C++ as it matured
• Joined Adobe Systems Inc. in 2002 as a developer on Adobe Premiere Pro
• Became tired of slow development in C++, left Adobe in 2012 and started my
consulting company going again, focusing on .NET C#/F#, web technologies
and machine learning
3. Why I Started This Group
• Cross-platform development with .NET is exciting and a lot is happening
• Help evangelize the available tools and the languages, in particular F#
• Xamarin promotes these meet ups (see freebies)
• Looking for a co-organizer
• Looking for corporate sponsors
• Network with others with similar interests
4. Visual Studio 2013
• Only works on Windows
• Allows a developer (without extensions) to build only
for Windows (8 and variants) and Windows Phone 8
• Great debugger
• Excellent profiling tools
• Fantastic add-ins like ReSharper
• Alas, no iOS, Android, no Mac, etc.
5. Typical iOS and Android
Development
• iOS: XCode and Objective-C
• Android: Eclipse and Google SDK
• Good news: free
• Bad news: nothing sharable, multiple languages to
learn, multiple API’s to learn, etc.
• Enter: Xamarin
6. How Xamarin Works
• Unify app development in C# for all
major device platforms
!
• Deliver fully native apps – UI &
Performance
!
• Speed time-to-market through
code-sharing and re-use
!
• Businesses can leverage existing C#
skills, tools, teams and code
!
• Achieve broad reach across device
platforms and escape the
Objective-C and Java dead ends
*Slide credit:Xamarin, “Xamarin 2.0 Overview “
7. Native UI: No Compromises.
Cross-platform field
service app for iOS,
Android and
Windows 8
*Slide credit:Xamarin, “Xamarin 2.0 Overview “
8. Code Sharing Case Study: TouchDraw
Released early Sept 2012 Android – Oct 2012
*Slide credit:Xamarin, “Xamarin 2.0 Overview “
9. Tiny Cuts (early) That I Experienced (MonoTouch)
• Initially had issues with value type generics - no reactive extensions
• debugging unstable
• no F# support
• no portable class library support
• little refactoring for C#
• IDE was unstable and had weird UI issues due to GTK
• Amazing how much better tools can get when a company is well funded!
Also see: http://jonathanpeppers.com/Blog/xamarin's-tiny-cuts
10. Xamarin 2.0 Summary
• Xamarin Studio. A new IDE that streamlines design, development, debugging and
deployment of native mobile apps.
!
• Xamarin.iOS for Visual Studio. Visual Studio users can build iOS, Android and Windows
apps in their favorite IDE.
!
• The Xamarin Component Store. An app store for code, where developers add third-
party libraries with a few lines of code, and also add beautiful native UI controls and
design themes.
!
• Starter Edition. A free tier that makes it easy for small businesses and individual
developers to get started and experience the power of the platform.
!
!
11. Rich IDE SupportIntroducing Xamarin Studio
Available on Mac and
Windows
Built from the ground up for
cross-platform mobile
development
*Slide credit:Xamarin, “Xamarin 2.0 Overview “
12. Rich IDE Support
Build iOS, Android and Windows apps in Visual
Studio
100% language unification
across platforms in C#
And with Xamarin 2.0
100% IDE unification
across platforms
*Slide credit:Xamarin, “Xamarin 2.0 Overview “
13. Pre-built apps
Customize and deploy
!
Cut and paste useful snippets
!
Cross-platform best practices
!
Routing, Time recording
!
Camera capture of work
!
Signature capture
!
Uses MVVM
!
Uses Xamarin.Mobile
!
Uses Signature control
!
Backend integration ready
Field Service App
!
*Slide credit:Xamarin, “Xamarin 2.0 Overview “
14. Pre-built apps
Employee Directory
!
Customize and deploy
!
Cut and paste useful
snippets
!
Cross-platform best
practices
!iPhone, Android and
Windows
!
LDAP-ready
!
Gravatar integration
!
Uses MVVM
!
SQLite data store with a .NET
based SQLite ORM on all
platforms
*Slide credit:Xamarin, “Xamarin 2.0 Overview “
15. Xamarin Component Store• Many components already offer async APIs, e.g. Parse!
Powerful, easy to use components http://components.xamarin.com
16. Now Bundled with Mono
• Reactive Extensions
– Possible on iOS with new code gen changes
• F# everywhere
• Razor - html template engine
• Entity Framework
• ASP.NET WebStack
17. F# Support
• Functional Programming comes to iOS!
!
• The pitch is simple:
– Fewer bugs
– Focus on intent
– Reuse C# libraries, experience
– More features, less time
18. Razor Integration
• Sometimes you want to generate HTML
• Razor offers a full template system
– Blend HTML and C#
– Code completion in HTML
• Easily pass parameters from C# to Template
• “static” pre-rendered templates on iOS
19. New Devices
• Google Glasses (beta)
• Amazon fireTV
• Motorola and others Android watches (beta SDK now)
20. Xamarin: Per-developer, per platform pricing.
What is the difference between
Starter and Indie?
!
Xamarin Starter allows developers to
build and publish simple apps,
which contain no more than 64k of
compiled user code (IL), and which
do not call out to native third party
libraries (i.e., developers may not P/
Invoke into C/C++/Objective-C/Java.
See the full product comparison
chart.
*Slide credit:Xamarin, “Xamarin 2.0 Overview “
21. Rich IDE Support
Xamarin Component Store
High quality pre-built
components – UI controls,
themes & web services
Full IDE integration
*Slide credit:Xamarin, “Xamarin 2.0 Overview “
22. MonoDevelop / Xamarin Studio
MonoDevelop Xamarin Studio
MonoDevelop Core MonoDevelop Core
Android Mac iOS
Branding Add-In
Open source
Commercial
23. dtrace probes on MacOS
Major collections and minor collections pause times visualized
http://schani.wordpress.com/2012/11/02/sgen-and-dtrace/
24. Static Compilation
• For systems that don’t support JITing
– Apple’s iOS devices
– Consoles (PlayStation, Xbox)
– Security: when not shipping IL
!
• Limited generics support
– Static analysis limitations
– Some dynamisms in .NET idioms
• LINQ and Value Types
25. “Attempting to JIT compile method”
!
!
!
System.ExecutionEngineException: Attempting to JIT compile method
Foo[]:Bar`1
*Slide credit: miguel@gnome.org, “What is new in Mono? “
26. “Attempting to JIT compile method”
!
!
!
System.ExecutionEngineException: Attempting to JIT compile method
Foo[]:Bar`1
FIXED
*Slide credit: miguel@gnome.org, “What is new in Mono? “
28. Cocos2D XNA
• XNA port of the popular Cocos2D API
– Over 4,000 games built with this API
– Well documented, well known
!
• MonoGame brings it everywhere
– iOS, Android, Windows Phone (7 and 8)
– Mac
– Windows (GL, DX, , Windows Store)
– Xbox360, Amazon Fire, future Google TV Box
– Play Station Mobile (PS Vita + Sony Androids)
*Slide credit: miguel@gnome.org, “What is new in Mono? “
29. Using Cocos2D XNA Today
• Available as:
– NuGet Packages
– Templates for VS and Xamarin Studio
!
• Source code:
– http://github.com/mono/cocos2d-xna
!
• Getting Started:
– http://docs.xamarin.com/guides/cross-platform/cocos2d_xna
*Slide credit: miguel@gnome.org, “What is new in Mono? “
30. Angry Ninjas - Full Open Source Game
https://github.com/xamarin/AngryNinjas
*Slide credit: miguel@gnome.org, “What is new in Mono? “
31. Xamarin.Mobile
• Base class library
for mobile services
!
• Mike Bluestein’s on
Slideshare
*Slide credit: miguel@gnome.org, “What is new in Mono? “
32. Xamarin.Auth
!
• Clients for OAuth 1 and OAuth 2
– Includes variations
• Stores user credentials
• Support non-standard auth schemes
• Cross Platform
33. Xamarin.Social
• Posts statuses, links, images/media to social networks
– Access social network APIs using authenticated requests.
– Automatically and securely store user credentials using Xamarin.Auth.
– Cross Platform
!
• Extensible, currently has support for:
– App.net
– Facebook
– Flickr
– Pinterest
– Twitter
34. Now all Open Source
• All frameworks:
– Cocos2D XNA
• http://github.com/mono/cocos2d-xna
– Xamarin.Auth
• http://github.com/xamarin/Xamarin.Auth
– Xamarin.Mobile
• http://github.com/xamarin/Xamarin.Mobile
– Xamarin.Social
• http://github.com/xamarin/Xamarin.Social
!
• Taking patches!
*Slide credit: miguel@gnome.org, “What is new in Mono? “
35. MVVMCross
• The Mvvm Platform for Xamarin.iOS,
Xamarin.Android, WindowsPhone, WindowsStore,
WPF and Mac. Includes databinding support for
Android XML, for iOS XIBs and for
MonoTouch.Dialog.
• http://vimeo.com/68375201
• Keep your models and “view models” as common
code, using device specific views per platform. Also
provides many abstractions for various platform
services.
36. Future topics
• F#: functional programming for mobile development
• Reactive Extensions using reactive programming in mobile
• Open source .NET libraries for use in mobile dev (JSON.NET, etc.)
• MonoTouch.Dialog and MonoDroid.Dialog
• Using PCL (Portable Class Libraries)
• C#/F# Async Deep dive
• MonoGame for easy cross-platform game development
• MVVMCross for easier cross-platform app development
• Cloud services - Parse, Azure, Firebase….
• Hackathon??
37. Why I Use It
• F# allow me to do very rapid development
• Allows me to use F# and C# libs
• PCL’s allow me to write core non-UI logic once and share
• Rapid turn around time (quick incremental compiles)
• Tons of open source libraries
• Lots of books and web sites on C#/F# and more on Xamarin every day
• With one too I can natively target almost anything out there…even the web
38. My Dev Environment
• I use Git for source control
• I use a Mac and run Xamarin Studio on it, as well as Visual Studio on
Windows 8 on a VM with Parallels
• I try to use on F# and fall back to using open source C# libraries
• I have a MacMini server that I use to push my Git commits to (supports a
Git server very easily!)
• I have the business editions, but will likely drop back to Indie when they
are up for renew. They seem to do all I need.