2014年3月19日 星期三

adb device 無法發現裝置

前一陣子突然間手上的android device無法被ubuntu認識。
下了adb device指令一直沒有出現device裝置。

查了好幾個地方都沒有問題。
查看 /etc/udev/rules.d/99-android.rules也都正確。(參考資料)

最後同事教了一招。
在home目錄下有一個 .android 的目錄
裏面會有一個 adb_usb.ini 檔,請將 device 的 usb vendor id 加到此檔最後一行即可。
如何查詢device usb vendor id 請參考連結


最後檔案會如下範例:
$ cat .android/adb_usb.ini 
# ANDROID 3RD PARTY USB VENDOR ID LIST -- DO NOT EDIT.
# USE 'android update adb' TO GENERATE.
# 1 USB VENDOR ID PER LINE.
0x0110

其中,0x0110就是查出來的usb vendor id.

重新啟動adb一次就可以了。
$ adb kill-server
$ adb devices


2014年2月16日 星期日

在 ubuntu裡安裝sun java


  1. 下載JDK
    1. 首先下載官方的JDK. 官方網站有許多的選項,其中JDK是指Java Development Kit,如果你是開發人員,應該選擇這個。另外JRE是指Java Runtime Environment。
    2. 官方下載網站:http://www.oracle.com/technetwork/java/javase/downloads/index.html
    3. 接下來要選擇Java版本,Java分為許多版本,其中Java SE是指Standard Edition,選擇好一個版本之後,按下download,會連到更詳細的連結,這時請選擇你的OS平台,其中還分成rpm跟non-rpm,因為ubuntu不支援rpm安裝方式,所以請選擇non-rpm的版本下載。
    4. 以下假設下載的檔明為jdk6.bin
    5. 請先將此檔案改成可執行的權限
    6. chmod a+x jdk6.bin
    7. 直接執行它即可得到一個解壓縮的路徑
    8. ./jdk6.bin

  2. 安裝JDK
  3. 設定路徑
    1. export JAVA_HOME=/usr/java/jdk1.7.0 
  4. export PATH=$JAVA_HOME/bin:$PATH 
  5. export CLASSPATH=.:$JAVA_HOME/lib 

2014年2月13日 星期四

如何在eclipse下build有system權限的apk


以下為各位介紹如何在eclipse下build有system權限的apk. 並相關會遇到的問題。

當我們要寫一支system permission的apk時,需要在AndroidManifast.xml加入下面文字:
    android:sharedUserId="android.uid.system"
    < uses-permission android:name="android.permission.REBOOT" / >
    < uses-permission android:name="android.permission.UPDATE_DEVICE_STATS" / >
    .....
然而,加入之後,會有一些狀況,描述如下:


1. eclipse build error:
在eclipse的perference中,有一些android的相關設定。
在Android\Lint Error Checking\ProtectedPermissions預設是error等級(詳如下圖),也就是說當eclipse檢查到某些被定義成system權限的字串時,會提示user error訊息。
這樣的機制導致於無法build這個apk.
如:< uses-permission android:name="android.permission.REBOOT" / > 就被判定為 error 等級

解決方式:
到preference中將ProtectedPermissions設成warning即可通過eclipse檢查。也可build出具system權限的apk.

2. adb install:
雖然#1經過修改eclipse裡面的設定可以避開檢查,成功build出apk。
但是adb install會因權限呼叫PackageManager檢查signature。結果會出現沒有signatures.

adb logcat如下:
E/PackageManager( 176): Package com.test.android.testreboot has no signatures that match those in shared user android.uid.system; ignoring!
adb install回應如下:
Installation error: INSTALL_FAILED_SHARED_USER_INCOMPATIBLE


3. adb push:
既然adb install不成功,那改用adb push.
adb push雖然不會因權限檢查signature,但是android執行時會因權限檢查signatures,導致於下列error.
adb logcat如下:
E/PackageManager( 176): Package com.test.android.testreboot has no signatures that match those in shared user android.uid.system; ignoring!

#2跟#3的解決方式:
用相對應的platform key去sign過即可解決問題。
Sign key語法如下:
java -jar signapk.jar [pem certificate file of platform] [pk8 certificate file of platform] [origin.apk] [target.pak]
example:
java -jar signapk.jar platform.x509.pem platform.pk8 origin.apk target.pak


其他資訊#1:
如果沒有加上
android:sharedUserId="android.uid.system",
只有加
是可以build出apk,也可以用adb install方式安裝,但是runtime會出現下列錯誤訊息:

adb logcat如下:
E/AndroidRuntime( 1131): java.lang.SecurityException: Neither user 10048 nor current process has android.permission.REBOOT.


其他資訊#2:
eclipse的權限檢查不是檢查
    android:sharedUserId="android.uid.system"
而是檢查
    < uses-permission android:name="android.permission.REBOOT" / >
    < uses-permission android:name="android.permission.UPDATE_DEVICE_STATS" / >
導致上述問題的,應該還有其他項目,目前沒有找到哪裡有詳細列出檢查的項目。


2014年2月9日 星期日

How to contribute code to AOSP

1. You need a google account. Click here to register a new one.
2. Setup your environment.
3. Download Android source code from AOSP.
3.1. #repo init -u
4. Modify file.
5. Commit in your local.
6. push code to AOSP.

2013年12月19日 星期四

Eclipse cannot load SWT libraries

After installed eclipse in ubuntu 12.04. you may meet the following problem.

Eclipse cannot load SWT libraries

The log looks like belows.
 11         java.lang.UnsatisfiedLinkError: Could not load SWT library. Reasons:
 12         no swt-gtk-3740 in java.library.path
 13         no swt-gtk in java.library.path
 14         Can't load library: ~/.swt/lib/linux/x86_64/libswt-gtk-3740.so
 15         Can't load library: ~/.swt/lib/linux/x86_64/libswt-gtk.so

The solution is: 
echo "-Djava.library.path=/usr/lib/jni/" >> /etc/eclipse.ini




2013年7月18日 星期四

git revert without change-id

We can use git revert to revert a commit. But if you need a change-id, you will find git revert won't invoke commit-msg hooks. And you won't get a change-id for this commit.
Here is a workaround.

git revert -n <<commit-id>>
git commit

refer to git-revert,
-n
--no-commit
Usually the command automatically creates some commits with commit log messages stating which commits were reverted. This flag applies the changes necessary to revert the named commits to your working tree and the index, but does not make the commits. In addition, when this option is used, your index does not have to match the HEAD commit. The revert is done against the beginning state of your index.
This is useful when reverting more than one commits' effect to your index in a row.

2013年7月15日 星期一

how to add an existing git repo. to gerrit project.

1. Create new project in gerrit. command as below.
ssh -p 29418 user@gerrit.server gerrit create-project --name gerrit_project_name

2. Push existing git repo. to gerrit server as below.
git push ssh://user@gerrit.server:29418/gerrit_project_name HEAD:refs/heads/master