2013年1月18日 星期五

不知道從哪時候開始, 想要用更新家裡電腦中的android source, 打repo sync後都一直出現下面這個錯誤訊息


error: Failed to connect to 2404:6800:4008:c01::52: Network is unreachable while accessing https://android.googlesource.com/platform/manifest/info/refs
fatal: HTTP request failed

就算重新repo init 一包也一樣有類似的錯誤 遲遲無法獲得最新的source code
我都懷疑難道是中華電信ipv6的機制太差還是怎樣

最後終於就在剛剛, 找到解答了
原來一切都是proxy搞得鬼
在設定好proxy後 就可以開開心心repo sync了

方法很簡單
export HTTP_PROXY=http://proxy.hinet.net:80
export HTTPS_PROXY=http://proxy.hinet.net:80



2013年1月15日 星期二

Add new internal resource in Android Jelly Bean

依據之前的經驗, 只要將新增的xml (string or icon, id)放到Android source 對應的res folder裡面之後在編譯Android 時就會自動加入到內部生成的R.java

但最近在porting Android JB時發現新增加的internal resource 並沒有被自動生成, 導致編譯時會發生 cannot find symbol的問題如下

cannot find symbol
symbol  : variable xxxxx
location: class com.android.internal.R.(...)

Google了一下後找到解決方法了, 但是不曉得這到底是不是JB的新機制(很不方便XD)

在 frameworks/base/core/res/MakeJavaSymbols.sed 裡有註明


# Run this on the errors output by javac of missing resource symbols,
# to generate the set of commands to have aapt generate
# the symbol for them.
#
# For example: make framework 2>&1 | sed -n -f MakeJavaSymbols.sed | sort -u

於是我在Android source tree的 root folder下打

$ make framework 2>&1 | sed -n -f frameworks/base/core/res/MakeJavaSymbols.sed | sort -u

執行完後就會產生
< java-symbol type="string" name="xxxxx" / >

把產生出來的這些內容直接貼到
frameworks/base/core/res/res/values/public.xml
就可以了

再來就照編譯Android 的方法來編譯就好了


Ref: http://www.cppblog.com/wythern/archive/2012/12/21/191394.html


2013年1月9日 星期三

[eclipse] failed to launch eclipse on ubuntu 12.04

由於ubuntu的default JDK是Open JDK, 但由於要編譯Android 的關係, 我把JDK換成了Oracle JDK, 而導致安裝好Eclipse後 在啟動Eclipse會失敗, 失敗訊息如下

java.lang.UnsatisfiedLinkError: Could not load SWT library. Reasons:

no swt-gtk-3740 in java.library.path

no swt-gtk in java.library.path

Can't load library: /home/hamersun/.swt/lib/linux/x86_64/libswt-gtk-3740.so

Can't load library: /home/hamersun/.swt/lib/linux/x86_64/libswt-gtk.so





解決方法是

on 64-bit
ln -s /usr/lib/jni/libswt-* ~/.swt/lib/linux/x86_64/
on 32-bit
ln -s /usr/lib/jni/libswt-* ~/.swt/lib/linux/x86/

2012年12月27日 星期四

SSH登入到遠端機器不用輸入password

偷懶一下
這次不自己打了
直接附上link
http://www.csua.berkeley.edu/~ranga/notes/ssh_nopass.html

2012年12月26日 星期三

讓git push變成default push到code review server

假設local 端clone了一份 git project, 現在修改完後要準備push上去
如果單純只是下
   git push
的話, 會變成直接push 到 git server (假設權限允許的話)

但是現在如果多了一道 code review 的流程, 那要如何讓 git push 是先push 到 code review server呢?
一個方法是使用如下command
git push origin HEAD:refs/for/master
如果不想每次都打這麼長或忘記了直接打git push而造成bypass 了 code review階段
那可以在clone下 git project後, 先打下述指令來設定
git config remote.origin.push refs/heads/*:refs/for/*
之後的git push就會先push到code review server了

2012年12月25日 星期二

[C++] Move Semantics,Perfect Forwarding, and Rvalue references

關於C++11所引進的新技術
move semantics, perfect forwarding, and rvalue reference
一定要看Scott Meyers的介紹, 仔細看絕對可以把這些東西弄清楚
http://skillsmatter.com/podcast/home/move-semanticsperfect-forwarding-and-rvalue-references

等吸收完後再來整理重點吧.... 

[C++] Lvalue reference and Rvalue reference

Rvalue reference是從C++11正式被引入的一個屬性
而由於它的引入, 讓move semantics被介紹出來

move constructor與copy constructor不同處在於
較少的memory allocation/de-allocation 和copy, 因此效能也會比較好
Move Constructor不在此文中介紹, 就留待下篇文章吧!

以下節錄自(http://binglongx.wordpress.com/2010/08/20/c0x-rvalue-reference/)
===============================================================
In C++0x (see N2844, N2812), the rules are (with const correctness in mind):
  • lvalue reference T& binds to modifiable lvalues only; (making no sense to modify a temporary) (!VC10 is different)
  • lvalue reference T const& (i.e., const T&) binds to all modifiable/const lvalues and rvalues; (harmless const reference)
  • rvalue reference T&& binds to modifiable rvalues only; (do not steal resource from a non-temporary )
  • rvalue reference T const&& (i.e., const T&&) binds to modifiable and const rvalues;
Because a reference itself is an expression, there are rules regarding whether it’s lvalue or rvalue:
  • Named lvalue reference is lvalue;         T& tr = t; // tr is lvalue.
  • Unnamed lvalue reference is lvalue;      std::vector tv; tv.at(); // tv.at() is lvalue, backing object is non-temporary.
  • Named rvalue reference is lvalue;         void foo(T&& t){ // t is lvalue, t’s type is rvalue reference.
  • Unnamed rvalue reference is rvalue;
Named rvalue reference is lvalue. This is convoluted and confusing, isn’t it? In the function body of void foo(T&& t), t is bound to an afloat rvalue object in the caller’s site, from which you can steal its guts, but t itself is lvalue. That means, if you try to pass t in this function to another function, the other function would perceive t as lvalue, and therefore t loses its rvalue-ness. Why? The reason that a named rvalue reference is a lvalue, is because with a name it can be referred to by many occurrences, and obviously not all of these occurrences can steal its resource. If this is not enforced, in the function body of void foo(T&& t), if t is passed to two other functions that expect rvalue, which of them should take t’s guts? No matter which, the program is ill-fated. C++0x makes sure the program is safe by giving the two functions only lvalue so they cannot steal from t. Once you understand this, it is no longer confusing.
================================================================
lvalue reference: 可以想像成是一個物件的另一個名字, 也就是傳統c++所指的reference; reference必須是已經被初始化且不可被改變的. 宣告方法就是type&
例如:
int a = 1;
int &b = a; // it is a lvalue reference, reference to a object

rvalue reference: 與lvalue reference很像, 但是不同的地方是rvalue reference can bind to a temporary (rvalue), 但是 (non-const)lvalue reference can't bind to a rvalue. 宣告方法為 type&&
這個可以回顧一下之前的Lvalue 與 Rvalue的定義說明以及lvalue reference的說明(reference必須是已經被初始化且不可以被改變的)
例如:
A a;
A&& a_ref = a; // an rvalue reference
A& a_ref2 = A(); // Error
A&& a_ref3 = A(); // OK

Reference