The Android Development Environment Getting started on the Android Platform Installing required libraries Programming Android using the Eclipse IDE The Android emulator Debugging Android applications Other tools See: developer.android.com/sdk/index.html#quickstart Software to download & install 1. 2. 3. 4. 5. Java Development Kit (JDK) Eclipse IDE Android SDK starter package Eclipse ADT plugin Add Android platform & other comps to SDK Download Java Development Kit www.oracle.com/technetwork/java/javase/downloads/ind ex.html Preferred IDE, but you can use others Requires version 3.5 or higher Eclipse Classic recommended http://www.eclipse.org/downloads/ Core tools needed to get started developer.android.com/sdk/ Unpack files to a directory of your choice By default: android-sdk-<machine-platform> Add this directory to your path to use Android tools from the command line Download the ADT plugin Use the Help -> Install New Software function URL for Eclipse 3.5+ ▪ https://dl-ssl.google.com/android/eclipse/ In the Available Software dialog, select the checkbox next to Developer Tools and click Next Configure plugin Open preferences, click on “Android” and set the SDK location Launch the Android SDK and AVD Manager Select at least the latest platform (2.3) An Android Virtual Device (AVD) is a configuration of emulator options An AVD includes: A hardware profile A platform Other options ▪ e.g., emulator skin, screen dimensions, SD card size A storage area Create using Android SDK and AVD Manager tool Start Eclipse Create a new Android Project Project name: HelloAndroid Application name: Hello, Android Package name: course.examples Create activity: HelloAndroid Min SDK: 9 package course.examples; import android.app.Activity; import android.os.Bundle; import android.widget.TextView; public class HelloAndroid extends Activity { public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); TextView tv = new TextView(this); tv.setText("Hello, Android"); setContentView(tv); } } Applications can run in an emulator Advantages Fast turnaround Doesn’t require an actual phone Uses faster CPU on emulation computer Disadvantages Some features unavailable ▪ e.g., no support for bluetooth or USB connections Performance & user experience can be misleading Emulates telephone calls & SMS messages % telnet localhost 5554 > sms send 5554 “This is a text message” Will emulate typical speeds & latencies for different networks (e.g., edge, gprs, etc.) % telnet localhost 5554 > set speed gprs Can interconnect multiple emulators % emulator -avd Android_2.2_primary % emulator -avd Android_2.2_secondary In one dialer app, dial port num of other emulator Many more options See: developer.android.com/guide/developing/tools/e mulator.html Can also add trace code into your application // start tracing to "/sdcard/calc.trace" Debug.startMethodTracing("calc"); … // stop tracing Debug.stopMethodTracing(); Will need to set permissions (discussed later) <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE /> To view results after execution % adb pull /sdcard/calc.trace /tmp % traceview /tmp/calc Log viewer Android logs many events by default Can use android.util.Log & android.os.Debug class for application-specific logging View log entries with % adb logcat Or inside Eclipse Window -> Show View -> Other -> Android -> LogCat Visual representation of application UI % hierarchyviewer Sends psuedorandom events to applications Can also script events with monkeyrunner API // send event to browswer % adb shell monkey -p com.android.browser -v 500 // send events to all applications % adb shell monkey 500 Android-specific extensions to Junit MoreAsserts Additional result checking classes ViewAsserts Asserts about view layout TouchUtils Classes for generating touch events Instrumentation For monitoring application interaction with system Steps for testing Activity Create an Android test project Create one or more Android test classes ▪ Add code to each Test class Test code usually includes test methods for App initialization UI behavior & class functionality Application lifecycle state management AndroidTestCase Test case with access to Activity Context ActivityUnitTestCase ▪ isolated testing of a single activity InstrumentationTestCase Test case with access to system instrumentation & events ActivityInstrumentationTestCase2 ▪ functional testing of a single activity Many other test case types developer.android.com/guide/topics/testing/testing_a ndroid.html Junit Test flow setup() Put application in known state run() Create additional data Execute method under test Check result with Assert tearDown() Return to known state developer.android.com/resources/tutorials/te sting/activity_test.html Key steps Declare your application as "debuggable" in your Android Manifest Turn on "USB Debugging" on your device Setup your system to detect your device See: developer.android.com/guide/developing/device. html