Top Banner
CS241001 Android Lab 2009.11.24
22
Welcome message from author
This document is posted to help you gain knowledge. Please leave a comment to let me know what you think about it! Share it to your friends and learn new things together.
Transcript
Page 1: Set up Android Development Environment

CS241001 Android Lab2009.11.24

Page 2: Set up Android Development Environment

Websitehttp://developer.android.com/intl/zh-TW/

index.htmlAndroid API

http://developer.android.com/intl/zh-TW/reference/packages.html

Page 3: Set up Android Development Environment

Supported Operating SystemsWindows XP (32-bit) or Vista (32- or 64-bit)Mac OS X 10.4.8 or later (x86 only)Linux (tested on Linux Ubuntu Dapper

Drake)To get started, you’ll need to download

and install the following Eclipse IDE Eclipse 3.4 (Ganymede), 3.5(Galileo)

Recommended Eclipse IDE packages: Eclipse IDE for Java EE Developers, Eclipse IDE for Java Developers, Eclipse for RCP/Plug-in Developers

Eclipse JDT plugin (included in most Eclipse IDE packages)

JDK 5 or JDK 6 (JRE alone is not sufficient)Android Development Tools plugin (optional)

Page 4: Set up Android Development Environment

1. Download the latest JDK from Sun at http://java.sun.com/javase/downloads/index.jsp

2. After installing JDK , remember to modify environment parameters “Path”

C:\Programming Files\Java\jdk1.6.0_16\bin C:\Programming Files\Java\jre6\bin

Page 5: Set up Android Development Environment
Page 6: Set up Android Development Environment

1. Download Eclipse at http://www.eclipse.org/downloads/

Eclipse 3.4 (Ganymede), 3.5(Galileo) 2. Uncompress the download file

Page 7: Set up Android Development Environment

1. Open Ecilpse2. Select Help Software Updates…Available

Software3. In the resulting dialog box, choose “Add Site” 4. Enter the location

https://dl-ssl.google.com/android/eclipse/

5. Back in the Available Software view, you should see the plugin listed by the URL, with "Developer Tools" nested within it. Select the checkbox next to Developer Tools and click Install...

6. On the subsequent Install window, "Android DDMS" and "Android Development Tools" should both be checked. Click Next.

7. Read and accept the license agreement, then click Finish.

8. Restart Eclipse.

Page 8: Set up Android Development Environment

• Download SDK from http://code.google.com/p/androidbmi/wiki/InstallAndroid and uncompress

• Now modify your Eclipse preferences to point to the Android SDK directory:1. Select Window → Preferences... to open the

Preferences panel2. Select Android from the left panel. 3. For the SDK Location in the main panel, click

Browse... and locate your downloaded SDK directory.

4. Click Apply, then OK.

Page 9: Set up Android Development Environment

1. select Window Android SDK and AVD Manager

2. Select Available Packages in the left panel. This will reveal all components currently available for download.

3. Select the components you'd like to install and click Install Selected .

4. Verify and accept the components you want and click Install Accepted.

Page 10: Set up Android Development Environment
Page 11: Set up Android Development Environment
Page 12: Set up Android Development Environment

Create an AVDCreate a New Android ProjectCreating a Launch ConfigurationRunning and Debugging Your Android

Applications

Page 13: Set up Android Development Environment

1. Create a virtual device

2. select Window Android SDK and AVD ManagerVirtual DeviceNew

Virtual Device name

Select target

Select skin

Create Finish

Page 14: Set up Android Development Environment

1. From Eclipse, select File > New > Project.

2. Select "Android Project" and click Next.

Page 15: Set up Android Development Environment

3. Fill in the project details with the following values: Project name: HelloAndroid

4. Build Target : Android 1.55. Application name: Hello, Android6. Package name:

tw.nthu.cs241001.helloandroid7. Create Activity: HelloAndroid8. Min SDK Version: 59. Click Finish

Page 16: Set up Android Development Environment

3

5

4

6

7

8

9

Page 17: Set up Android Development Environment

1. Select Run → Run Configurations …. .

2. Right-click Android Application on the project type list, and select New.

Page 18: Set up Android Development Environment

1. Select Run As… Android Application

Page 19: Set up Android Development Environment

• src : This folder holds all the source code files for your application, inside the appropriate package subfolders.

• gen : This file holds all the automatic generation files

• res : This folder holds all the resources for your application.

• AndroidMainifest.xml : list the application provide functions

Page 20: Set up Android Development Environment

package com.example.helloandroid;

import android.app.Activity;import android.os.Bundle;

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); }}

Page 21: Set up Android Development Environment

package com.example.helloandroid;

import android.app.Activity;import android.os.Bundle;import android.widget.TextView;

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);

TextView tv = new TextView(this); tv.setText( “Test TextView” ); setContentView(tv);

}}

Page 22: Set up Android Development Environment

New String res values strings.xml Click Add… String OKFill up Name and Value Save

Add to main.xmlres layout main.xmlSelect Text fieldProperties

Property : Text Value Select the new string