AN INTRODUCTION TO ANDROID DEVELOPMENT CS231M | Alejandro Troccoli
Outline
! Overview of the Android Operating System ! Development tools ! Deploying application packages ! Step-by-step application development ! Calling native code from your application
The Android ecosystem
! An open source platform for mobile, embedded and wearable devices
! Google is the principle maintainer ! Other companies contribute to the system. ! Each device manufacturer can customize Android to suite their
needs
Android architecture
Linux Kernel (GPL license) C code – compiled to native platform (x86, arm, mips)
Native framework layer User mode C, C++ code – compile to native platform or 32bit
compatibility mode on 64 bits.
Android framework Java classes under com.android
User applications Use Java framework and, optionally, native code.
Android versioning
! Plaform version ! 4.4.2 KitKat ! 4.4.3 Jellybean MR2
! Framework API level ! SDK compatibility ! Each platform version has an API level
! NDK API level ! API level for native headers
Browsing the Android Source
! Source at: ! https://android.googlesource.com/
! Porting instructions (for system developers) ! https://source.android.com/devices/index.html
! New camera HAL ! https://source.android.com/devices/camera/camera.html
Reference to the framework APIs
! com.android classes ! http://developer.android.com/reference/packages.html
Outline
! Overview of the Android Operating System ! Development tools ! Deploying application packages ! Step-by-step application development ! Calling native code from your application
Tools for application development
! Android SDK ! Provides the Java framework classes ! Compiles to java bytecode ! Class framework is updated with every OS release
! Android NDK ! C/C++ toolchain for compiling to machine code
! Android platform tools ! adb (android debug bridge) : runs and debugs apps from your dev machine
! Android developer tools ! Eclipse plug-in for Android
All tools packed in a Virtual Machine
! To speed up setup, a virtual machine has been setup.
Tegra Android Development Pack
Tegra Android Development Pack
! Register for an account at: ! https://developer.nvidia.com/user/register
! Sign-up for Gameworks Registered Developer Program
Tegra Note 7
Click 7 times to enable developer options
Application packages
! .apk files: compressed files ! class byte code ! resources( icons, sounds, etc). ! Binary native files
! All .apks are signed ! Default development key is created by SDK. ! When updating an application, signature are checked.
Outline
! Overview of the Android Operating System ! Development tools ! Deploying application packages ! Step-by-step application development ! Calling native code from your application
Installing an application
! From application distribution markets ! Google Play ! Amazon AppStore
! From your local computer using adb
Enabling android debug bridge (adb)
Outline
! Overview of the Android Operating System ! Development tools ! Deploying application packages ! Step-by-step application development ! Calling native code from your application
Useful adb commands
Hello Android!
! In Eclipse ! File -> New -> Android
Application Project
Hello Android!
Hello Android!
Import an project from existing code
AndroidManifest.xml
! Package Name / version ! Required SDK and target SDK ! Application/Activities ! Permissions
Android Activity
! Provides user interaction ! http://developer.android.com/reference/android/app/Activity.html
! Callbacks for life-cycle management ! onCreate() ! onResume() ! onPause()
! An application can have multiple activities.. ! Needs one launcher activity…
HelloAndroidActivity
HelloAndroidActivity
! Use onCreate() to create UI.
Launch!
Add Activity to AndroidManifest.xml:
Launch! (take 2)
Launch with debugger
Launch (take 3!)
Views
! Can be composed in a tree hierarchy. ! The root View is the argument to setContentView
Creating a layout
Accessing layout elements from Activtiy
! Use findViewById R.id.name corresponds to the name given in the xml file
Event listeners (and logging, too)
Logcat
! Window -> Show View -> Other -> Android -> Logcat
Creating a log file
Writing to the log file
Long running task
! Long running tasks on the main thread can block the UI ! App looks unresponsive
Use a separate Thread instead
Use Handlers to update UI
Add a Progress dialog
Outline
! Overview of the Android Operating System ! Development tools ! Deploying application packages ! Step-by-step application development ! Calling native code from your application
Adding native code: Java Native Interface
In the Java class, add a method without implementation and the native prefix
Create the jni headers: > javah –d jni –classpath .\bin\classes edu.stanford.cs231m.helloandroid.HelloAndroidActivity
Adding native support
! Right-click on project -> Android Tools -> Add Native Support
Android.mk
! Makefile for NDK
HelloAndroid.cpp
Let’s run it!
! Modify the Java code to call square and run the app…
Unfortunately, HelloAndroid has stopped.
Need to load the native library into the Java virtual machine!
Application.mk
! Makefile options that are applied to all modules! ! Target ABI ! Choice of STL implementation ! Global compiler options..
Debugging Native Code
! Enable debug build with NDK_DEBUG
Launch: Debug as Native app
Need to wait for debugger to attach
Little trick to wait for debugger
Android.mk
Define waitForDebugger() and insert a call to wait in your program. Once the debugger attaches, pause the program and set _debug to 0.
Top Related