Вы находитесь на странице: 1из 34

Android Basic Course

Module 2: Getting Started with Android Development

M.Sc. Bui Tan Loc btloc@fit.hcmus.edu.vn

Department of Software Engineering, Faculty of Information Technology, University of Science Ho Chi Minh City, Viet Nam
.

2012 University of Science HCM City

Android Basic Course

Objectives

After completing this module, you will have learned:


About installing the Android development environment About using SDK Manager and AVD Manager About Android project structure About launching an Android application with different
emulators

corresponding different platforms About DDMS tools About how to debug an application About changing xml resource file by GUI or Text editor.

2012 University of Science HCM City

Android Basic Course

Contents

Getting to install the Android development environment Getting to know Android SDK tools Getting to know Android project structure Getting to know how to run with the default emulator Getting to know how to run with the specified emulator Getting to know DDMS tools Getting to know how to debug with the default emulator Getting to know how to change xml resource files

2012 University of Science HCM City

Android Basic Course

Getting to install the Android development environment

Supported OS:
JDK

Pre-requirement:

Windows, Mac OS X, Linux

1. Installing Editor:

2. Installing SDK Starter Package (SDK Manager):


3. Installing ADT plugin for Eclipse: 4. Using

this called set path)

Eclipse (Eclipse classic version is recommended)

Note that you need to refer to the SDK directory (In Windows OS,

Configuring Eclipse to work with SDK Manager


SDK Manager to add platforms and other components:
SDKs, documents, sample source codes, etc.
. 4

2012 University of Science HCM City

Android Basic Course

Installing JDK

http://www.oracle.com/technetwork/java/javase/downlo
ads/index.html Ex:

The installation directory is c:\Program Files\Java\ The JDK folders path is c:\Program Files\Java\jdk1.6.0_17

2012 University of Science HCM City

Android Basic Course

Installing Eclipse Editor

http://www.eclipse.org/downloads/ Ex: At

The installation directory is d:\Program Files\ The Eclipse folders path is d:\Program Files\eclipse\
Ex: The workspace folder is d:\Program Files\eclipse\workspace\ Ex: File > Switch workspace > Other

the first time launching Eclipse, you must select a workspace folder to store your projects.

You can change workspace folder at any time you want.

2012 University of Science HCM City

Android Basic Course

Installing SDK starter package (SDK Manager)

http://developer.android.com/sdk/index.html Ex:
windows\

The installation directory is d:\Program Files\Android\ The SDK folders path is d:\Program Files\Android\android-sdk-

2012 University of Science HCM City

Android Basic Course

Installing ADT plugin for Eclipse

http://developer.android.com/sdk/eclipse

adt.html#installing
Start Eclipse, then select Help > Install New Software.... Click Add, in the top-right corner. In the Add Repository dialog that appears, enter "ADT Plugin" for the Name and the following URL for the Location: https://dl-ssl.google.com/android/eclipse/ Click OK Note: If you have trouble acquiring the plugin, try using "http" in the Location URL, instead of "https"
(https is preferred for security reasons).

In the Available Software dialog, select the checkbox next to Developer Tools and click Next. In the next window, you'll see a list of the tools to be downloaded. Click Next. Read and accept the license agreements, then click Finish. Note: If you get a security warning saying that the authenticity or validity of the software can't be
established, click OK.

When the installation completes, restart Eclipse


. 8

2012 University of Science HCM City

Android Basic Course

Updating the ADT Plugin

Want to update the ADT plugin, see more :

http://developer.android.com/sdk/eclipse-adt.html#installing

2012 University of Science HCM City

Android Basic Course

Installing ADT plugin for Eclipse

10

2012 University of Science HCM City

Android Basic Course

Configuring Eclipse to work with SDK Manager

Start Eclipse, then Select Window > Preferences... to

open the Preferences panel (Mac OS X: Eclipse > Preferences). Select Android from the left panel. You may see a dialog asking whether you want to send usage statistics to Google. If so, make your choice and click Proceed. You cannot continue with this procedure until you click Proceed. For the SDK Location in the main panel, click Browse... and locate your downloaded SDK directory. Click Apply, then OK.

11

2012 University of Science HCM City

Android Basic Course

Configuring Eclipse to work with SDK Manager

12

2012 University of Science HCM City

Android Basic Course

Getting to know Android SDK tools

SDK

Manager is used for adding platforms and other components.

AVD

Start Eclipse, then Select Android SDK Manager Or launch SDK Manager.exe in Android SDK folder

(Android Virtual Device) Manager is used for creating emulators corresponding to the selected platforms.

Start Eclipse, then Select AVD Manager Or launch AVD Manager.exe in Android SDK folder

13

2012 University of Science HCM City

Using SDK Manager to add platforms and other components

Android Basic Course

14

2012 University of Science HCM City

Android Basic Course

Using AVD Manager to create a new emulator

15

2012 University of Science HCM City

Android Basic Course

Testing your development environment

If above things are be ready-towork. You will run the HelloWorld Application successfully. http://developer.android.com/res ources/tutorials/hello-world.html

16

2012 University of Science HCM City

Android Basic Course

Getting to know project structure


contains java source files is generated when res folder is modified is selected platform to build the application is application package that will be installed on emulators or real devices are image resources

describes UI components describes string constant values

is an application configuration file


. 17

2012 University of Science HCM City

Android Basic Course

Getting to know how to switch platform

Right

click the project root, then select Properties > Android > select the platform you want.

18

2012 University of Science HCM City

Android Basic Course

Getting to know how to run with the default emulator

Run

application with the default emulator


> Android Application

Right click project, then select Run As

19

2012 University of Science HCM City

Android Basic Course

Getting to know how to run with the specified emulator

Run application with the specified


emulator

Right click project, then select Run As

> Run Configurations > select the specified emulator

20

2012 University of Science HCM City

Android Basic Course

Getting to know how to run with the specified emulator

21

2012 University of Science HCM City

Android Basic Course

Getting to know DDMS tools

The ADT plug-in in Eclipse provides some useful tools to

control your Android Emulator. In Eclipse, click on the Open Perspective button and select DDMS or select Other/DDMS.

22

2012 University of Science HCM City

Android Basic Course

Overview DDMS Tools

23

2012 University of Science HCM City

Android Basic Course

Overview DDMS Tools

24

2012 University of Science HCM City

Android Basic Course

Getting to know how to debug with the default emulator

Debug application with the


default emulator

Right click project, then select Debug


As > Android Application Select Yes to open Debug Perspective

25

2012 University of Science HCM City

Android Basic Course

Insert breakpoint

26

2012 University of Science HCM City

Android Basic Course

Debug tools

Run/Resume Suspend Terminate Step Into Step Over Step Return

27

2012 University of Science HCM City

Android Basic Course

Debug tools

Viewing variables in a function automatically

Viewing specified variables in a function

28

2012 University of Science HCM City

Getting to know how to change xml resource file: main.xml, string.xml, and AndroidManifest.xml

Android Basic Course

There are two ways to change these xml files:


Using text editor Using GUI editor

29

2012 University of Science HCM City

Android Basic Course

Ex: Using text editor to change main.xml

30

2012 University of Science HCM City

Android Basic Course

Ex: Using GUI editor to change main.xml

31

2012 University of Science HCM City

Android Basic Course

Questions or Discussions

How to install a new Android platform How to create an Android emulator How to run an Android application

with different emulators corresponding different platforms How to emulate voice calls, SMS messages, and GPS functionalities How to debug an Android application with different emulator corresponding different platforms How to modify xml files in the Android project

32

2012 University of Science HCM City

Android Basic Course

References & Further Readings

Installing the SDK:

Getting Started with Android Development: Managing AVDs with AVD Manager:
avds.html
android-development

http://developer.android.com/sdk/installing.html

http://mobiforge.com/developing/story/getting-started-with http://developer.android.com/guide/developing/devices/managing http://developer.android.com/guide/developing/devices/managingavds-cmdline.html

Managing AVDs from the Command Line:

Using the Android Emulator:


tml

http://developer.android.com/guide/developing/devices/emulator.h
. 33

2012 University of Science HCM City

Android Basic Course

References & Further Readings

Creating an Android Application using the Eclipse Plugin Adding an External Library (.jar) using Eclipse
ddexternallibrary

http://developer.android.com/resources/faq/commontasks.html#n
eweclipseandroidproject

http://developer.android.com/resources/faq/commontasks.html#a http://developer.android.com/resources/faq/commontasks.html#lo
calhostalias

Referring to localhost from the emulated environment

34

2012 University of Science HCM City

Вам также может понравиться