This document discusses cross-platform mobile development using Xamarin and Visual Studio. Key points include:
- Using C# and .NET with Xamarin allows building iOS, Android, and Windows Phone apps with one shared codebase while still getting native performance and user experience.
- The code compiles to native for each platform, rather than being interpreted, and full access to platform SDKs is provided. Shared code, data layers, and platform abstractions allow code reuse.
- Visual Studio solutions can contain projects for shared code, platform-specific code for each mobile OS, and tests. Linking or portable class libraries are recommended for sharing code.
- Considerations include designing native U
5. One Language +
C#
Framework
LINQ
Lambdas
Task Parallel Library (TPL)
Compile-Time Checks
Garbage Collection
Âș
6. Native Perf. + UX
Compiles Down to Native Code
Not Interpreted
All Native UX Controls
Full Platform SDK Access
iOS: Selectors/Obj-C Runtime
Android: JNI
Fast Enough for Games
Âș
7. Reuse Story
C# Libraries
Obj-C Bindings + Binding Projects
.jar Bindings + Binding Projects
C via pInvoke
C++ via Cxxi
Âș
11. Design Platform-Specific UX
UX in iOS != Android != Windows
Phone
UX Metaphors are Different:
Navigation Controller vs. Back
Button
Write-Once, Run-Anywhere is
Problematic
Users Expect Native UX
Âș
16. Code Sharing - Linking vs. PCL
Portal Library Projects - Take a Lot of Work
Great Discussion Here:
http://forums.xamarin.com/discussion/28/challenges-thoughts-loves/p1
Takeaway:
PCL is clean, but difficult to implement
Linking is less âcleanâ but simpler
Our Recommendation Now: File Linking for Most Projects
Walkthrough Here: Linking
Âș
17. WP7 + Android
New Blank Solution: "[AppName]"
New C# Lib Project: "[AppName].Core"
Test Project: â[AppName].Core.Testsâ
New Mono for Android Project: â[AppName].Droidâ
New WP7 Project "[AppName].WP7"
Âș
18. iOS - Visual Studio 2012
VS MonoTouch Plugin:
https://github.com/ste8/VSMonoTouch
Visual Studio SDK (to build plugin):
http://msdn.microsoft.com/en-us/library/bb166441(v=vs.80).aspx
iOS - Visual Studio 2010
VS MonoTouch Plugin:
https://github.com/follesoe/VSMonoTouch
Âș
19. .csproj edit:
iOS - Plugin Config <ItemGroup> <Reference
Include="mscorlib" />
Create iOS Project (on Mac): "[AppName].iOS"<Reference
Copy to Solution Directory or Synch in Source Include="monotouch" />
Manually Edit iOS .csproj File, add Refs -> <Reference
Include="System" />
Remove CoreLib Reference -> <Reference
Include="System.Xml" />
Limitations: Can Build, but No Designer, or <Reference
Deployment Include="System.Core" />
(must use Mac for now**) </ItemGroup>
Âș
20. Shared Code Linking
Two Linking Options: Auto or Manual
Auto: Use Project Linker VS Add-In
Add a project link, voila. (2010 + 2012)
Manual: Link Files
Add Files as Links
Âș
21. Shared Data +
Data Access
Layer
Data Access
Layer
SQLite on iOS + Android, C# SQLIte on WP7:
http://code.google.com/p/csharp-sqlite/
SQLite.NET ORM
Use Generics for CRUD Convenience Methods:
TaskDatabase.cs
Âș
Fast Enough for Games Native UX means that apps look like they belong Full platform SDK Access means that anything you can do in Obj-C on iOS or Java in Android, you can do here. Animation libraries, Media libraries, etc.
Need better graphic for this.
Need Visual Studio Screenshot
A good layered architecture allows for proper separation of responsibility and encapsulation, providing isolation to allow for code changes and maximizing code sharing between platforms. It also provides a pattern-agnostic framework so you can pick and choose which patterns you want to use, and then be flexible to changing them later on. And this is very simple to do. Weâll see later on how to accomplish this with proper namespacing and project setup.
Xamarin supports portable library projects, but they pose practical problems in real-world scenarios because of dependencies. it eliminates the ability to use ifDefs, so you have to do massive architectural refactoring, use the provider/simple dependency pattern, etc. to solve even minor things. Best way, instead is to link your code.
Donât use .Android - the namespace will cause you hell
Download install, and configure the plugin as state on the git page. Must create the initial MonoTouch application on a mac. Copy it over to your VS machine, into your project. or just synchronize in your source control. Edit the <ItemGroup> that has the âSystemâ entry to include the mscorlib and monotouch items Finally, remove the mscorlib.dll reference in project settings : build : advanced.
Download install, and configure the plugin as state on the git page. Must create the initial MonoTouch application on a mac. Copy it over to your VS machine, into your project. or just synchronize in your source control. Edit the <ItemGroup> that has the âSystemâ entry to include the mscorlib and monotouch items Finally, remove the mscorlib.dll reference in project settings : build : advanced.
Xamarin supports portable library projects, but they pose practical problems in real-world scenarios because of dependencies. it eliminates the ability to use ifDefs, so you have to do massive architectural refactoring, use the provider/simple dependency pattern, etc. to solve even minor things. Best way, instead is to link your code. There are two ways to do this. The magical way, or the manual way. Automatic linking is done fia the Project Linker VS Add-in. Manual is just plain old file links - your only option in MD. Simply add a project link to the corelib, and when you add/remove classes there, theyâll show up in your app projects. if you put your classes in folders, theyâll link nicely into your apps. The manual way is to simply add existing files and make sure theyâre added as links.
You can use SQLite on all three mobile platforms, iOS, Android, and WP7. on iOS and Android, SQLite is bundled with it, and on Windows Phone, you can use the open source C# port. Weâll show later how to easily support this cross platform with the same exact API. Additionally, we recommend SQLite.NET ORM for easy data access. For Data Access, weâve added some nice convenience methods in TaskDatabase.cs that make the basic CRUD operations a snap with zero code.
Platforms are different. pInvoke is available on iOS and Android, not on WP. SQLite is native on Android and iOS, on WP you have to use the C# lib. Devices also have different features. Cameras are different on nearly every single android device out there. Some devices have location features, some donât. Some vary, etc.
There are predefined symbols that allow you to use different code, depending on the platform youâre building for. Additionally, you can define your own symbols in Build Settings. Demo of this in use can be found here: TaskyPro :: CoreLib.DataLayer/SQLite.cs
ITask - Interface TaskBase - Task class DialogTask - with MT.D annotations