83
Xamarin for not only Android developers Aleksander Piotrowski @pelotasplus

Xamarin for (not only) Android developers

Embed Size (px)

Citation preview

Page 1: Xamarin for (not only) Android developers

Xamarinfor not only Android developers

Aleksander Piotrowski@pelotasplus

Page 2: Xamarin for (not only) Android developers

What platform needsto be a rockstar platform

Page 3: Xamarin for (not only) Android developers

IDE

Visionary

Documentation

Jake Wharton

Testing tools/services

Emulator

Third-party components Library

Events

Blogs/podcasts

Programing Language

Page 4: Xamarin for (not only) Android developers

Historya rising star

Page 5: Xamarin for (not only) Android developers

2000 Microsoft announces .NET Framework

2001 Mono project launched by Ximian

2003 Ximian bought by Novell

2004 Mono first release

2009 MonoTouch 1.0

2011 MonoAndroid first release

2011 Novell acquired by Attachmate0000 Xamarin is founded

2012 Xamarin.Mac

2013 Xamarin Studio

.NET is 15 years old

mono is 11 years old

Xamarin.iOS is 7 years old

Xamarin.Android is 4 years old

modern Xamarin is 2 years old

Page 6: Xamarin for (not only) Android developers

Miguel de Icaza

● never received a degree● free software developer since 1992● Midnight Commander● early Wine contributor● worked on Linux Sun SPARC● later on Linux for SGI Indy● almost did Internet Explorer port to SPARC● started GNOME project and created

Gnumeric● started Mono project to implement .NET on

Linux

source: wikipedia

Page 7: Xamarin for (not only) Android developers

sou

rce:

wik

iped

ia

Page 8: Xamarin for (not only) Android developers

Pricingnot free for personal use

Page 9: Xamarin for (not only) Android developers

command linesupport

good IDE

x2 if targeting both iOS and

Android

Page 10: Xamarin for (not only) Android developers

Write once run everywhere*

* that to run your app on every device make sure it contains nothing else but white background without

any other UI elements

Page 11: Xamarin for (not only) Android developers

Supported platforms

● target:

○ Android, iOS, Mac

○ Windows Phone by sharing C# code between projects

● development:

○ Mac: for all platforms excluding Windows

○ Windows: for all platforms by using remote Mac

○ Linux: -

Page 12: Xamarin for (not only) Android developers

What is

● single language for all platforms - C#

● single base library - .NET Base Class Library

plus specific libraries for target platforms

MonoTouch or Mono.Android

● single runtime for all targeted platforms

iOS, Android, Windows Phone

● “performant enough even for demanding games”

Page 13: Xamarin for (not only) Android developers

What is not

● write once and run anywhere

● use one one platform (Mac or Windows)

to target them all (iOS, Android, Windows)

● one UI for all target platforms

Page 14: Xamarin for (not only) Android developers

Native vs non-native

iOS

● native code at the end

● AOT compiler converts Xamarin app to native ARM code

Android

● no final native code

● Xamarin compiler creates IL (Intermediate Language) which is executed at

runtime on the device

Page 15: Xamarin for (not only) Android developers

Fat binary vs slim debug build● Hello world + Base Class Library: 15.8MB

● Hello world + BCL after Linking: 2.9MB

● Hello world debug release: 6KB + Mono Shared components: 10MB

source: used to be here http://developer.xamarin.com/guides/android/advanced_topics/linking/

Page 16: Xamarin for (not only) Android developers

IDEone to rule them all

Page 17: Xamarin for (not only) Android developers
Page 18: Xamarin for (not only) Android developers

IDE

● have to switch manually between iOS and Android

in multiplatform projects

● ultra annoying “app is running, are you sure you want to stop it and install

new version?”

● cannot even compare to IntelliJ aka IDEA

● Visual Studio to the rescue

● horror when overriding methods CMD-I

Page 19: Xamarin for (not only) Android developers

Let’s codeand have fun hopefully

Page 20: Xamarin for (not only) Android developers

Let’s code in C# and F#

var i = 10; // implicitly typed

int i = 10; // explicitly typed

#define preprocessor

directive

ulong, ushortunsigned types

async/await for asynchronous programming

mandatory break in switch

Lambda expression

Generics with runtime type

supportnamespaces

properties

Page 21: Xamarin for (not only) Android developers

F#

Page 22: Xamarin for (not only) Android developers

F#

Page 23: Xamarin for (not only) Android developers

Let’s code in Java or Objective-C

● using Java Native Interface (JNI), or

● using bindings for Java code

● with Objective-C creating binding

● straightforward process, for the second time

Page 24: Xamarin for (not only) Android developers
Page 25: Xamarin for (not only) Android developers

Project^wSolution structure

Page 26: Xamarin for (not only) Android developers

Solution structure

● References - base .Net classes

● Components

● Packages

● Assets

● Properties

● Resources

● our code

● and even maybe tests...

Page 27: Xamarin for (not only) Android developers
Page 28: Xamarin for (not only) Android developers

Code sharing

Page 29: Xamarin for (not only) Android developers

Layers

● Data Layer SQLite

● Data Access Layer create, read, update, delete

● Business Logic data model and business logic

● Service Access Layer access REST, parsing JSON

● Application Layer platform specific code but not UI-related

● User Interface Layer UI-related code

shared

not shared

shared

shared

shared

not shared

Page 30: Xamarin for (not only) Android developers

source: https://xamarin.com/forms

Page 31: Xamarin for (not only) Android developers

Code Sharing

● Shared Project

● Portable Class Library

Page 32: Xamarin for (not only) Android developers

Shared Project

● no .dll as an output

● “compiled into” referencing project

● not compiled, if not used

● platform specific code via #if statements

○ #if __MOBILE__

○ #if __ANDROID__

● “for personal use only”

Page 33: Xamarin for (not only) Android developers

source: http://developer.xamarin.com/guides/cross-platform/application_fundamentals/shared_projects/

Page 34: Xamarin for (not only) Android developers

Portable Class Library

● using a subset of BCL called Profile

● targets many different (supported) platforms

● no platform-specific libraries allowed

● refactoring of PCL affects all referencing projects

● good for sharing with others

Page 35: Xamarin for (not only) Android developers

source: http://developer.xamarin.com/guides/cross-platform/application_fundamentals/building_cross_platform_applications/sharing_code_options/

Page 36: Xamarin for (not only) Android developers

source: http://developer.xamarin.com/guides/cross-platform/application_fundamentals/building_cross_platform_applications/sharing_code_options/

Page 37: Xamarin for (not only) Android developers

UI design

Page 38: Xamarin for (not only) Android developers
Page 39: Xamarin for (not only) Android developers
Page 40: Xamarin for (not only) Android developers

Xamarin Forms

Page 41: Xamarin for (not only) Android developers

source: https://xamarin.com/forms

Page 42: Xamarin for (not only) Android developers

source: video @ https://xamarin.com/forms

Page 43: Xamarin for (not only) Android developers

Forms

● single app screen called a Page

● Page contains layouts (StackLayout, GridLayout) and

UI elements (Button, Image, SearchBar, WebView)

● connect actions (click event, long press event) to code

which is shared across all platforms

● at the end at run-time all UI elements are mapped to native platform-

specific UI components

Page 44: Xamarin for (not only) Android developers

Forms

● can be written in pure code

○ sounds a bit like old school iOS style

● or in XAML layout files

○ sounds more like Android style

○ not supporting existing XAML editor :-/

○ layouts have supporting class, so called CodeBehind class

● using MVVM pattern

Page 45: Xamarin for (not only) Android developers

sou

rce:

htt

ps:/

/xam

arin

.com

/for

ms

Page 46: Xamarin for (not only) Android developers

sou

rce:

htt

ps:/

/xam

arin

.com

/for

ms

Page 47: Xamarin for (not only) Android developers

source: https://xamarin.com/forms

Page 48: Xamarin for (not only) Android developers

source: https://xamarin.com/forms

Page 49: Xamarin for (not only) Android developers

Pros

● data entry apps● prototypes & proof-of-

concept apps● little platform-specific

APIs● code sharing over

custom UI

Cons

● specialized interaction required

● highly polished design● many platform-

specific APIs● custom UI above code

sharing

Page 50: Xamarin for (not only) Android developers

Emulatoror is it simulator

Page 51: Xamarin for (not only) Android developers
Page 52: Xamarin for (not only) Android developers
Page 53: Xamarin for (not only) Android developers
Page 54: Xamarin for (not only) Android developers

Xamarin Player

● simulate, debug, demo or run Android apps in our fast and hassle-free

environment.

only Android apps

● integrated with Xamarin Studio and Visual Studio

● native UI on Windows and Mac

● widgets for location and battery

● easy screenshot taking

Page 55: Xamarin for (not only) Android developers

Xamarin Player

● x86 virtual machine with HW acceleration

● VT-x AMD-V

● OpenGL 2.0

● uses VirtualBox 5.0.4

Page 56: Xamarin for (not only) Android developers

Xamarin Player

● can install non-Xamarin native Android APKs?

YES

● supports Google Play Services?

YES via installing third-party provided ZIP file

● hmm, sounds like a Genymotion clone?

YES indeed

Page 57: Xamarin for (not only) Android developers

Xamarin Player

● free

● less widgets

● better drag & drop

● fixed aspect window scaling

● couple of device configurations

● paid

● more widgets

● drag & drop

● window scaling

● lots of device configurations

Page 58: Xamarin for (not only) Android developers

Documentationfor C#, Android, iOS, and ...

Page 59: Xamarin for (not only) Android developers

Documentation

● for all targeted platforms

Xamarin.Android, Xamarin.iOS, Xamarin.Forms, Xamarin.Mac and Windows

● Android developer could learn iOS app architecture

● explains not only C# or Xamarin-related aspects but also basics of the

platforms

● always with “download as PDF”

Page 60: Xamarin for (not only) Android developers

Documentation

● iOS app fundamentals

http://developer.xamarin.com/guides/ios/application_fundamentals/

Protocols, Events, and Delegates

● iOS user interface

http://developer.xamarin.com/guides/ios/user_interface/

UIKit, Tables and cells, Storyboards

● platform features

http://developer.xamarin.com/guides/ios/platform_features/

Newsstand, HealthKit, and iOS 9 introduction

Page 61: Xamarin for (not only) Android developers

Documentation

● Android app fundamentals

http://developer.xamarin.com/guides/android/application_fundamentals/

API levels, Activity lifecycle, Handling rotation

● Android user interface

http://developer.xamarin.com/guides/android/user_interface/

Actionbar, Splash screen, List view & adapters, RecyclerView

● platform features

http://developer.xamarin.com/guides/android/platform_features/

Fragments, ContentProvider, new Android versions

Page 62: Xamarin for (not only) Android developers

Third-party librariesmaven, pip, apt, cocoapods, npm, we want more!

Page 63: Xamarin for (not only) Android developers

Third-party libraries

● components via Xamarin Components Store

● packages via NuGet package manager

● libraries & UI components

● easily to be added to a project

Page 64: Xamarin for (not only) Android developers
Page 65: Xamarin for (not only) Android developers

Components

● HockeyApp

● Crittercism

● SQLCipher 499$

● Facebook SDK by Xamarin Inc.

● Parse SDK by Parse Inc.

● Tip of the Day

Page 66: Xamarin for (not only) Android developers
Page 67: Xamarin for (not only) Android developers

Packages

● for Android, iOS, or both

● native C#

● via NuGet packages by .NET Foundation

● 44,015 packages

Page 68: Xamarin for (not only) Android developers

Packages

● Android Support Library, Design Library,

RecyclerView by Xamarin

● Android Picasso by jacksierkstra

● iOS SVProgressHUD (wrapper)

● iOS FloatLabelEntry (native)

● Parse.com in 6 versions

Page 69: Xamarin for (not only) Android developers

Packages

● get data from RESTful API and store it

in data model

● refit by paulcbetts

● one C# code for Android, iOS and .NET

RESTful API

datamodel

network servicein our app

AFNetworking Retrofit

Retrofitmanuallyas a dict

Page 70: Xamarin for (not only) Android developers

Packages

● get data from network

● iOS AFNetworking

● Android OkHttp latest is 2.5.0

● Xamarin ModernHttpClient

on iOS NSURLSession

on Android OkHttp 2.4.0

Page 71: Xamarin for (not only) Android developers

Testingin case you have time for that

Page 72: Xamarin for (not only) Android developers

Testing

● Xamarin Test Cloud

● Calabash

Page 73: Xamarin for (not only) Android developers

Xamarin Test Cloud

● 1,800 devices and adding 100 monthly

● stars at 1,000 USD/month paid annually … for 2 apps

● 5,000 USD for 5 apps

● NUnit or Calabash tests

● screenshots, device performance for every step of every test

Page 74: Xamarin for (not only) Android developers

source: https://xamarin.com/test-cloud

Page 75: Xamarin for (not only) Android developers

source: https://xamarin.com/test-cloud

Page 76: Xamarin for (not only) Android developers

Calabash

● automated UI tests

● using Behavior Driven Development approach

● written in Ruby, or Cucumber, or Gherkin

Page 77: Xamarin for (not only) Android developers

source: http://developer.xamarin.com/guides/testcloud/introduction-to-test-cloud/

Page 78: Xamarin for (not only) Android developers

Scenario: Credit card number too short

Given I am on the Credit Card Validation Screen

When I enter a credit card number that's 16 digits long

And I click on the Validate button

Then I should see a validation error

source: http://developer.xamarin.com/guides/testcloud/calabash/introduction-to-calabash/

Page 79: Xamarin for (not only) Android developers

Communityand expensive conference

Page 80: Xamarin for (not only) Android developers

Community

● blogs

● developer advocates and their apps

James Montemagno https://github.com/jamesmontemagno

● podcast - Xamarin Podcast

http://pca.st/9cXF

● their own WWDC, also quite pricey 1,499$

Xamarin Evolve

● Paul C. Betts and his libraries https://github.com/paulcbetts/

Page 81: Xamarin for (not only) Android developers

IDE

Visionary

Documentation

Jake Wharton

Testing tools/services

Emulator

Third-party components Library

Events

Blogs/podcasts

Programing Language

Page 82: Xamarin for (not only) Android developers

IDE

Visionary

Documentation

Jake Wharton

Testing tools/services

Emulator

Blogs/podcasts

Third-party components Library

Events

Paul C Betts

Xamarin Studio

Xamarin Podcast

Miguel de Icaza

Awesome docs

Evolve

Xamarin Android Player

Components & packages

Test Cloud & Calabash

Programing LanguageC#, F#, support native

Page 83: Xamarin for (not only) Android developers