Download presentation only

Survey
yes no Was this document useful for you?
   Thank you for your participation!

* Your assessment is very important for improving the workof artificial intelligence, which forms the content of this project

Document related concepts
no text concepts found
Transcript
Mono for Android
<Monodroid>
.net for Android
HowTo:
MultiTargeting-PortabilityInteroperability
for .netters
2011.06.30 MSCommunity.DevUG.Zg
[email protected]
1
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]
2
Motivation 2 - Market Share Current
• Wikipedia
Source
Gartner [24]
Gartner [25]
Gartner [25][26]
Gartner [26][27]
Gartner [27]
Year
2011 Q1
2010
2009
2008
2007
Symbian
27.4%
37.6%
46.9%
52.4%
63.5%
Android
36.0%
22.7%
3.9%
0.5%
N/A
RIM
12.9%
16.0%
19.9%
16.6%
9.6%
iOS
16.8%
15.7%
14.4%
8.2%
2.7%
Microsoft
3.6%
4.2%
8.7%
11.8%
12.0%
Other
3.3%
3.8%
6.1%
10.5%
12.1%
• References
– http://en.wikipedia.org/wiki/Mobile_operating_system#Market_projection
2011.06.30 MSCommunity.DevUG.Zg
[email protected]
3
Motivation 3 - Market Share Projection
Gartner
OS
Symbian
Android
RIM
iOS
Microsoft
Other OS
Total [k]
2010
111,577
67,225
47,452
46,598
12,378
11,417.40
296,647
[%]
37.6
22.7
16
15.7
4.2
3.8
2011
89,930
179,873
62,600
90,560
26,346
18,392.30
467,701
[%]
19.2
38.5
13.4
19.4
5.6
3.9
2012
32,666
310,088
79,335
118,848
68,156
21,383.70
630,476
[%]
5.2
49.2
12.6
18.9
10.8
3.4
2015
661
539,318
122,864
189,924
215,998
36,133.90
1,104,898
[%]
0.1
48.8
11.1
17.2
19.5
3.3
• References
– http://www.gartner.com/it/page.jsp?id=1622614
– http://socialtimes.com/gartner-idc-agree-about-mobile-marketshare-in-2015-butdisagree-about-2011_b56708
2011.06.30 MSCommunity.DevUG.Zg
[email protected]
4
Motivation 4 - Software Eng
PL1
PLn
BL1
BLn
PLn
PL1
BL
• Multilayer architecture
– Business Logic / Model x%
– Presentation Layer / View y%
2011.06.30 MSCommunity.DevUG.Zg
[email protected]
5
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]
9
Android 2 – Architecture/Stack
2011.06.30 MSCommunity.DevUG.Zg
[email protected]
11
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]
12
Android 9 – App Fx 7 External data
External 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)
Function
Path
Access programatically
UI
layout/filename.xml
layout-land/main.axml
// R.layout.filename
TextView 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);
2011.06.30 MSCommunity.DevUG.Zg
[email protected]
19
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]
20
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, orientation
LinearLayout, AbsoluteLayout, RelativeLayout, tableLayout,
FrameLayout, ScrollView
2011.06.30 MSCommunity.DevUG.Zg
[email protected]
21
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]
24
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]
25
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]
26
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]
27
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]
28
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]
29
Mono for Android 4 –
Architecture/Stack
2011.06.30 MSCommunity.DevUG.Zg
[email protected]
32
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 API
type 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]
33
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]
34
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]
35
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]
36
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]
39
Mono for Android 9 – Cons 1
• Performance
– 2 VMs: Mono + Java VM – Dalvik - interop/marshaling
very 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]
42
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
[email protected]
43
RIP
Mono
2002-2011
2011.06.30 MSCommunity.DevUG.Zg
[email protected]
44
Mono for Android 12 – Refs / Links 1
• Official
– http://mono-android.net
gone from Novell web in 2011/06/ ????????
– Download (free cannot deploy to device, only emulator)
• http://mono-android.net/Welcome
– Future
Xamarin http://www.xamarin.com
• Diverse
• http://morewally.com/cs/Default.aspx
• http://blogs.infosupport.com/blogs/willemm/archive/2011/03/23/intr
oducing-monodroid.aspx
• http://www.mono-droid.com/
• http://conceptdev.blogspot.com/
2011.06.30 MSCommunity.DevUG.Zg
[email protected]
45
Mono for Android 13 – Refs / Links 2
• Code samples
• https://github.com/mono/monodroid-samples
• https://github.com/kevinmcmahon/MonoDroid101
• https://github.com/gshackles/SampleProjects/tree/master/MonoDroid/MonoDroidSamples
• https://github.com/gshackles/Sample-Projects/
• https://github.com/conceptdev/RestaurantGuide/tree/master/RestGuide_And
roid
• Comparison
• http://www.holisticware.net/HolisticWare/Know-How/Development/uidevelopment-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]
46
Mono for Android 14 – Q&A
• ??????????????????????????
• VB
– Mono – yes
– Mono 4 Android – no
• no Vb templates
• Compiler status?
2011.06.30 MSCommunity.DevUG.Zg
[email protected]
47