Set up Android Development Environment

Post on 17-May-2015

1.188 views 8 download

Tags:

Transcript of Set up Android Development Environment

CS241001 Android Lab2009.11.24

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

index.htmlAndroid API

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

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)

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

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

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

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.

• 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.

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.

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

Applications

1. Create a virtual device

2. select Window Android SDK and AVD ManagerVirtual DeviceNew

Virtual Device name

Select target

Select skin

Create Finish

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

2. Select "Android Project" and click Next.

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

3

5

4

6

7

8

9

1. Select Run → Run Configurations …. .

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

1. Select Run As… Android Application

• 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

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

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

}}

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