Android Development Getting Started and Crossing Platforms By
Android Development Getting Started and Crossing Platforms By Stephen Damm
Me. . . • Undergraduate at the University of Saskatchewan ▫ Finishing this year! ▫ Worked as a Surf. NET intern (Sept 2010 – Sept 2011) • Main skills: ▫ ▫ C/C++ development Low level development Game development and design Hardcore gamer • Started a company, Sandstorm ▫ Mobile game development ▫ Working on our first big release!
Homebrew • Hobbie programming done at home • My Homebrew: ▫ PS 3 �Released first ports of FCEU and VBA �Brought GPU shaders to the emulation world � 2 x. SAI, hq 2 x, Super. Eagle ▫ Android apps: �Gen. Plus. Droid, NESDroid, Gambatte. Droid, SNESDroid, Handy. Clicker
Homebrew Cafe • Blog / Forums • Main focus: ▫ PS 3, Xbox 360, Android, XNA development • www. homebrewcafe. net ▫ http: //blackbird. usask. ca • Contact me if you wish to contribute!
Outline 1. 2. 3. 4. Android Development Crossing Platforms Becoming A Developer
Android
Smartphone Dubbed - 1997
Android Beginnings • “First commercially available phone to run Android was the HTC Dream, released on October 22, 2008” • Compare to: ▫ ▫ ▫ Apple: 2007 – Iphone Black. Berry: 2002 – Black. Berry Palm: 2001 Windows: 2000 Nokia: 1996 – Nokia 9000 IBM: 1992 – Simon �Touchscreen + no physical buttons!
Market Share – The Last Year
Market Share – July 2011
As A Developer • 40%+ sure sounds nice if you could only choose one platform!
The Android OS - Codebase • Fully open source ▫ Managed in a GIT repository ▫ http: //source. android. com/ • Compiling ▫ Uses GNU Build tools (make, gcc) • Deploying ▫ Any device with an open bootloader ▫ Android emulator ▫ Jailbroken Ipad can even run Android OS: �http: //www. idroidproject. org/ ▫ Custom x 86 version runs in virtualization: �http: //www. android-x 86. org/
The Android OS – Codebase • Compare to: ▫ Apple, Black. Berry, Palm OS �Closed source software and hardware ▫ Windows Mobile �Closed source software ▫ Nokia �Symbian OS is proprietary ▫ web. OS �Closed source with some open sourced libraries
The Android OS - Codebase • Pros: ▫ ▫ Separation of workload Free to manufacturers Community support Custom distributions (ie. Cyanogen) �http: //www. cyanogenmod. com/ ▫ More consumer choices in hardware • Cons: ▫ Custom distributions, a pain to everyone ▫ To many choices, consumers overwhelmed
Android Hardware • Primarily ARM based ▫ RISC based (Reduced instruction set computing) ▫ ARMv 5, ARMv 7, Snapdragon, NVidia Tegra • Google recently added x 86 support ▫ x 86 OS not available yet but we can compile for it! • Hardware Guarantees (* = >Android 1. 6) ▫ ▫ ▫ Touch Screen Accelerometer and Compass* GPS receiver* Bluetooth transceiver* 802. 11 g
Android Certification • Test Suits: ▫ An automated set of test suits �http: //source. android. com/compatibility/download s. html ▫ All built in Java by Google • Why bother: ▫ Access to Android Market ▫ Use of Android branding
Android Compatibility • Public API ▫ Absolutely must implement correctly �The SDK • Private API ▫ Signatures must remain the same ▫ Implementation is manufacturer’s choice
Android – Targeting Hardware • 500+ Registered devices ▫ Way to many to fathom testing them all • Hardware ▫ The version of OS the device initially releases with will generally determine its “generation” in terms of hardware functionality and specs • Code ▫ Using the public API will always work ▫ Using the private API is dangerous
As A Touch Device • As of Android 2. 0 / IOS / Black. Berry Playbook ▫ Multi-Touch �>= 2 fingers �Maximum is device specific �Often given a radius in normalized device coordinates of the estimated area a touch is covering ▫ Gesture Recognition �Automatic in most API’s �Pinch and Zoom �Fling
Moment of Silence #1 - web. OS
Moment of silence #1 - web. OS • web. OS died on August 18 th, 2001 ▫ http: //www. engadget. com/2011/08/18/hp-will-discontinue-operationsfor-webos-devices/ • Not really dead but. . . ▫ HP is getting out of the hardware game ▫ Now not a single OEM now for web. OS • HP Touch. Pad ▫ Price reduced from $399 to $99 (16 GB model) ▫ Mass liquidation, #1 selling Electronic on Amazon overnight • Developer Reaction: ▫ Not even a blip ▫ Microsoft steals web. OS devs with free hardware
Moment of Silence #2 – Symbian OS • February 2011 ▫ Nokia teams with Microsoft • August 2011 ▫ Nokia drops all Symbian based smart phones in North American market • What happened: ▫ Slipping market share ▫ Choosing to focus primarily on hardware
Moment of Silence #2 - Symbian OS • Results ▫ Symbian OS and Qt’s future put into question ▫ Nokia’s 200 million Symbian users disenfranchised ▫ Symbian developers at a loss • Prediction ▫ Although not official declared dead. . .
Outline 1. 2. 3. 4. Android Development Crossing Platforms Becoming A Developer
Android Development
Android Dev – Getting Started • Tools: ▫ All major OS supported: ▫ ▫ ▫ � Linux, Windows, OSX Eclipse 3. 5+ All CLI supported Version Control System (recommended) � Git, Mercurial, Subversion • Compare ▫ Apple ▫ ▫ � OSX, XCode Windows Mobile � Windows OS, Visual Studio Black. Berry � Windows OS (unofficially can run on any OS), Eclipse
Android Dev – Getting Started • Avoiding the boring details: ▫ Download Eclipse: �http: //www. eclipse. org/downloads/ ▫ Download SDK: �http: //developer. android. com/sdk/index. html ▫ Installation Guide: �http: //developer. android. com/sdk/installing. html
Android Dev – Eclipse SDK Path ▫ Window -> Preferences
Android Dev – New Project • Simple ▫ Eclipse -> File -> New -> Project -> Android
Android Dev –Deploy/Run Snake
Android Dev – Emulator
Android Dev - Emulator • Pros: ▫ Runs on any OS • Cons: ▫ ▫ Slow deploy times Uses ~2 GB of RAM No Open. GL ES 2. 0 support Does not replace testing on Android devices
Android Dev - Manifest • Defines: ▫ ▫ ▫ ▫ Target and min SDK versions Application name Application package Version code Version name Entry point Valid Activities Extra configuration control
Android Dev – Activity Class • Activity is your Entry Point • Activity is not your Application ▫ Application is a global context ▫ Application manages Activities ▫ Application does require a main activity • Application can contain many Activities ▫ Managed as a stack
ADB – Android Device Bridge • ADB is a daemon ▫ Runs on your PC �Windows, Linux, OSX ▫ Bridges access to any Android device or emulator �Device -> loopback 127. 0. 0. 1 -> PC ▫ Gain access to device terminal shell �Root access required to do anything complex • Swiss army knife for android tasks!
Dalvik Debug Monitor Server (DMMS) • • • Automatically get heap usage See all running threads Device screenshots Control process affinity Allocation tracker Full Java profiler - Traceview ▫ The best part!
Traceview • Code profiler
Outline 1. 2. 3. 4. Android Development Crossing Platforms Becoming A Developer
Crossing Platforms
Developers Interest - Mobile
Crossing Platforms • Reasons: ▫ Constantly changing field �Never know when a platform will disappear ▫ Future proofing �Cross platform solutions are just that, not tied to any specific platform ▫ More participants �Data collection studies ▫ More profits
Crossing Platforms • Obstacles: ▫ Persistent storage ▫ Widgets ▫ Device specific limitations, functionality • Native Development ▫ Back to the basics. . . ▫ Working in C/C++
Crossing Platforms - Solutions • Naive “Hardcore” approach: ▫ ▫ ▫ Everything in C/C++ Open. GL Roll own GUI SQLite Utilize Bridge pattern:
Bridge Design Pattern • "decouple an abstraction from its implementation so that the two can vary independently"
Crossing Platforms - Repository • Use GIT or Mercurial ▫ Branch control ▫ Powerful merge tool ▫ Password-less key support • Why not SVN? ▫ Not conducive to cross platform projects ▫ Branching support is weak at best • Private repo ▫ Github paid account ▫ Run your own linux server, install gitosis
Crossing Platforms - Solutions • HTML 5 ▫ Write core user interface logic in HTML 5 ▫ Platform specific HTML viewer �Use bridge pattern again ▫ Use HTTP requests to call core application logic ▫ HTML 5 has local persistent storage or use SQLite • HTML 5 Problems: ▫ Performance ▫ Will never look identical on all browsers
Crossing Platforms - Solutions • Adobe AIR ▫ Write user interface in Action Script ▫ Leverage years of flash development ▫ Compile and hook with any C/C++ shared library �C/C++ -> LLVM -> Binary -> SWF ▫ Runs inside a flash emulator on mobile devices ▫ Can publish on Android Market • Adobe AIR Problems: ▫ Single-threaded on mobile devices ▫ No Bluetooth support ▫ No easy way to access device specific tasks
Crossing Platforms - Solutions • Unity ▫ Can compile for: �PS 3, Wii, XBOX, IOS, Android, more ▫ High performance �Essentially a lightweight wrapper of Open. GL & Direct. X ▫ Cost �EXPENSIVE! �Risky to start
Crossing Platforms – Solutions • GUI Toolkits: ▫ Phonegap (free): http: //docs. phonegap. com/ ▫ Mosync (free): http: //www. mosync. com/ • Pros: ▫ Expose device functionality (bluetooth, gps, cameras) • Cons: ▫ Still limiting ▫ Exception of Unity, major performance issues
Crossing Platforms – Solutions • “Use the right tool for the right job” ▫ Games �Naive approach �C/C++/Open. GL �Lightweight hand rolled GUI ▫ Data collection (research) �HTML GUI with hooks to native code �Handle all bluetooth, gps, etc logging in native side ▫ Interface Driven �Use an existing library for robust GUI (Qt, Phonegap, Mosync) �Perform application logic native side
Language Use - Google Code
Language Use – Tiobe Index
Language Use – Trend • Java / C# ▫ Enterprise applications • C/C++ ▫ ▫ “write once run everywhere” Dominates open source domain Games When performance matters • C dominates C++ ▫ What you see is what you get ▫ Best choice for true “run everywhere” • The motto still applies: ▫ “Use the right tool for the right job”
Language Use – Revival • C/C++ on the rise again ▫ Mobile devices ▫ Huge indie game development push • Interesting 10 slide read: ▫ http: //www. eweek. com/c/a/Application. Development/Top-10 -Programming-Languages-to -Keep-You-Employed-719257/
Open Source • “Don’t reinvent the wheel” • Leverage existing solution • Often the best solution: ▫ ▫ Eigen matrix math VLC media player and Ffmpeg Apache HTTP 7 zip • Licensing issues ▫ GPLv 2+, LGPLv 2, non-commercial
Android NDK The True Power of Android
Android Dev – NDK • Opens up use of C/C++ ▫ Compile straight to ARM object code • Uses GNU Tools ▫ gcc, g++, make ▫ Even supports STL, C++0 x, C++1 x • Designed for performance critical code • As of Android 2. 3 apps can be 100% native ▫ Remove use of Java completely
Android NDK – Build Toolchain • Prebuilt ▫ Use Google’s Makefile syntax ▫ Easy to compile to multiple CPU’s • Standalone Toolchain ▫ Use GNU make ▫ Directly call android build toolchain ▫ More flexible for cross platform projects
NESDroid • You. Tube – NESDroid
NESDroid – Real Time Rewind • Utilizing the powerful performance and memory control of C ▫ Youtube – NESDroid Rewind
NESDroid – Real Time Rewind • Using video and TCP network transmission compression techniques ▫ Key I-Frame is initial RAM on game load ▫ Every other frame is a P-Frame �XOR diff of previous state • Mass reduction in space ▫ Raw Data for NES frames �(Pixels + Palette + VRAM + SRAM) = ~79297 bytes ▫ 30 s of RAW frames � 60 fps * 30 s * 79297 bytes = 142734600 bytes = ~136 MB ▫ 30 s of Compressed frames �Averages 20 MB, ~85% reduction �Varies based on the game
Outline 1. 2. 3. 4. Android Development Crossing Platforms Becoming A Developer
Becoming A Developer
Android Developer - Registration • One time $25 Registration Fee • Requires ▫ Google Account ▫ Credit Card • Compare to: ▫ Apple – $99/year ▫ Black. Berry – no fee, $20 for signing key
Android Developer - Publishing • Signing ▫ All markets require developers to sign their application package • Packaging ▫ All assets are compressed into an APK ▫ Multiple platform compilations can exist in APK � A “fat” APK can contain x 86, armv 5 and armv 7 builds • Updating ▫ Simply push a new version of the APK • Pricing ▫ Free or paid ▫ Google takes 30% of all sales � Same for Apple and Black. Berry ▫ In-App purchasing allowed (sell virtual goods)
Android Developer - Publishing • Eclipse does the following for you: ▫ Signing ▫ Packaging the APK
The Android Market – Your App • Ranking ▫ Hidden to developer and users ▫ Based on: �Download count �Active install count �App ratings �Developers rating on other apps
The Android Market – Rating • User driven • Ratings are often generous or damning ▫ Either 4 -5 star or 1 star • Comments are often complaints ▫ Happy users go on happy ▫ Angry users go on complaining • Developers cannot respond to comments ▫ No way to further an inquiry ▫ No way to discuss with end user his complaint
GENPlus. Droid QR Code • Free • All Android 2. 2 devices
Download this! • QR Code:
Questions • Contact Info ▫ Stephen Damm ▫ shinhalsafar@gmail. com ▫ http: //blackbird. usask. ca • Slides available soon!
- Slides: 108