Getting Started
With Android
Development
Abe Pralle
CS 477
February 9, 2012
tinyurl.com/android-development
Terminology
● SDK - the primary Java-based toolset.
● NDK - Native Dev Kit for C++ shared
object (.so) "DLL" libraries.
● APK - "Android Package" - the "JAR"
containing a standalone app.
● ADB - "Android Debug Bridge" - the
communication interface between your
computer and Android devices.
Terminology (continued)
● API Level - an integer that defines which
version of the Android API your app is
compatible with, e.g. 7 = OS 2.1.x, 8 = OS
2.2.x, etc.
● Thoughout slides, notation ">command"
means "type 'command' on a CMD prompt
or terminal.
Windows Setup
(including command line support)
1. Install the Java JDK:
http://www.oracle.com/technetwork/java/javase/down
loads/jdk-7u2-download-1377129.html
2. Install the ANT built system:
http://ant.apache.org/
○ Unzip and place in e.g. C:\Program Files (x86)\
○ Add C:\Prog...apache-ant...\bin to PATH
○ Run >ant in CMD window. If error about missing
"tools.jar", add JAVA_HOME environment
variable pointing to jdk base directory and open
new CMD window.
Windows Setup (continued)
3. Install the Android SDK:
developer.android.com/sdk/index.html
○ Add C:\...\android-sdk\tools and C:\...\android-
sdk\platform-tools to your PATH
Mac Setup
(including command line support)
Install the Android SDK:
developer.android.com/sdk/index.html
○ Unzip and place in /Applications folder
○ Edit /etc/paths (>sudo vim /etc/paths) and add the
following lines:
/Applications/android-sdk-mac_x86/tools
/Applications/android-sdk-mac_x86/platform-tools
General Setup
● Eclipse Plugin - popular but not covered here - see:
http://developer.android.com/sdk/eclipse-adt.html#installing
● >android brings up SDK Manager. >android --help
shows other options.
○ Launch SDK Manager and download recommended files - takes a
while (click "Accept All" on license agreement to avoid hassle).
○ Download optional OS versions to target specific API levels in
your apps.
● May want to create one or more AVD (Android
Virtual Device) emulators. Run Android SDK
Manager and select Tools>Manage AVDs...
● Under System Settings for device/emulator, find and
enable "Unknown Sources" and "USB Debugging".
Starter Project
1. Create directory for project and cd to it.
2. >android create project --name
"UserInterfaces" --target "android-8"
--path . --package edu.nau.cs477
--activity UserInterfacesActivity
3. >ant debug to compile.
4. >ant installd to install on emulator or
actual device (whichever is available).
5. Find the program in the "all apps" menu to
run it.
6. Menu>Manage Apps to delete it.
Choosing an API Level
● http://developer.android.com/guide/appendix/api-levels.html
● The lower you choose, the more devices
will be compatible with your app.
● Certain features only available in higher
API Levels.
● To support "Gen 1" devices (e.g. "G1")
choose API Level 4 (OS 1.6).
● Otherwise choose API Level 8 (OS 2.2.x)
unless you really need a certain feature.
API 8 is the first one that allows install to
SD Card.
Project Contents
AndroidManifest.xml
● Contains info & settings about app.
assets/
● Optional dir to store raw binary files that won't be preprocessed.
ant.properties
● Place to override default build properties, e.g. "target=android-10" to
change API used for build, not for distribution.
bin/
● Build products directory. Deletable.
build.xml
● The ANT build file.
gen/
● Used to compile resources (images etc.). Deletable.
Project Contents (continued)
libs/
● Place .JAR and .SO libraries here to be linked with your project.
local.properties
● Contains paths relative to your individual computer. Do not commit to
code repositories. Update with >android update project -p .
proguard.cfg
● Advanced settings for code obfuscator. Can be ignored.
project.properties
● Defines the API Level this project targets.
res/
● Contains text and image resources processed by build system.
src/
● Source code organized by package name.
API Basics
http://developer.android.com/reference/android/app/Activity.html
● Application manager extends "Activity"
(like an Applet).
● Activity has overridable onStart(),
onPause(), etc.
● Define a UI layout in the res/layout/
directory or programmatically define in
onCreate().
Debugging
● Type >ddms to launch log viewer window.
● Type >adb logcat to list log in current
window.
● In the program, System.out.println() and
System.err.println() will work.
● Official system is Log.d( "app name",
"mesg" ) for debug, Log.e(...) for error,
Log.wtf(...) etc.
Quirks and Caveats
● No easy way to terminate an app via the
OS User Interface (Menu>Manage
Apps>App Name>Force Stop).
● Must look in separate menus to launch
app and to remove from device.
● Device usually easier and quicker to test
on than emulator.
The End!
this.finish();