最近要学习Android,首先第一件事就是搭建 Android 的开发环境,几经周折终于搞定,其中参考了很多好的博文和其他资料,写下来为了感谢博友,也为了分享经验,共同进步。
具体步骤如下(接上篇日志):
5. 安装 Eclipse 的 Android ADT 插件
1) 可以直接到 Android 官网去下载这个 ADT 插件。
笔者是到 http://androidappdocs.appspot.com/sdk/eclipse-adt.html#installing 这里下载了 ADT-0.9.9.zip ,
此处参考英文,其实都是很简单的英文,不浪费时间
1. Start Eclipse, then select Help > Install New Software .
2. In the Available Software dialog, click Add... .
3. In the Add Site dialog that appears, enter a name for the remote site (for example, "Android Plugin") in the "Name" field.
In the "Location" field, enter this URL:
https : //dl-ssl.google.com/android/eclipse/
Note: If you have trouble acquiring the plugin, you can try using "http" in the URL, instead of "https" (https is preferred for security reasons).
Click OK .
4. Back in the Available Software view, you should now see "Developer Tools" added to the list. Select the checkbox next to Developer Tools, which will automatically select the nested tools Android DDMS and Android Development Tools. Click Next .
5. In the resulting Install Details dialog, the Android DDMS and Android Development Tools features are listed. Click Next to read and accept the license agreement and install any dependencies, then click Finish .
6. Restart Eclipse.
Configuring the ADT Plugin
Once you've successfully downloaded ADT as described above, the next step is to modify your ADT preferences in Eclipse to point to the Android SDK directory:
1. Select Window > Preferences... to open the Preferences panel (Mac OS X: Eclipse > Preferences ).
2. 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 .
Done! If you haven't encountered any problems, then the installation is complete. Now read Adding Platforms and Other Components for instructions on how to complete the setup of your SDK environment.
Troubleshooting ADT Installation
If you are having trouble downloading the ADT plugin after following the steps above, here are some suggestions:
· If Eclipse can not find the remote update site containing the ADT plugin, try changing the remote site URL to use http, rather than https. That is, set the Location for the remote site to:
http : //dl-ssl.google.com/android/eclipse/
· If you are behind a firewall (such as a corporate firewall), make sure that you have properly configured your proxy settings in Eclipse. In Eclipse 3.3/3.4, you can configure proxy information from the main Eclipse menu in Window (on Mac OS X, Eclipse ) > Preferences > General > Network Connections .
If you are still unable to use Eclipse to download the ADT plugin as a remote update site, you can download the ADT zip file to your local machine and manually install it:
1. Download the current ADT Plugin zip file from the table below (do not unpack it).
Name | Package | Size | MD5 Checksum |
ADT 0.9.9 | ADT-0.9.9.zip | 8301681 bytes | 7deff0c9b25940a74cea7a0815a3bc36 |
2. Follow steps 1 and 2 in the default install instructions (above).
3. In the Add Site dialog, click Archive .
4. Browse and select the downloaded zip file.
5. In Eclipse 3.5 only, enter a name for the local update site (e.g., "Android Plugin") in the "Name" field.
6. Click OK .
7. Follow the remaining procedures as listed for default installation above, starting from step 4.
To update your plugin once you've installed using the zip file, you will have to follow these steps again instead of the default update instructions.
Other install errors
Note that there are features of ADT that require some optional Eclipse components (for example, WST). If you encounter an error when installing ADT, your Eclipse installion might not include these components. For information about how to quickly add the necessary components to your Eclipse installation, see the troubleshooting topic ADT Installation Error: "requires plug-in org.eclipse.wst.sse.ui" .
6. 配置 Eclipse 和 Android ADT 插件
1) 设置 Eclipse 的 Java JDK 属性设置
选择【 Window 】 > 【 Preferences… 】打开编辑属性窗口;选择 Java 属性面板;选择 Java 编译器为 6.0 ;点击 Apply ,和 OK 。
2) 进行 Android SDK 设置
选择【 Windows 】 > 【 Preferences… 】打开编辑属性窗口;选择 Android 属性面板;加入 Android SDK 的目录(点击【 Browse… 】进行选择,这里是 "D:/android-sdk-windows/" 目录)。
7. 测试开发环境
搭建好开发环境之后,我们来创建一个 Hello World 工程,体验一下 Android 的开发。
1) 选择【 File 】 > 【 New 】 > 【 Project 】
2) 选择【 Android 】 > 【 Android Project 】,点击【 Next 】
3) 对新工程进行设置,点击 Finish
4) 将文件 HelloAndroid.java 中的代码修改为 :
package com.example.hello;
public class HelloAndroid extends Activity
{
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState)
{
super .onCreate(savedInstanceState);
TextView tv = new TextView(this);
tv.setText("Hello, Android");
setContentView(tv);
}
}
import android.app.Activity;
import android.os.Bundle;
import android.widget.TextView;
运行程序,第一次启动 AVD ,时间有点长,运行效果为 :
参考博客及其他资料:
http://blog.csdn.net/Mac_cm/archive/2009/01/06/3720492.aspx
(如何在Windows下搭建Android开发环境)
http://blog.163.com/liu_yang1234/blog/static/24474310201081734627645/
(详解)Eclipse3.6搭建 Android 2.2 开发环境
http://ethan163.javaeye.com/blog/792209
http://androidappdocs.appspot.com/sdk/installing.html