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

來源:互聯網
上載者:User

本章主要討論如何建立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 中;

Ø 驗證安裝是否成功:

1.2.4 Eclipse
安裝

Android應用程式是在Java上進行開發的。Android自身不是一個語言,是一個運行應用程式的環境。在理論上,可以使用任何發布或者綜合開發環境(IDE)來開始自己的開發,例如使用Borland的Jbuilder進行開發或者開源NetBeans。但是,Eclipse是開放手機聯盟和Google認同的一個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後,跳出如下框圖:

Ø 點擊“Available Software Sites”,在中填入如下資訊:

Name:Android Plugin

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

這邊請注意:若擷取後續外掛程式有問題,請將上述網址中 https 改為 http。

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

Ø 後續將列出兩個工具外掛程式的特性,接受其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:

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

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”一節中以一個項目來驗證環境的可行性。

相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.