Android 學習筆記(三)Windows下建立Android開發環境

本章主要討論如何建立Android開發環境。

 

1.1 準備開發計算機

查看 System Requirements 網頁,以確認您開發用的計算機性能夠強!

1.2 Windows 下建立Android開發環境

1.2.1 下載必須的安裝包

爲了開發Android,必須安裝Java開發包JDK,以及Android開發環境(IDE,如Eclipse等)。當然,還有Android的SDK包。

1. JDK

進入http://java.sun.com/javase/downloads/index.jsp,根據操作系統選擇最新的JDK下載。我當時選擇的是JDK6 Update 20。

2. Eclipse

進入http://www.eclipse.org/downloads/,根據操作系統選擇最新的JDK下載。我當時選擇的是eclipse-jee-galileo-SR2-win32.zip。

3. android-sdk

進入http://androidappdocs.appspot.com/sdk/index.html,根據操作系統選擇最新的SDK下載。我當時選擇的是android-sdk_r06。

4. ADT

進入http://androidappdocs.appspot.com/sdk/eclipse-adt.html ,下載最新的ADT。我當時選擇的是ADT 0.9.7。

1.2.2 Java JDK 安裝

在下載和安裝Eclipse之前,由於Eclipse作爲一個程序是用Java寫的,它要求JRE(Java Runtime Environment)來運行,因此必須首先安裝JRE,否則打開Eclipse會出現錯誤。JRE允許運行Java基礎的應用程序,但並不允許開發者創建Java基礎的程序。爲在Android上利用Java進行應用程序的開發,需要下載安裝JDK(Java Development Kit),JDK 包含了JRE

傻瓜式安裝JDK後,必須確保JDK的bin目錄(如E:/Tech/Java/jre6/bin)包含在PATH環境變量中。

在cmd下輸入 java -version ,如果顯示如下,則表示安裝成功:

java version “1.6.0_20”

Java(TM) SE Runtime Environment (build 1.6.0_20-b02)

Java HotSpot(TM) Client VM (build 16.3-b01, mixed mode, sharing)

1.2.3 Android SDK 安裝

注意 :在安裝Androoid SDK前一定要先安裝JDK,否則SDK安裝不了。

Ø 先將sdk解壓。

必須將SDK解壓到我們的SDK安裝目錄中。因爲SDK安裝程序會從網上下載相應package下來安裝,而其安裝目錄正是解壓目錄。

Ø 安裝中會讓我們選擇要安裝的package。不熟悉的話,最好是選用默認值;

Ø 之後安裝程序自己從網上下載相應package下來安裝,不需我們干預。但費時較長,我這邊約略花了2個小時;

Ø 將SDK的tools 目錄的絕對路徑添加到系統的PATH 中;

Ø 驗證安裝是否成功:

clip_image002

1.2.4 Eclipse 安裝

Android應用程序是在Java上進行開發的。Android自身不是一個語言,是一個運行應用程序的環境。在理論上,可以使用任何發佈或者綜合開發環境(IDE)來開始自己的開發,例如使用Borland的Jbuilder進行開發或者開源NetBeans。但是,Eclipse是開放手機聯盟和谷歌認同的一個Java開發IDE,因此我們進行應用開發的一般選擇還是安裝Eclipse,以下是爲什麼選擇Eclipse的補充幾點原因:

Ø Eclipse具有開源、免費的特點,同時也是一個可用的Java開發IDE,這些特點符合開放手機聯盟真正開發移動開發市場的宗旨和要求。此外,Eclipse也較容易使用。

Ø 開放手機聯盟已經爲Eclipse發佈了一個Android的Plugin,允許開發者創建Android-定義項目,並可將編譯後的程序在Android模擬器上進行運行和調試。Android的plugin所具有的工具和能力,能縮短開發的時間。

Ø Eclipse同樣也可用於蘋果和Linux系統,對應不同的系統有對應的版本,它們之間的操作差異並不會太多。

該軟件不需安裝,只需將下載的Eclipse安裝包直接解壓到安裝路徑,點擊eclipse.exe後設置workspace就可以了。

1.2.5 Eclipse 中安裝Android 組件

Android 爲Eclipse 定製了一個插件,即Android Development Tools(ADT),目的是爲用戶提供一個強大的綜合環境用於開發Android 應用程序。ADT 擴展了Eclipse 的功能,可以讓用戶快速地建立Android 項目,創建應用程序界面,在基於Android 框架API 的基礎上添加組件,以及用SDK 工具集調試應用程序,甚至導出簽名(或未簽名)的APKs 以便發行應用程序。

Installing the ADT Plugin :ADT安裝、配置、更新與卸載指南。

1.2.5.1 安裝組件

下面介紹安裝ADT的步驟:

Ø 啓動Eclipse,選擇菜單 Help-> Install New Software後,跳出如下框圖:

clip_image004

Ø 點擊“Available Software Sites”,在下圖中填入如下信息:

Name:Android Plugin

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

這邊請注意:若獲取後續插件有問題,請將上述網址中 https 改爲 http。

clip_image006

Ø 選擇 OK 後退回前圖,在Work with 列表中選擇“Android Plugin”。稍候片刻,下圖列表中出現"Developer Tools"。選擇其下兩個插件”Android DDMS” 和 “Android Development”。並點擊 Next;

clip_image008

Ø 後續將列出兩個工具插件的特性,接受其Licence,最後,安裝後重啓Eclipse;

1.2.5.2 配置組件

配置ADT組件其實就是給Eclipse指明SDK的目錄所在。

Ø 選擇菜單項 Window > Preferences,打開Preferences面板;

Ø 在面板左側選擇“Android”,在右側中填入 SDK目錄,選擇 Apply;

Ø ok,稍後片刻右側列表中將列出在上述SDK目錄下找到的Target。

1.2.6 增加Android平臺和其他組件

在前幾節 Android SDK安裝中,選擇package的地方即爲本節要着重討論的。

安裝SDK後,可通過啓動SDK根目錄下的 SDK Setup.exe來啓動“Android SDK and AVD Manager”。下圖列出了已經裝好的package:

clip_image010

如需下載其他組件的話,請進入如下界面,其中列出了網上可獲取且未安裝的組件:

clip_image012

Android SDK 使用一種組件結構來將其內部的各個組成部分劃分成一個個可獨立安裝的“components”。這些組件有:Android platform versions, add-ons, tools, samples, and the API documentation。

一般來說,我們剛下載的SDK只包含了一個組件:最新版本的SDK工具。爲了開發Android程序,我們至少還需增加一種Android平臺到我們的開發環境中。當然,Google非常推薦下載其他可選組件。

1.2.6.1 SDK組件有哪些類型?

SDK提供瞭如下幾種類型的組件:

Ø SDK Tools

該組件預裝在下載下來的“Android SDK starter package”中,包含了開發、調試、測試我們的程序和UI所需的全部SDK工具。關於SDK Tools的更多信息可參考Dev Guide :http://androidappdocs.appspot.com/guide/developing/tools/index.html;

Ø Android platforms

An SDK platform is available for every production Android platform deployable to Android-powered devices. Each platform component includes a fully compliant Android library and system image, sample code, emulator skins, and any version specific tools. For detailed information about each platform, see the overview documents available under the section "Downloadable SDK Components," at left.

Ø SDK Add-Ons

SDK add-ons provide a development environment for specific Android external library or a customized (but fully compliant) Android system image. The Android SDK repository offers the Google APIs Add-On, which gives your application access to powerful mapping capabilities through the com.google.android.maps library. You can also add additional repositories, so that you can download other SDK add-ons, where available.

Ø USB Driver for Windows

Contains driver files that you can install on your Windows computer, so that you can run and debug your applications on an actual device. You do not need the USB driver unless you plan to debug your application on an actual Android-powered device. If you develop on Mac OS X or Linux, you do not need a special driver to debug your application on an Android-powered device.

Ø Samples

Contains the sample code and apps available for each Android development platform. If you are just getting started with Android development, make sure to download the samples to your SDK.

Ø Documentation

Contains a local copy of the latest multiversion documentation for the Android framework API.

1.2.6.2 哪些組件是我們需要的?

根據我們開發的需要,可以分爲幾種開發環境,其相應所需的組件見下表:

Environment

SDK Component

Comments

Basic

SDK Tools

If you've installed the SDK starter package, then you already have this component preinstalled. The SDK Tools component is required — you can't develop or build an application without it.

SDK platform

You need to download at least one platform into your environment, so that you will be able to compile your application and set up an Android Virtual Device (AVD) to run it on (in the emulator). To start with, just download the latest version of the platform. Later, if you plan to publish your application, you will want to download other platforms as well, so that you can test your application on the full range of Android platform versions that your customers are using.

Recommended

Documentation

The Documentation component is useful because it lets you work offline and also look up API reference information from inside Eclipse.

Samples

The Samples components give you source code that you can use to learn about Android, load as a project and run, or reuse in your own app. Note that multiple samples components are available — one for each Android platform version. When you are choosing a samples component to download, select the one whose API Level matches the API Level of the Android platform that you plan to use.

Usb Driver

The Usb Driver component is needed only if you are developing on Windows and have an Android-powered device on which you want to install your application for debugging and testing. For Mac OS X and Linux platforms, no special driver is needed.

Full

Google APIs

The Google APIs add-on gives your application access to the Maps external library, which makes it easy to display and manipulate Maps data in your application.

Additional SDK Platforms

If you plan to publish your application, you will want to download additional platforms corresponding to the Android platform versions on which you want the application to run. The recommended approach is to compile your application against the lowest version you want to support, but test it against higher versions that you intend the application to run on. You can test your applications on different platforms by running in an Android Virtual Device (AVD) on the Android emulator.

1.2.6.3 如何增加Android組件

關於這部分建議請參考:http://androidappdocs.appspot.com/sdk/adding-components.html

至此,Windows下的Android開發環境安裝完成。後續我們將在“Hello World”一節中以一個項目來驗證環境的可行性。

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章