2012年4月23日 星期一

ANDROID_SWT問題


在Linux環境下執行ddms時有時候會出現
SWT folder '/XXXX/android/out/host/linux-x86/framework/x86' does not exist.
Please export ANDROID_SWT to point to the folder containing swt.jar for your platform.
這是因為swt.jar找不到。

很簡單的方法可以解決:
先用 locate swt.jar 找到哪裡有swt.jar.
然後直接 export ANDROID_SWT={找到的路徑}
就可以正常使用了。

2012年1月11日 星期三

file compare tool in lunix

今天跟大家介紹在ubuntu下如何做檔案比對。
在windows下我們很容易找到一些如windiff, winmerge等等之類的軟體,同樣在ubuntu環境下也有一些軟體工具可以做同樣的事。

1. KDiff3
home: http://kdiff3.sourceforge.net/
command: sudo apt-get install kdiff3
優點:○目錄比對
缺點:×即時編輯

2. Diffuse
home: http://diffuse.sourceforge.net/
command: sudo apt-get install kdiff3
優點:○即時編輯
缺點:×目錄比對

3. Kompare
home: http://www.caffeinated.me.uk/kompare/
command: sudo apt-get install kdiff3
優點:○目錄比對
缺點:×即時編輯

~~~附加一提~~~
自己試了一下上面提到的軟體都沒有提供:滑鼠右鍵選取兩個檔案,直接進入比對視窗。
但是透過修改設定就可以達到功能要求。
1. change context menu for diffuse
sudo vim /usr/share/applications/diffuse.desktop
=====修改以下內容=====
Exec=diffuse %F %F
====================

2. change context menu for kdiff3
sudo vim ~/.local/share/applications/userapp-kdiff3-DHDL7V.desktop
=====修改以下內容=====
Exec='/usr/bin/kdiff3' %f %f
====================

3. change context menu for kompare
sudo vim /usr/share/applications/kde4/kompare.desktop
=====修改以下內容=====
# Exec=kompare -caption "%c" -o %U
Exec=kompare %f %f
====================


當然,如果你不想安裝任何軟體,也是有一些網站提供基本的檔案比對服務。
1. comparemyfile
home:http://www.comparemyfiles.com/

最後,也提供一個最新的參考連結。
http://en.wikipedia.org/wiki/Comparison_of_file_comparison_tools


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               "進行語法檢驗,顏色顯示。
----------------------------------------------------------

2011年11月18日 星期五

android CTS 介紹---cts plan 包含哪些東西

1. CTS從大到小包含了
Plan > package > suite > case > method


Plan:
User can create plan in cts shell. Plan should include packages, suites, cases or methods. Picture below shows the “add plan” command.

  • Cts test plan comes from [android source tree]/out/host/linux-x86/repository/plans/[xml file];
  • User can also create cts plan by adding xml file manually, without cts shell. This means when user types command “ls --plan”, cts shell search xml immediately.
  • Cts shell will check contents in plan when processing user command, following picture shows the error message for the item.
Package:
  • Package comes from [android source tree]/out/host/linux-x86/repository/plans/*.xml
  • Each package should responds to one xml and one apk file in [android source tree]/out/host/linux-x86/repository/testcase/. (but some package don’t.)
Suite:
  • Following picture shows the xml structure. It show the relationship between suite, TestCase(Case) and Test(Method).
  • And picture below shows the source code for corresponded class method.
  • We can find Suite in each xml file in [android source tree]/out/host/linux-x86/repository/testcase/*.xml.

Case:
  • It corresponds to class name in java file.
  • Test case is recorded in xml as suite child node. We can find them in source code as a class name.

Method:
  • Method is recorded in xml as TestCase child node. We can find them in source code as a class method.


android CTS 介紹---運作方式

需要設備.

  • Host side: PC with linux OS or windows OS.
  • Client side: tablet.

運作流程.

  • When cts start on host pc. Host pc will install test apk to tablet via adb.
  • After installing, tablet will start apk to test. And send result to host pc.
  • Host pc send adb command to remove apk on tablet.
  • Host pc gathers result information and generates xml report.

2011年10月31日 星期一

今早看到一則新聞:
懂得閃避的文字 -- 用 Kinect 便能解決 Keynote 之「遮蔽問題」

大意是說,日本明治大學利用 Kinect 來解決投影片會投到人身上的問題。其動機是非常好的,不過,就現實生活來講,演講者可以粗略地分成兩種:第一種是只站在演講桌後方,動也不動,這樣的人應該用不到這套技術。第二種人可能像Jobs Steve一樣在投影機前面亂亂跑,這樣的人可能需要這樣的技術。

所以我們就第二種人來討論,當演講者在投影機前面亂亂跑的時候,投影片上的文字圖案應該也會亂亂跑,我想如果我是聽演講的人,應該很不舒服吧。而且可能會模糊焦點。
如果,就這樣的狀況來探討的話,是否可以對這樣的技術再做一些加強,比如說:

1. 投影片上的文字、圖案都不需要自動調整,只要不打光在演講者身上就可以了。
2. 前面的作法是不打光在演講者身上,這樣的效果很容易造成演講者光線偏暗。或許我們可以利用Kinect捕捉人影的技術,動態在演講者身上投射微光。讓整場演講的效果更專注在演講者身上。

也許這樣的投影機會更受消費者歡迎。這樣的技術不難,也許再過一陣子就會有廠商開發出來了喔!

2011年10月3日 星期一

如何建立android unit test專案

前置作業:
1. 先建立要被測試的專案,假設要被測試的專案是com.myCompany.myHello.要被測試的class是MyHelloActivity.


2. 開始建立unit test project

步驟:
1. 在Eclipse 裡開新專案, new > project > Android > Android test Project.


2. 設定值如下說明
2.1. 假設test專案名稱為myTestProject.
2.2. 被測試專案為myHello.


3. 完成之後,會在eclipse的package explorer出現一個test專案,如下:


4. 接著新增加一個test case class,如下圖。
為什麼要用ActivityInstrumentationTestCase2,原文解釋:Android offers several, but the one that tests in the most realistic environment is ActivityInstrumentationTestCase2, so you will use it as the base class. Like all activity test case classes, ActivityInstrumentationTestCase2 offers convenience methods for interacting directly with the UI of the application under test.


5. 完成之後eclipse自動generate出一個myTestClass.java檔,請加入
import com.myCompany.MyHelloActivity;
並MyTestClass的建構子,如下:

這裡的”com.myCompany”指的是package name.,也就是告訴super class說,我要使用com.myCompany的MyHelloActivity的class.

6. 加入setUp() function,這個function是整個test project在開始test 程序之前會先被呼叫的,在這裡需要先確保需要使用到的變數都先被初始化。

在setUp()裡,也許你需要加上
setActivityInitialTouchMode(false);
如果在你的test procedure裡有送出一些key events,一定要將touch mode設定成off。如果沒有用到key events,可以不管這一行。

7. 加入preconditions() function,這個function是用來做前置測試用,先確保等一下要被呼叫的test functions裡面用到的變數,物件都是有用的資訊。跟setUp()作用很相似,Android development help裡面提到,preconditions只會被呼叫一次,但是setUp是每一個test function被呼叫之前都會先被執行一次。


8. 原文補充:The purpose of testing initial conditions is not the same as using setUp(). The JUnit setUp() runs once before each test method, and its purpose is to create a clean test environment. The initial conditions test runs once, and its purpose is to verify that the application under test is ready to be tested.

10. 最後加入要測試的functions,根據測試結果只要是test開頭的function都會被執行。


11. 執行unit test


12. 範例原始碼


13. 執行結果,如下圖。
根據這樣的資訊,我們可以知道在每個test procedure被執行之前,都會先呼叫setUp(),所以我們應該將變數的初始化放在這個地方。Android development裡面提到testPreconditions只會被執行一次,但是系統執行test開頭的的順序似乎是以function name的ascii順序來執行的。


14. 參考來源:
Android develop: http://developer.android.com/resources/tutorials/testing/helloandroid_test.html