290 likes | 627 Views
Mono for Android < Monodroid > .net for Android. HowTo : MultiTargeting -Portability-Interoperability for .netters. Motivation 1 – Financial. Cross platform / Multitargeting / Portability “write once, run everywhere ” Goal / Drive Time = Money greater or equal profit
E N D
Mono for Android<Monodroid>.net for Android HowTo: MultiTargeting-Portability-Interoperabilityfor .netters mcvjetko@holisticware.net
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 mcvjetko@holisticware.net
Motivation 2 - Market Share Current • WikipediaSource Year Symbian Android RIM iOS Microsoft Other 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 mcvjetko@holisticware.net
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.1 Android 67,225 22.7 179,873 38.5 310,088 49.2 539,318 48.8 RIM 47,452 16 62,600 13.4 79,335 12.6 122,864 11.1 iOS 46,598 15.7 90,560 19.4 118,848 18.9 189,924 17.2 Microsoft 12,378 4.2 26,346 5.6 68,156 10.8 215,998 19.5 Other OS 11,417.40 3.8 18,392.30 3.9 21,383.70 3.4 36,133.90 3.3 Total [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-disagree-about-2011_b56708 mcvjetko@holisticware.net
Motivation 4 - Software Eng PL1 PLn PLn PL1 BL1 BLn BL • Multilayer architecture • Business Logic / Model x% • Presentation Layer / View y% mcvjetko@holisticware.net
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 … mcvjetko@holisticware.net
Android 2 – Architecture/Stack mcvjetko@holisticware.net
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 mcvjetko@holisticware.net
Android 9 – App Fx 7 External data External elements/data: • Resources - more often (java: ProjectRootDir/res/) • Compiled/generated by aresgeninto R.java – strongly typed • Accessed through R.Drawable.Id • Assets (java: ProjectRootDir/assets/) • For raw access (no ability to extract raw data from Resource) mcvjetko@holisticware.net
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 mcvjetko@holisticware.net
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{} – widgetsButton, CheckBox, TextView, EditText, AutoComplete, ListView, ImageView, Gallery, pickers • Android.View.ViewGroup{} - specialization, order, orientationLinearLayout, AbsoluteLayout, RelativeLayout, tableLayout, FrameLayout, ScrollView mcvjetko@holisticware.net
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 mcvjetko@holisticware.net
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) mcvjetko@holisticware.net
Android 12 – Debugging • Adb + Logging • adblogcat • 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 mcvjetko@holisticware.net
Android 13 - Deployment • Deploy to • Android Virtual Device • Device: phone || pad • Debug capabilities on both • Sell (eventually) • Android Marketplace • Amazon App Store mcvjetko@holisticware.net
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 mcvjetko@holisticware.net
Mono for Android 1 - Intro • Ex • monodroid • Commercial Product from Novell (was)~$99 student / $399 individual / ~$999 enterprise • MonoForAndroidV 1.0.1 • Is Extension to Android which wraps Android as app framework • Contains: • MonoVMvm • Managed Mono Libs: RSilverlight, Rdesktop • Android and Mono Callable Wrappers mcvjetko@holisticware.net
Mono for Android 4 – Architecture/Stack mcvjetko@holisticware.net
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 mcvjetko@holisticware.net
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 mcvjetko@holisticware.net
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”); mcvjetko@holisticware.net
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 mcvjetko@holisticware.net
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) mcvjetko@holisticware.net
Mono for Android 9 – Cons 1 • Performance • 2 VMs: Mono + Java VM – Dalvik - interop/marshalingvery controversaltest 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) mcvjetko@holisticware.net
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 similarFriction 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 mcvjetko@holisticware.net
RIP Mono 2002-2011 mcvjetko@holisticware.net
Mono for Android 12 – Refs / Links 1 • Official • http://mono-android.netgone from Novell web in 2011/06/ ???????? • Download (free cannot deploy to device, only emulator) • http://mono-android.net/Welcome • FutureXamarinhttp://www.xamarin.com • Diverse • http://morewally.com/cs/Default.aspx • http://blogs.infosupport.com/blogs/willemm/archive/2011/03/23/introducing-monodroid.aspx • http://www.mono-droid.com/ • http://conceptdev.blogspot.com/ mcvjetko@holisticware.net
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-development-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 mcvjetko@holisticware.net
Mono for Android 14 – Q&A • ?????????????????????????? • VB • Mono – yes • Mono 4 Android – no • no Vb templates • Compiler status? mcvjetko@holisticware.net