mono for android.net for android howto: multitargeting-portability- interoperability for.netters...

29
Mono for Android <Monodroid> .net for Android HowTo: MultiTargeting-Portability- Interoperability for .netters 2011.06.30 MSCommunity.DevUG.Zg [email protected] 1

Upload: madeleine-adelia-jackson

Post on 25-Dec-2015

225 views

Category:

Documents


1 download

TRANSCRIPT

[email protected] 1

Mono for Android<Monodroid>

.net for Android

HowTo: MultiTargeting-Portability-Interoperability

for .netters

2011.06.30 MSCommunity.DevUG.Zg

[email protected] 2

Motivation 1 – Financial

• Cross platform / Multitargeting / Portability– “write once, run everywhere”– Goal / Drive

• Time = Money • greater or equal profit

– Bigger market => more customers

• Necessity or perversion/masochism??

– Multitargeting Tools 2011-06-30• Java• Native + UI

– C++: Qt, AirPlaySDK (Marmalade), MoSync

• Html5 + css3 + JS (hype, even Windows 8, .net is dead?)– PhoneGap, Titanium, SenchaTouch

• .net ??– Mono

2011.06.30 MSCommunity.DevUG.Zg

[email protected] 3

Motivation 2 - Market Share Current

• WikipediaSource Year Symbian Android RIM iOS MicrosoftOther Gartner [24] 2011 Q1 27.4% 36.0% 12.9% 16.8% 3.6%3.3%Gartner [25] 2010 37.6% 22.7% 16.0% 15.7% 4.2%3.8%Gartner [25][26] 2009 46.9% 3.9% 19.9% 14.4% 8.7%6.1%Gartner [26][27] 2008 52.4% 0.5% 16.6% 8.2% 11.8%10.5%Gartner [27] 2007 63.5% N/A 9.6% 2.7% 12.0%12.1%

• References– http://en.wikipedia.org/wiki/Mobile_operating_system#Market_projection

2011.06.30 MSCommunity.DevUG.Zg

[email protected] 4

Motivation 3 - Market Share Projection

GartnerOS 2010 [%] 2011 [%] 2012 [%] 2015 [%]Symbian 111,577 37.6 89,930 19.2 32,666 5.2 661 0.1Android 67,225 22.7 179,873 38.5 310,088 49.2 539,318 48.8RIM 47,452 16 62,600 13.4 79,335 12.6 122,864 11.1iOS 46,598 15.7 90,560 19.4 118,848 18.9 189,924 17.2Microsoft 12,378 4.2 26,346 5.6 68,156 10.8 215,998 19.5Other OS 11,417.40 3.8 18,392.30 3.9 21,383.70 3.4 36,133.90 3.3Total [k] 296,647 467,701 630,476 1,104,898

• References– http://www.gartner.com/it/page.jsp?id=1622614– http://socialtimes.com/gartner-idc-agree-about-mobile-marketshare-in-2015-but-disagr

ee-about-2011_b56708

2011.06.30 MSCommunity.DevUG.Zg

[email protected] 5

Motivation 4 - Software Eng

• Multilayer architecture– Business Logic / Model x%– Presentation Layer / View y%

2011.06.30 MSCommunity.DevUG.Zg

BL1

PL1

BLn

PLn PL1

BL

PLn

[email protected] 9

Android 1 - Intro

• Android– Is linux with modified 2.6 kernel– Set of native libs– Application framework written in java

• Dalvik VM

– Architecture• ARM6+• x86 v.2.2 Froyo

• Rich development environment– Eclipse and …

2011.06.30 MSCommunity.DevUG.Zg

[email protected] 11

Android 2 – Architecture/Stack

2011.06.30 MSCommunity.DevUG.Zg

[email protected] 12

Android 3 – App Fx 1

• Components:• Activity

– application component that provides a interaction screen (or not)• Intent

– messaging facility for late run-time binding between components in the same or different applications

• Service– application component that can perform long-running operations in the

background and does not provide a user interface.• ContentProviders

– providers store and retrieve data and make it accessible to all applications• BroadcastReceiver

– broadcast receiver is a component that responds to system-wide broadcast announcements

2011.06.30 MSCommunity.DevUG.Zg

[email protected] 19

Android 9 – App Fx 7 External dataExternal elements/data:• Resources - more often (java: ProjectRootDir/res/)

– Compiled/generated by aresgen into R.java – strongly typed– Accessed through R.Drawable.Id

• Assets (java: ProjectRootDir/assets/)– For raw access (no ability to extract raw data from Resource)

2011.06.30 MSCommunity.DevUG.Zg

Function Path Access programatically

UI layout/filename.xmllayout-land/main.axml

// R.layout.filenameTextView tv = findViewById(Resource.id.nameTextbox);

Bitmaps drawable/icon.png Drawable d = res.getDrawable(Resource.Drawable.icon);

Text values/strings.xml String s = getString(Resource.String.hello);

[email protected] 20

Android 10 - Resources/Assets

• Abstraction layer which helps decouples code• Resources– Images, layout descriptions, binary blobs and

string dictionaries– Localization– Multiple displays– Different hardware configurations

• Assets + AssetManager– Makes managing assets easier

2011.06.30 MSCommunity.DevUG.Zg

[email protected] 21

Android 10 – App Fx 8 UI

• Layouts– Defined in xml (*.axml in VS) like XAML, XHTML– During build generated as objects• Activity contains View[s] and/or ViewGroup[s]

have appearance– Android.View.View{} – widgets

Button, CheckBox, TextView, EditText, AutoComplete, ListView, ImageView, Gallery, pickers

– Android.View.ViewGroup{} - specialization, order, orientationLinearLayout, AbsoluteLayout, RelativeLayout, tableLayout, FrameLayout, ScrollView

2011.06.30 MSCommunity.DevUG.Zg

[email protected] 24

Android 11 – Dalvik VM

• Register-based (normal Java VMs are stack based)– Requires a .class to .dex transformation

• Runs multiple VMs efficiently• JIT (as of Android 2.2)• Each Android Application:– Runs in their own process – Runs on their own VM

• One of main sources of dispute Oracle vs. Google– Java ME – license does not allow changing VM

2011.06.30 MSCommunity.DevUG.Zg

[email protected] 25

Android 12 - Tools

• Development– JDK + Android SDK– IDE - eclipse– UI - DroidDraw

• SDK– SDK + AVD Manager– Android Debug Bridge – adb.exe (cmdline)

• Interface to Emulator/Device

– Emulator.exe– Build process

• Javac (for class files) + dex (.dex files for Dalvik VM)• apkbuilder – generates apk (zip file)• jarsigner (signing) + zipalign (optimizations)

2011.06.30 MSCommunity.DevUG.Zg

[email protected] 26

Android 12 – Debugging

• Adb + Logging– adb logcat– android.util.Log

• Debugging on device– Android SDK + USB drivers– Wi-fi, though deployment over USB– Update drivers for unrecognized device in Device Manager

with non-google USB drivers (android.bat in SDK dir)– Selecting image or device!– Error connecting stderr/stdout

• check ports IP address, firewall, VS – tools – options

2011.06.30 MSCommunity.DevUG.Zg

[email protected] 27

Android 13 - Deployment

• Deploy to – Android Virtual Device– Device: phone || pad

• Debug capabilities on both• Sell (eventually) – Android Marketplace– Amazon App Store

2011.06.30 MSCommunity.DevUG.Zg

[email protected] 28

Android 14 – Refs / Links

• Links– http://developer.android.com/index.html– http://www.androiddevelopment.org/– http://www.vogella.de/articles/Android/article.html

• Opinion (personal):

– Pros• Openness

– Speed of development

– Cons

• Openes– Fragmentation/Diversity (versions …)– Security

2011.06.30 MSCommunity.DevUG.Zg

[email protected] 29

Mono for Android 1 - Intro

• Ex– monodroid– Commercial Product from Novell (was)

~$99 student / $399 individual / ~$999 enterprise• MonoForAndroid V 1.0.1– Is Extension to Android which wraps Android as app

framework– Contains:

• MonoVM vm• Managed Mono Libs: RSilverlight, Rdesktop• Android and Mono Callable Wrappers

2011.06.30 MSCommunity.DevUG.Zg

[email protected] 32

Mono for Android 4 – Architecture/Stack

2011.06.30 MSCommunity.DevUG.Zg

[email protected] 33

Mono for Android 3 - Design Principles• Follow the Framework Design Guidelines• Allow developers to subclass any Java class

– Derive from class, call base ctor for chain, c# overriding– Common Java tasks easy, hard ones possible– JavaBean properties as c# properties

• Strongly typed APItype safety, minimize errors, intellisense, docs,

• C# constructs (delegates, lambdas, anonymous methods) instead of sinlge method interfaces– c# delegates for widget events (less cumbersome than java hooking)

• Mechanism to call Java libs• Bindings - Java.util.collections -> System.Collections.Generic

– Use Helper classes Android.Runtime.JavaList<T> et al to reduce marshalling overhead between Mono VM and Dalvik VM

• Threading (runnables) Android.Activity.RunOnUIThread()• Resources (Resources/drawable-hdpi/* -> Resource object• Android constants -> c# enums• Android.Runtime.JNIEnv managed wrapper for Java Native Interface JNI calls

2011.06.30 MSCommunity.DevUG.Zg

[email protected] 34

Mono for Android 4 - Tools + Build• Android SDK• IDE

– Visual Studio 2010 Profesional + – MonoDevelop

• Monodroid tools– VS plug in – Aresgen: resource generator (resgen)– mandroid.exe – monodroid.exe

• Generates ACWs. AndroidManifest.xml and packages app

– Shared runtime for debugging on emulator 18MB + – Signing needed for devices, slow not part of build– AndroidManifest.xml

• controlled through c# Attributes

2011.06.30 MSCommunity.DevUG.Zg

[email protected] 35

Mono for Android 5 - Development

• IDE– VS 2010 Professional+ (Windows)

• Almost no need to leave VS• External tools• Project and Item templates

– MonoDevelop 2.6 (Windows, Linux, Mac OS X)• Principles

– BL – classical (desktop) .net, c#– PL – different, but resembles XAML (WPF, SL, SLWP7)– Debugging - Like “normal” debugging in VS– Logging (no Console) (android.util.Log)

• Android.Util.Log.Info(“some_tag_for_app”, “message”);• Android.Util.Log.Warn(“some_tag_for_app”, “message”);• Android.Util.Log.Error(“some_tag_for_app”, “message”);

2011.06.30 MSCommunity.DevUG.Zg

[email protected] 36

Mono for Android 6 – Tips&Tricks

• Principles– Achitecture layers

• BL /Model– develop as classical (desktop) – tested in desktop Mono - Mono

• PL – Do learn Android SDK

• Tools (need another session)– VS Project Linker– VS Productivity power tools– VSCommands– VS Power Commands

2011.06.30 MSCommunity.DevUG.Zg

[email protected] 39

Mono for Android 9 – Pros 1

• Mono supports lots from netfx 3, 3.5 and 4– Attributes: no need to edit AndroidManifest.xml– Lambda expressions– anonymous delegates – LINQ– WCF (alpha)

2011.06.30 MSCommunity.DevUG.Zg

[email protected] 42

Mono for Android 9 – Cons 1• Performance

– 2 VMs: Mono + Java VM – Dalvik - interop/marshalingvery controversal test results depending on context

– (UI yes, rest can be avoided)– No shared runtime

• Release takes time (linker analyzes dependencies)

– http://www.koushikdutta.com/2009/01/dalvik-vs-mono.html• Debugging: Slow (some have abandoned because of this)• Limitations

– Java proxy classes generation (automatic) => cannot generate all code!– ACW generated based on static analysis of assemblies => no dynamic

languages• Not native

– wraps native Android java libs (java is not native either)

2011.06.30 MSCommunity.DevUG.Zg

[email protected] 43

Mono for Android 10 – Cons 2

• Difficulty / Ignorance / Laziness– dev must learn new platform Android API

only PL - UI layer– c# and java althoug quite similar

Friction still due to Java idioms and architecture• Political– Microsoft is in/out (haters hate it anyway)– Mono status

• dead??? – no it is open source• Progress dynamics - vary

2011.06.30 MSCommunity.DevUG.Zg

RIPMono

2002-2011

2011.06.30 MSCommunity.DevUG.Zg

[email protected] 46

Mono for Android 13 – Refs / Links 2

• Code samples• https://github.com/mono/monodroid-samples• https://github.com/kevinmcmahon/MonoDroid101• https

://github.com/gshackles/Sample-Projects/tree/master/MonoDroid/MonoDroidSamples

• https://github.com/gshackles/Sample-Projects/• https://github.com/conceptdev/RestaurantGuide/tree/master/RestGuide_Android

• Comparison• http://www.holisticware.net/HolisticWare/Know-How/Development/ui-developme

nt-presentation-layer-framework-comparison.aspx

• Applications• http://mix11.confapp.com/• http://www.barnesandnoble.com/w/spawn-eodsoft/1030870830• MonoTouch showcase:

– http://monotouch.net/Apps/?tag=/Showcase– http://www.eodsoft.com/artisan.html

2011.06.30 MSCommunity.DevUG.Zg

[email protected] 47

Mono for Android 14 – Q&A

• ??????????????????????????

• VB– Mono – yes– Mono 4 Android – no • no Vb templates• Compiler status?

2011.06.30 MSCommunity.DevUG.Zg