2011年12月29日 星期四

如何設定android開發環境

這裡來介紹一下如何設定android的開發環境。
我們分為幾個階段:
1. linux基本環境設定
2. android apk 開發環境設定
3. android os 開發環境設定

首先,linux環境設定:

1. 安裝 ubuntu version 10.04 LTS 64bit (以下是以ubuntu來舉例說明)
1.1. 設定 eth0.
1.2. 設定 samba service. (這個是為了方便與windows共享檔案用)
參考資料: http://ithelp.ithome.com.tw/question/10027945
1.3. 最好執行 system / administration / update manager 將系統更新到最新.
2. 安裝瀏覽器 google chrome. (也可以用內建的firefox)
下載位置: https://www.google.com/chrome?hl=zh-TW
3. 安裝 ssh (方便用其他電腦連線進去作業)
參考資料: http://twntwn.info/blog/ajer001/archives/2822
安裝指令: sudo apt-get install ssh
4. 安裝中文輸入法 gcin.
參考資料: http://cle.linux.org.tw/trac/wiki/GcinInstallUbuntu


接下來,安裝 android apk 開發環境:

參考資料: http://developer.android.com/sdk/requirements.html

1. 安裝 jdk 6 (non-rpm version for ubuntu)
參考資料: http://source.android.com/source/initializing.html
安裝指令: sudo add-apt-repository "deb http://archive.canonical.com/ lucid partner"
安裝指令: sudo apt-get update
安裝指令: sudo apt-get install sun-java6-jdk
2. 安裝 eclipse
下載位置: http://www.eclipse.org/downloads/
3. 安裝 android sdk
參考資料: http://developer.android.com/sdk/installing.html
4. 安裝 android adt from eclipse.
參考資料: http://developer.android.com/sdk/eclipse-adt.html
5. 安裝相關 android sdk 元件.
5.1. 設定 android sdk folder for eclipse.
5.2. 啟動 android sdk manager and download necessary components.
6. 安裝 android ndk (非必要步驟)
參考資料: http://developer.android.com/sdk/ndk/index.html


最後,安裝 android os 開發環境

1. 安裝必要元件.
參考資料: http://source.android.com/source/initializing.html    (key word: "Installing required packages")
安裝指令: sudo apt-get install git-core gnupg flex bison gperf build-essential zip curl zlib1g-dev libc6-dev lib32ncurses5-dev ia32-libs x11proto-core-dev libx11-dev lib32readline5-dev lib32z-dev libgl1-mesa-dev g++-multilib mingw32 tofrodos python-markdown libxml2-utils xsltproc
安裝指令: sudo ln -s /usr/lib32/mesa/libGL.so.1 /usr/lib32/mesa/libGL.so
安裝指令: sudo apt-get install sharutils    //for uudecode

2. 設定 USB Access 權限
參考資料: http://source.android.com/source/initializing.html (key word: "Configuring USB Access")
安裝指令: sudo vim /etc/udev/rules.d/51-android.rules
add following lines:
----------------------------------------------------------
SUBSYSTEM=="usb", SYSFS{idVendor}=="vendor id here", MODE="0666"
SUBSYSTEM=="usb", SYSFS{idVendor}=="vendor id here", OWNER="user name here" GROUP="group name here"
----------------------------------------------------------
!!NOTE: This is known to work on both Ubuntu Hardy Heron (8.04.x LTS) and Lucid Lynx (10.04.x LTS).

3. 設定 ccache (加快 build image 速度)
參考資料: http://source.android.com/source/initializing.html (key word: "Setting up ccache")
安裝指令: mkdir ~/data/ccache
安裝指令: vim ~/.bashrc
add following lines at end of file:
----------------------------------------------------------
export USE_CCACHE=1
export CCACHE_DIR=~/data/ccache
----------------------------------------------------------

4. 設定開啟檔案最大值
安裝指令: sudo vim /etc/security/limits.conf
add following lines at end of file:
----------------------------------------------------------
user_name_here      -       nofile          4096
root             -       nofile          4096
----------------------------------------------------------




其他實用的設定
1. format history command:
安裝指令: vim ~/.bashrc
add following line at end of file:
----------------------------------------------------------
export HISTTIMEFORMAT="%F %T "
----------------------------------------------------------

2. format vim editor
安裝指令: vim ~/.vimrc
add following lines
----------------------------------------------------------
set hlsearch            "高亮度反白
set backspace=2         "可隨時用倒退鍵刪除
set autoindent          "自動縮排
set ruler               "可顯示最後一行的狀態
set showmode            "左下角那一行的狀態
set nu                  "可以在每一行的最前面顯示行號啦!
set bg=dark             "顯示不同的底色色調
syntax on               "進行語法檢驗,顏色顯示。
----------------------------------------------------------