The Android Development Environment. Getting started on the Android Platform Installing required...
-
date post
19-Dec-2015 -
Category
Documents
-
view
223 -
download
3
Transcript of The Android Development Environment. Getting started on the Android Platform Installing required...
![Page 1: The Android Development Environment. Getting started on the Android Platform Installing required libraries Programming Android using the Eclipse.](https://reader031.fdocuments.us/reader031/viewer/2022032309/56649d2e5503460f94a0653d/html5/thumbnails/1.jpg)
Programming the Android Platform
The Android Development Environment
![Page 2: The Android Development Environment. Getting started on the Android Platform Installing required libraries Programming Android using the Eclipse.](https://reader031.fdocuments.us/reader031/viewer/2022032309/56649d2e5503460f94a0653d/html5/thumbnails/2.jpg)
Topics
Getting started on the Android Platform Installing required libraries Programming Android using the Eclipse
IDE The Android emulator Debugging Android applications Other tools
![Page 3: The Android Development Environment. Getting started on the Android Platform Installing required libraries Programming Android using the Eclipse.](https://reader031.fdocuments.us/reader031/viewer/2022032309/56649d2e5503460f94a0653d/html5/thumbnails/3.jpg)
Installation
See: developer.android.com/sdk/
index.html#quickstart Software to download & install
1. Java Development Kit (JDK)2. Eclipse IDE3. Android SDK starter package4. Eclipse ADT plugin5. Add Android platform & other comps to SDK
![Page 4: The Android Development Environment. Getting started on the Android Platform Installing required libraries Programming Android using the Eclipse.](https://reader031.fdocuments.us/reader031/viewer/2022032309/56649d2e5503460f94a0653d/html5/thumbnails/4.jpg)
Java
Download Java Development Kit www.oracle.com/technetwork/java/javase/
downloads/index.html
![Page 5: The Android Development Environment. Getting started on the Android Platform Installing required libraries Programming Android using the Eclipse.](https://reader031.fdocuments.us/reader031/viewer/2022032309/56649d2e5503460f94a0653d/html5/thumbnails/5.jpg)
Eclipse
Preferred IDE, but you can use others Requires version 3.5 or higher
Eclipse Classic recommended http://www.eclipse.org/downloads/
![Page 6: The Android Development Environment. Getting started on the Android Platform Installing required libraries Programming Android using the Eclipse.](https://reader031.fdocuments.us/reader031/viewer/2022032309/56649d2e5503460f94a0653d/html5/thumbnails/6.jpg)
Android SDK starter package
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
![Page 7: The Android Development Environment. Getting started on the Android Platform Installing required libraries Programming Android using the Eclipse.](https://reader031.fdocuments.us/reader031/viewer/2022032309/56649d2e5503460f94a0653d/html5/thumbnails/7.jpg)
Eclipse ADT plugin
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
![Page 8: The Android Development Environment. Getting started on the Android Platform Installing required libraries Programming Android using the Eclipse.](https://reader031.fdocuments.us/reader031/viewer/2022032309/56649d2e5503460f94a0653d/html5/thumbnails/8.jpg)
Add Components to SDK
Launch the Android SDK and AVD Manager
Select at least the latest platform (2.3)
![Page 9: The Android Development Environment. Getting started on the Android Platform Installing required libraries Programming Android using the Eclipse.](https://reader031.fdocuments.us/reader031/viewer/2022032309/56649d2e5503460f94a0653d/html5/thumbnails/9.jpg)
Create an Android Virtual Device 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
![Page 10: The Android Development Environment. Getting started on the Android Platform Installing required libraries Programming Android using the Eclipse.](https://reader031.fdocuments.us/reader031/viewer/2022032309/56649d2e5503460f94a0653d/html5/thumbnails/10.jpg)
HelloAndroid
Start Eclipse Create a new Android Project
![Page 11: The Android Development Environment. Getting started on the Android Platform Installing required libraries Programming Android using the Eclipse.](https://reader031.fdocuments.us/reader031/viewer/2022032309/56649d2e5503460f94a0653d/html5/thumbnails/11.jpg)
Hello Android
Project name: HelloAndroid Application name: Hello, Android Package name: course.examples Create activity: HelloAndroid Min SDK: 9
![Page 12: The Android Development Environment. Getting started on the Android Platform Installing required libraries Programming Android using the Eclipse.](https://reader031.fdocuments.us/reader031/viewer/2022032309/56649d2e5503460f94a0653d/html5/thumbnails/12.jpg)
Hello Android (cont.)
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); }}
![Page 13: The Android Development Environment. Getting started on the Android Platform Installing required libraries Programming Android using the Eclipse.](https://reader031.fdocuments.us/reader031/viewer/2022032309/56649d2e5503460f94a0653d/html5/thumbnails/13.jpg)
The Android Emulator
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
![Page 14: The Android Development Environment. Getting started on the Android Platform Installing required libraries Programming Android using the Eclipse.](https://reader031.fdocuments.us/reader031/viewer/2022032309/56649d2e5503460f94a0653d/html5/thumbnails/14.jpg)
The Android Emulator
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
![Page 15: The Android Development Environment. Getting started on the Android Platform Installing required libraries Programming Android using the Eclipse.](https://reader031.fdocuments.us/reader031/viewer/2022032309/56649d2e5503460f94a0653d/html5/thumbnails/15.jpg)
The Android Emulator
Many more options See:
developer.android.com/guide/developing/tools/emulator.html
![Page 16: The Android Development Environment. Getting started on the Android Platform Installing required libraries Programming Android using the Eclipse.](https://reader031.fdocuments.us/reader031/viewer/2022032309/56649d2e5503460f94a0653d/html5/thumbnails/16.jpg)
Debugger
![Page 17: The Android Development Environment. Getting started on the Android Platform Installing required libraries Programming Android using the Eclipse.](https://reader031.fdocuments.us/reader031/viewer/2022032309/56649d2e5503460f94a0653d/html5/thumbnails/17.jpg)
Execution Tracing
![Page 18: The Android Development Environment. Getting started on the Android Platform Installing required libraries Programming Android using the Eclipse.](https://reader031.fdocuments.us/reader031/viewer/2022032309/56649d2e5503460f94a0653d/html5/thumbnails/18.jpg)
Execution Tracing
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
/>
![Page 19: The Android Development Environment. Getting started on the Android Platform Installing required libraries Programming Android using the Eclipse.](https://reader031.fdocuments.us/reader031/viewer/2022032309/56649d2e5503460f94a0653d/html5/thumbnails/19.jpg)
TraceView
To view results after execution
% adb pull /sdcard/calc.trace /tmp% traceview /tmp/calc
![Page 20: The Android Development Environment. Getting started on the Android Platform Installing required libraries Programming Android using the Eclipse.](https://reader031.fdocuments.us/reader031/viewer/2022032309/56649d2e5503460f94a0653d/html5/thumbnails/20.jpg)
TraceView
![Page 21: The Android Development Environment. Getting started on the Android Platform Installing required libraries Programming Android using the Eclipse.](https://reader031.fdocuments.us/reader031/viewer/2022032309/56649d2e5503460f94a0653d/html5/thumbnails/21.jpg)
Logcat
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
![Page 22: The Android Development Environment. Getting started on the Android Platform Installing required libraries Programming Android using the Eclipse.](https://reader031.fdocuments.us/reader031/viewer/2022032309/56649d2e5503460f94a0653d/html5/thumbnails/22.jpg)
Hierarchy Viewer
Visual representation of application UI
% hierarchyviewer
![Page 23: The Android Development Environment. Getting started on the Android Platform Installing required libraries Programming Android using the Eclipse.](https://reader031.fdocuments.us/reader031/viewer/2022032309/56649d2e5503460f94a0653d/html5/thumbnails/23.jpg)
Layout inspector
![Page 24: The Android Development Environment. Getting started on the Android Platform Installing required libraries Programming Android using the Eclipse.](https://reader031.fdocuments.us/reader031/viewer/2022032309/56649d2e5503460f94a0653d/html5/thumbnails/24.jpg)
Pixel Perfect View
![Page 25: The Android Development Environment. Getting started on the Android Platform Installing required libraries Programming Android using the Eclipse.](https://reader031.fdocuments.us/reader031/viewer/2022032309/56649d2e5503460f94a0653d/html5/thumbnails/25.jpg)
Monkey & monkeyrunner
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
![Page 26: The Android Development Environment. Getting started on the Android Platform Installing required libraries Programming Android using the Eclipse.](https://reader031.fdocuments.us/reader031/viewer/2022032309/56649d2e5503460f94a0653d/html5/thumbnails/26.jpg)
Android Unit Testing
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
![Page 27: The Android Development Environment. Getting started on the Android Platform Installing required libraries Programming Android using the Eclipse.](https://reader031.fdocuments.us/reader031/viewer/2022032309/56649d2e5503460f94a0653d/html5/thumbnails/27.jpg)
Android Unit Testing (cont.)
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
![Page 28: The Android Development Environment. Getting started on the Android Platform Installing required libraries Programming Android using the Eclipse.](https://reader031.fdocuments.us/reader031/viewer/2022032309/56649d2e5503460f94a0653d/html5/thumbnails/28.jpg)
Android Unit Testing (cont.) 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_android.html
![Page 29: The Android Development Environment. Getting started on the Android Platform Installing required libraries Programming Android using the Eclipse.](https://reader031.fdocuments.us/reader031/viewer/2022032309/56649d2e5503460f94a0653d/html5/thumbnails/29.jpg)
Android Unit Testing (cont.)
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
![Page 30: The Android Development Environment. Getting started on the Android Platform Installing required libraries Programming Android using the Eclipse.](https://reader031.fdocuments.us/reader031/viewer/2022032309/56649d2e5503460f94a0653d/html5/thumbnails/30.jpg)
Android Unit Testing (cont.)
developer.android.com/resources/tutorials/testing/activity_test.html
![Page 31: The Android Development Environment. Getting started on the Android Platform Installing required libraries Programming Android using the Eclipse.](https://reader031.fdocuments.us/reader031/viewer/2022032309/56649d2e5503460f94a0653d/html5/thumbnails/31.jpg)
Running on a Device
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
![Page 32: The Android Development Environment. Getting started on the Android Platform Installing required libraries Programming Android using the Eclipse.](https://reader031.fdocuments.us/reader031/viewer/2022032309/56649d2e5503460f94a0653d/html5/thumbnails/32.jpg)
Lab Assignment