Anda di halaman 1dari 30

Part 2-a

Android Environment SDK


Notes are based on:
Android Developers http://developer.android.com/index.html

2A. Android Environment: Eclipse & ADT

Android Development Tools (ADT) plugin dnh cho Eclipse gn phn m rng cho Eclipse IDE. N cho php ta to v debug ng dng Android application nhanh hn v d hn. u im 1.Cho php s dng cc cng c pht trin Android (Android development tools) t bn trong Eclipse IDE. V d: Chp screenshot, Debug / t cc breakpoint, v Xem thng tin v thread v process trc tip t Eclipse. 2. New Project Wizard gip ta nhanh chng to v set up tt c cc file c bn m ta s cn cho mt ng dng Android mi. 3. N t ng ha v n gin ha quy trnh xy dng ng dng Android. 4. N cung cp mt trnh son tho m Android gip ta vit m XML cho Android manifest v resource file. 5. N s export project ca ta thnh mt signed APK giao cho ngi dng.
2

2A. Android Environment: Eclipse & ADT


Typical Layout of the Eclipse IDE for Android Development

2A. Android Environment: Eclipse & ADT


Typical Layout of the Eclipse IDE for Android Development (details)

Android SDK and AVD Manager New Android Project

DDMS Perspective Dalvik Debugging Monitoring System


4

2A. Android Environment: Eclipse & ADT


SETUP Download the Android SDK Installing on Windows, Linux, Mac OS
This page is taken from http://developer.android.com/sdk/index.html

Windows Mac OS X (intel) Linux (i386)

installer_r16-windows.exe android-sdk_r16-mac_86.zip android-sdk_r16-linux_86.tgz

Tng quan v cc bc ci t Android SDK: 1. Chun b my tnh p ng c cc yu cu h thng. 2. Ci gi SDK starter ly t trang web link trn. 3. Ci ADT Plugin cho Eclipse (nu s dng Eclipse vit ng dng). 4. B sung cho SDK cc Android platform v cc component khc. 5. Xem ni dung ca Android SDK (ty chn). bt u, ti gi ci t thch hp t link trn, sau c hng dn Installing the SDK. (http://developer.android.com/sdk/installing.html)

2A. Android Environment: Eclipse & ADT


Installing the SDK (Link: http://developer.android.com/sdk/installing.html) Trang ny m t cch ci Android SDK v thit lp mi trng pht trin cho ln u Updating? Nu ang dng Android SDK, ta nn cp nht tool hoc platform mi bng cch dng Android SDK and AVD Manager, thay v download mt gi SDK starter mi. Step 1. Chun b my tnh 1. ci bn JDK mi nht.

2. ci Eclipse (c th ti t http://www.eclipse.org/downloads/ (Vi Eclipse 3.5 hoc mi hn, nn dng bn "Eclipse Classic.

2A. Android Environment: Eclipse & ADT


Step 2. Ti gi SDK Starter Gi SDK starter khng phi l mt mi trng pht trin hon chnhn ch bao gm cc cng c SDK ct yu m ta dng download cc thnh phn khc ca SDK (chng hn Android platform mi nht). Nu ta download Windows installer (file .exe), hy chy n ci SDK Tools vo mt v tr trn a cng (ta c th chn), v d: c:/your-chosen-path/android-sdk-windows Ghi li tn v v tr ca th mc SDKta s cn n n khi set up ADT plugin v khi dng cc cng c SDK t dng lnh. Step 3. Ci ADT Plugin cho Eclipse Android cung cp mt plugin dnh cho Eclipse IDE, gi l Android Development Tools (ADT). Ta nn dng platform ny. Trc ht, ta nn c hng dn tng bc ci t ti Installing the ADT Plugin, sau quay li y tip tc thc hin bc cui dng ca vic set up Android SDK.
7

2A. Android Environment: Eclipse & ADT


Step 4. B sung cc Platform v cc component khc Ta s dng Android SDK and AVD Manager (mt cng c c trong gi SDK starter) download cc thnh phn SDK quan trng cho mi trng lp trnh. Nu dng Windows installer, khi wizard ci t xong, n s chy Android SDK and AVD Manager vi tp mc nh cc platform v cc component c nh du sn ta ci. Ch cn click Install chp nhn ci tp cc component c gi . Ta cn c th gi Android SDK and AVD Manager bng cc cch sau: T trong Eclipse, chn Window > Android SDK and AVD Manager. Ti Windows, double-click file SDK Manager.exe file ti th mc gc ca Android SDK. Ti Mac hoc Linux, m mt terminal v chuyn ti th mc tools/ ca Android SDK, ri chy lnh: android

2A. Android Environment: Eclipse & ADT


Step 4. B sung cc Platform v cc component khc (tip) download cc component, dng giao din ha ca Android SDK and AVD Manager. u tin ch chn cc phin bn mi nht ca Android (gm documentation, samples v USB driver) (Cnh bo: cng vic ny tn kh nhiu thi gian)

Figure 1. The Android SDK and AVD Manager's Available Packages panel, which shows the SDK components that are available for you to download into your environment.
9

2A. Android Environment: Eclipse & ADT


Installing the Eclipse ADT Plugin
(Link: http://developer.android.com/sdk/eclipse-adt.html#installing)
n gin ha vic thit lp ADT, nn ci Android SDK trc khi ci ADT.

Eclipse 3.6 (Helios) and Indigo 1.Start Eclipse, then select Help > Install New Software.... 2.Click Add, in the top-right corner. 3.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/ Note: If you have troubles try using "http" instead of "https Click OK. 4.In the Available Software dialog, select the checkbox next to Developer Tools and click Next. 5.In the next window, you'll see a list of the tools to be downloaded. Click Next. 6.Read and accept the license agreements, then click Finish. 7.When the installation completes, restart Eclipse.
10

2A. Android Environment: Eclipse & ADT


Configuring the ADT Plugin Bc tip theo l sa ADT preferences ti Eclipse chiu ti th mc ca Android SDK: 1. 2. 3. 4. Chn Window > Preferences... m Preferences panel (Mac OS X: Eclipse > Preferences). Chn Android panel bn tri. Vi mc SDK Location trong panel chnh, click Browse... V chn th mc SDK download ca ta (c:/path/android-sdk-windows) Click Apply, ri OK.

Done!

11

2A. Android Environment: Eclipse & ADT


Creating an Android Virtual Device (AVD) Mi Android Virtual Device (AVD) l mt cu hnh ca cc ty chn cho emulator ta c th m hnh ha mt thit b thc.
1.In Eclipse, choose Window > Android SDK and AVD Manager. 2.Select Virtual Devices in the left panel. 3.Click New. 4.The Create New AVD dialog appears. 5.Type the name of the AVD, such as AVD23API9". 6.Choose a target (such as Android 2.3 API Level9). 7.Optionally specify any additional settings (SD, camera, trackball, .) YES to all. 8.Click Create AVD.

12

2A. Android Environment: Eclipse & ADT


Testing the Emulator
1.In Eclipse, choose Window > Android SDK and AVD Manager. 2.Select Virtual Devices in the left panel. 3.Click on an AVD 4.Click Start.

13

2A. Android Environment: Eclipse & ADT


A Final Step Cp nhp bin h thng PATH h thng nhn hai th mc bn trong android-sdk-windows: tools v platform-tools. 1.Windows > Start > Control Panel > System > Advanced > Environment Variables > System Variables > PATH > Edit 2.Thm ng dn ti cc th mc ni trn. Trong v d ca ta l C:\androidsdk-windows\tools;C:\android-sdk-windows\platform-tools; 3.OK

14

Android Setup Videos


Appendix. Web resources available at

http://www.hometutorials.com/google-android.html
Nm video, hi c (SDK1.0) nhng vn hu ch. 1. How to setup Java. 2. How to install Eclipse IDE 3. Application development: Hello World using Eclipse + Android

15

Android Setup Tutorial


MAC OS Users
1. In a terminal window send the command: sudo su. You will act as the superuser. 1. Enter superusers password. After accepted, you will issue commands from a shell line. 2. Locate the file .profile and edit (pico, vi,) its path contents as follows: export PATH="/Users/myfolder/android-sdk-mac_86 3/tools":$PATH where "/Users/myfolder/android-sdk-mac_86 3/tools" (including the quotes) is the location of the /tools directory in our Android SDK folder.

16

Android Setup Tutorial


Appendix. Install Java

1. 2. 3. 4. 5.

Go to http://developers.sun.com/downloads/ Expand choice Java SE. Click on: Java SE (JDK) 6 From the list of choices select the most recent Java SE JDK (Update 14 in our case). Click on the Download button

17

Android Setup Tutorial


Appendix. Install Java

1. 2. 3. 4.

On the next screen select Platform (Windows) and accept license agreement. Hit the Continue button. Check box: Java SE Development Kit 6u14 and click on the download (arrow) symbol Save file to c:\

18

Android Setup Tutorial


Appendix. Install Java

5. Execute the downloaded file: jdk-6u14-windows-i586.exe 6. Click on Accept button to agree on licensing. 7. Note the Java folder location. Click on Next to complete installation.

19

Android Setup Tutorial


Appendix. Install Eclipse IDE
Eclipse is a multi-language software development platform comprising an IDE and a plug-in system to extend it. It can be used to develop applications in Java and, by means of the various plug-ins, in other languages (from Wikipedia)
1. Go to http://www.eclipse.org/downloads/. 2. Download the current version (Galileo at the time of writing) and save it to drive C:\. 3. Unzip the compress file to your hard drive (c:\eclipse) 4. For convenience create a Shortcut to eclipse.exe and place it on your Desktop.

20

Android Setup Tutorial


Appendix. Install Eclipse IDE
1. Launch eclipse application. 2. Create a folder to be your workspace

21

Android Setup Tutorial


Appendix. Creating an Android Project
(made for 1.5) Reference: http://developer.android.com/guide/developing/eclipse-adt.html

Hello, Android

22

Android Setup Tutorial


Creating an Android Project
To create a new project: 1. Start Eclipse 2. Select File > New > Project. 3. Select Android > Android Project, and click Next. 4. Enter Project name: HelloAndroid. 5. Select Target Android 2.1 update. 6. Application name: Hello, Android. 7. Package name: es.demo. 8. Create Activity: HolaMundo. 9. Min SDK Version: 7. 10. Click Finish.

23

Android Setup Tutorial


Creating an Android Project
Sau khi hon thnh New Project Wizard, ADT to cc th mc v file trong project mi:
src/ cha file Java cho Activity. Tt c cc file Java khc ca ng dng s y. <Android Version>/ Cha file android.jar s dng build ng dng. gen/ cha cc file Java c ADT to ra, chng hn R.java v cc interface to t cc file AIDL. assets/ Rng. Dnh lu cc file asset th. res/ cha ti nguyn cho ng dng (application resource) AndroidManifest.xml Manifest ca project. default.properties file cha cu hnh ca project, chng hn build target (phin bn Android s dng khi build ng dng).
24

Android Setup Tutorial


Creating an Android Project

25

Android Setup Tutorial


Creating an Android Project - Debugging

26

Android Setup Tutorial


Creating an Android Project
package es.demo; import android.app.Activity; import android.os.Bundle; import android.widget.Toast; public class HelloAndroid extends Activity { /** Called when the activity is first created. */ @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main); for (int i=0; i<3; i++){ Toast.makeText(getApplicationContext(), i + " Hello, Android", 1).show(); } Toast.makeText(getApplicationContext(), " Bye", 1).show(); } }

27

Android Setup Tutorial


Creating an Android Project

28

Android Setup Tutorial

Questions ?

29

Android Setup Tutorial


Summary of Android On-line Installation Resources
0. JAVA http://www.dailymotion.com/video/x77uqg_google-android-emulator-tutorial-tr_tech 1. ECLIPSE http://www.dailymotion.com/related/x77v5t_google-android-eclipse-adt-tutorial_tech/video/x77usr_google-android-eclipse-tutorial-tra_tech

2. ANDROID-SDK Android ADT Eclipse Plug-in link: https://dl-ssl.google.com/android/eclipse/ http://www.dailymotion.com/related/x77v5t_google-android-eclipse-adt-tutorial_tech/video/x77uou_google-android-sdk-emulator-tutoria_tech


3. ECLIPSE-PLUGIN http://www.dailymotion.com/related/x77usr_google-android-eclipse-tutorial-tra_tech/video/x77v5t_google-android-eclipse-adttutorial_tech?from=rss 4. HELLO WORLD TUTORIAL http://www.dailymotion.com/video/x77v6w_google-android-apps-tutorial-traini_tech 5. DROID_DRAW http://www.droiddraw.org 6. MAKING SDCARD (Video, blogs) http://www.anddev.org/emulating_a_sd-card-t263.html http://groups.google.com/group/android-developers/browse_thread/thread/9d068936b43c5f27 http://www.anddev.org/problem_pushing_files_onto_sdcard-t2467.html

7. Three GOOD videos from Google (Architecture, Interprocess Comm, APIs) 1. http://www.youtube.com/watch?v=QBGfUs9mQYY&eurl=http://developerlife.com/theblog/?p=454 2. http://www.youtube.com/watch?v=fL6gSd4ugSI&feature=related 3. http://www.youtube.com/watch?v=MPukbH6D-lY&feature=related 8. More APPs (Google President, HelloWorld, PhoneLocator) http://www.youtube.com/watch?v=1FJHYqE0RDg&feature=channel http://www.youtube.com/watch?v=I6ObTqIiYfE&feature=channel http://www.helloandroid.com/taxonomy/term/29

30

Anda mungkin juga menyukai