---
title: "Android SDK 2.2 开发环境搭建"
author: "panxq0809"
date: "2010-08-25T17:46:19Z"
tags: ["Android", "Eclipse", "Google", "Linux", "配置管理"]
categories: ["移动开发"]
slug: "android-sdk-2-2"
draft: false
lastmod: "2010-08-26T16:55:35Z"
id: 747108
url: "https://panxq0809.iteye.com/blog/747108"
---

本文介绍 Android SDK 2.2开发环境搭建过程，

包括：Android SDK 2.2, Eclipse 3.5.2(galileo), 和 Andoid Development Tools (ADT) plugin。

 

前提：已经安装了 JDK5.0 或 JDK 6.0。并且在系统环境变量设置了 Path 包含 JDK 的 bin 目录。

内容参考：http://developer.android.com/sdk/installing.html 或 http://androidappdocs.appspot.com/sdk/installing.html

 

\[安装 Android SDK 2.2]

1\. 下载Android SDK 2.2 

For windows 版 [android-sdk\_r06-windows.zip](http://dl.google.com/android/android-sdk_r06-windows.zip)   (http://dl.google.com/android/android-sdk\_r06-windows.zip)  
For Mac 版 [android-sdk\_r06-mac\_86.zip](http://dl.google.com/android/android-sdk_r06-mac_86.zip)   (http://dl.google.com/android/android-sdk\_r06-mac\_86.zip)  
For Linux 版 [android-sdk\_r06-linux\_86.tgz](http://dl.google.com/android/android-sdk_r06-linux_86.tgz)   (http://dl.google.com/android/android-sdk\_r06-linux\_86.tgz)

 这个 zip 包并不是一个完整的软件包。Android 软件包采用“组件”的形式，用户可以根据需要选取组件。上述zip文件只包含了一个组件管理工具和一个基本的工具组件。

2.设置环境变量

解压缩上面的 zip 包，然后

      On Linux, edit your `~/.bash_profile` or `~/.bashrc` file. Look for a line that sets the PATH environment variable and add the full path to the `tools/` directory to it. If you don't see a line setting the path, you can add one:export PATH=${PATH}:*&lt;your\_sdk\_dir&gt;* /tools

      On a Mac OS X, look in your home directory for `.bash_profile` and proceed as for Linux. You can create the `.bash_profile` if you haven't already set one up on your machine.

      On Windows, right-click on My Computer, and select Properties. Under the Advanced tab, hit the Environment Variables button, and in the dialog that comes up, double-click on Path (under System Variables). Add the full path to the `tools/` directory to the path.

3\. 运行 Android SDK and AVD Manager

可以运行 SDK Setup.exe， 即启动了Andoid SDK and AVD Manager。这个工具不但对Android SDK 组件进行管理，同时也是 Android 虚拟设备管理器。(关于后者，参见后面示例)。

　　然后，可以用这个工具下载完整的 Android SDK 开发包。需要注意的如果网络使用了代理服务器，则(有可能)需在这个工具里配置代理服务器域名和端口。

 

\[安装 Eclipse]

地址：[http://www.eclipse.org/downloads/](http://www.eclipse.org/downloads/) 下载Eclipse 3.5.2 ，同样，只需解压缩即可。

 

\[安装 ADT]

ADT 版本：

ADT 0.9.7 (May 2010)

ADT 0.9.6 (March 2010)

ADT 0.9.5 (December 2009)

ADT 0.9.4 (October 2009)

使用 Eclipse 的升级管理器来安装ADT：

1\. 启动 Eclipse, 然后进入 Help &gt; Install New Software.

2\. 在 Available Software 对话框里，点击 Add....

3\. 出现 Add Site 对话框，在 Name 域里面输入一个名字 (例如, "Android Plugin") ，

在 "Location" 域里面输入 URL: http://dl-ssl.google.com/android/eclipse/

4\. 注意：如果有问题，可以把 https 换成 http 试一下。点击 OK.

5\. 回到 Available Software 界面，你应该看到 "Developer Tools" 。选取 checkbox 。点击 Next, 接受 license agreement， 然后点击 Finish。

6\. 重起 Eclipse.

 

\[配置 ADT]

配置 Eclipse 里的 ADT,使其指向 Android SDK 。

1\. 选取 Eclipse Window &gt; Preferences...

2\. 选择 Android

3\. 点击 Browse... 定位 Android SDK 目录。

4\. 点击 Apply, 然后 OK.

 

\[创建虚拟设备]

开发环境建立好了，就可以写一个“Hello World”应用。但在之前，还需创建一个虚拟设备。

运行 Eclipse, 选取 Window &gt; Android SDK and AVD Manager.

在左侧面板选择 Virtual Devices

点击 New.

出现 Create New AVD 对话框

输入 AVD 名字, 例如 "android\_avd".

选取一个目标。目标是一个平台 (即，Android SDK 的版本，如 2.2)

暂时忽略其他设置

点击 Create AVD.

 

\[Hello World]

1). 创建一个新的 Android project

在创建 AVD 之后, 下个步骤就是在 Eclipse 里开始一个新的 Android 项目。

运行 Eclipse, 选取 File &gt; New &gt; Project.

如果 ADT 插件正确安装了，应该在 "Android Project" 里面有一项："Android" 。(在你创建了一个或多个Android 项目后，一个 "Android XML File" 入口也应该可见。)

选择 "Android Project" 并点击 Next.

填写项目信息如下：

Project name: HelloAndroid

Application name: Hello, Android

Package name: com.example.helloandroid (or your own private namespace)

Create Activity: HelloAndroid

点击 Finish.

2). 编写代码：打印 Hello Android

package com.android.helloandroid;

import android.app.Activity;

import android.os.Bundle;

import android.widget.TextView;

public class HelloAndroid extends Activity {

@Override

public void onCreate(Bundle savedInstanceState) {

super.onCreate(savedInstanceState);

TextView tv = new TextView(this);

tv.setText("Hello, Android");

setContentView(tv);

}

}

3)运行

ADT 使运行非常简单:

选取 Run &gt; Run.

选取 "Android Application".

 

 

附：Android SDK release number:

　　Android SDK 2.2 Revision 1 (May 2010) API Level: 8 Requires SDK Tools r6 or higher. FroYo

　　Android SDK 2.1 Revision 2 (May 2010) API Level: 7 Requires SDK Tools r6 or higher. Eclair

　　Android SDK 2.1 Revision 1 (Jan 2010) API Level: 7 Requires SDK Tools r6 or higher. Eclair

　　Android SDK 2.0.1 API Level: 6 Requires SDK Tools r6 or higher. Eclair

　　Android SDK 2.0 API Level: 5 Requires SDK Tools r6 or higher. Eclair

　　Android SDK 1.6 Revision 3 (May 2010) API Level: 4 Requires SDK Tools r6 or higher. Donut

　　Android SDK 1.6 Revision 2 (Dec 2009) API Level: 4 Requires SDK Tools r6 or higher. Donut

　　Android SDK 1.6 Revision 1 (Sep 2009) API Level: 4 Requires SDK Tools r6 or higher. Donut

　　Android SDK 1.5 Revision 3 (Jul 2009) API Level: 3 Requires SDK Tools r6 or higher. Cupcake

　　Android SDK 1.5 Revision 2 (May 2009) API Level: 3 Requires SDK Tools r6 or higher. Cupcake

　　Android SDK 1.5 Revision 1 (Api 2009) API Level: 3 Requires SDK Tools r6 or higher. Cupcake

　　Android SDK 1.1 API Level: 2

　　Android SDK 1.0 API Level: 1