2013IT鐵人賽-07-Android01-Android開發環境安裝與測試
此次使用的是 gasloin 的Android 手機應用程式設計入門第5版來進行 Android 的學習, 目前作者已經將範例原始碼放到 GitHub 上面 https://github.com/gasolin/androidbmi5th .
所以我們首先就是要練習用 git 將範例原始碼下載.
使用 git clone 下載範例
Cloning into 'androidbmi5th'...
remote: Counting objects: 537, done.
remote: Compressing objects: 100% (318/318), done.
remote: Total 537 (delta 231), reused 294 (delta 49)
Receiving objects: 100% (537/537), 732.12 KiB | 226 KiB/s, done.
Resolving deltas: 100% (231/231), done.
- 這樣會下載 Master 底下的所有檔案, 目錄名稱為 androidbmi5th
使用 git 下載各章節的範例
# git clone https://github.com/gasolin/androidbmi5th.git -b CH09
- 這邊的 -b 為指定分支 branch, CH09 是分支名稱
- 但是下載的目錄還是 androidbmi5th, 所以如果在同一個目錄下已經存在 androidbmi5th 目錄, 不可以使用者這樣的方式 clone.
- 錯誤訊息為 fatal: destination path 'androidbmi5th' already exists and is not an empty directory.
另外一種方式為直接下載各章節範例的 .zip 檔案
#wget https://github.com/gasolin/androidbmi5th/archive/CH09.zip
- 解壓縮之後的目錄名稱為 androidbmi5th-CH09
接下來準備 Android 開發環境
必要開發工具
- JDK(Java Development Kit)
- 目前是 JDK 6 或是 JDK 7
- ADT Bundle
- Android 4.1 以後提供整合套件, 包含 Eclipse
開始進行安裝開發工具吧
首先安裝 JDK, 先查詢是否有安裝相關套件
# zypper search jdk
Loading repository data...
Warning: Repository 'openSUSE-12.2-Update-Non-Oss' appears to outdated. Consider using a different mirror or server.
Reading installed packages...
S | Name | Summary | Type
--+----------------------------+------------------------+-----------
i | java-1_7_0-openjdk | Java runtime environ-> | package
| java-1_7_0-openjdk | Java runtime environ-> | srcpackage
| java-1_7_0-openjdk-demo | Sources for building-> | package
| java-1_7_0-openjdk-devel | Java SDK based on Op-> | package
| java-1_7_0-openjdk-javadoc | Documentation of the-> | package
| java-1_7_0-openjdk-src | OpenJDK 7 Java class-> | package
| ldapjdk | The Mozilla LDAP Jav-> | package
| ldapjdk-javadoc | Javadoc for ldapjdk | package
目前只有安裝 JRE (Java Runtime Environment), 但是沒有安裝 Java 開發環境(SDK).
安裝相關套件
# zypper install java-1_7_0-openjdk-devel
Loading repository data...
Warning: Repository 'openSUSE-12.2-Update-Non-Oss' appears to outdated. Consider using a different mirror or server.
Reading installed packages...
Resolving package dependencies...
The following NEW package is going to be installed:
java-1_7_0-openjdk-devel
The following packages are going to be upgraded:
java-1_7_0-openjdk lcms2
2 packages to upgrade, 1 new.
Overall download size: 57.6 MiB. After the operation, additional
45.4 MiB will be used.
Continue? [y/n/?] (y): y(輸入 y 安裝)
順便安裝一下 javacc 套件
# zypper search javacc
Loading repository data...
Warning: Repository 'openSUSE-12.2-Update-Non-Oss' appears to outdated. Consider using a different mirror or server.
Reading installed packages...
S | Name | Summary | Type
--+-----------------+-----------------------------------------+--------
| javacc | A Parser and Scanner Generator for Java | package
# zypper install javacc
Loading repository data...
Warning: Repository 'openSUSE-12.2-Update-Non-Oss' appears to outdated. Consider using a different mirror or server.
Reading installed packages...
Resolving package dependencies...
The following NEW package is going to be installed:
javacc
1 new package to install.
Overall download size: 251.3 KiB. After the operation, additional 273.0 KiB
will be used.
Continue? [y/n/?] (y): y(輸入 y 安裝)
接下來安裝 ADT 套件
下載 ADT Bundle 套件(套件會隨著Android 發行的版本有變化, 目前下載的是 20130729的版本)
# wget http://dl.google.com/android/adt/adt-bundle-linux-x86_64-20130729.zip
觀察目錄下的物件
# ls
Desktop Music README.md adt-bundle-linux-x86_64-20130729.zip inst-sys
Documents Pictures Templates androidbmi5th ruby
Downloads Public Videos bin
解壓縮檔案
# unzip adt-bundle-linux-x86_64-20130729.zip
觀察目錄下的物件 (會出現一個同名的目錄)
# ls
Desktop Music README.md adt-bundle-linux-x86_64-20130729 bin
Documents Pictures Templates adt-bundle-linux-x86_64-20130729.zip inst-sys
Downloads Public Videos androidbmi5th
接下來執行 adt-bundle-linux-x86_64-20130729/eclipse 目錄下的 eclipse
# ./adt-bundle-linux-x86_64-20130729/eclipse/eclipse
執行之後首先會詢問 Workspace 的目錄要設定在哪個目錄?
這邊如果沒有特別的想法, 就可以依照預設值, 或是可以儲存在有同步的目錄, 例如 Dropbox 的目錄下.
點選 OK 啟動 Eclipse
此時會出現 Eclipse 的開發環境
使用 Android SDK Manager 安裝組件
點選選單上的 Window → Android SDK Manager
在這邊我們選取 Android 4.3 ( API 18)內的 Sample for SDK 來安裝
請勾選套件再點選 Install packages
點選Accept License 再點選 Install 來安裝
有了 SDK 的API 參考範例
接下來就可以使用 Eclipse 來進行 Android 的開發了.
Fun with Day 7 ~
沒有留言:
張貼留言