1、將資源放入 frameworks/base/core/res/res/ 中的相應目錄,假設要添加的資源是 drawable 類型,檔案名稱為 test(尾碼可能為xml或者png等等),則將檔案放入 frameworks/base/core/res/res/drawable*/ 下。
2、仿照已有的同類型系統資源修改 framework/base/core/res/res/values/public.xml,public.xml中有兩種類型的資源描述,一種是<java-symbol/>系統私人的資源(不對app公開),另一種是<public />公用資源(可以在app中訪問)。
如果要添加的資源是私人的,則加上 <java-symbol type="drawable" name="test" />(不需要id),如果是公用的則先找到最後一個type為 drawable 的 public 項,4.1.2系統中最後一項為<public type="drawable" name="dialog_holo_light_frame" id="0x010800b3"
/>,然後添加一句 <public type="drawable" name="test" id="0x010800b4" />,即id為最後一個的id+1(為了避免 id 衝突)
3、在 frameworks/base/core/res/ 中執行mm,編譯後產生framework-res.apk 並會更新com.android.internal.R,該 R 所對應的檔案為 /out/target/common/R/com/android/internal/R.java,可以在該檔案中查看自己的資源是否已經加進去了。(如果mm出錯可以嘗試先執行一下“touch 資源檔”命令)
4、如果添加的是公用資源,則還需要在源碼目錄下執行 make update-api 以更新 frameworks/base/api/current.txt 檔案。
5、完成之後在源碼根目錄中 make 即可。
另外,如果要在系統中添加一個新的id,比如為myid,則上述第一步改為在 frameworks/base/core/res/res/values/ids.xml 中增加一列<item type="id" name="myid" />,之後的步驟都一樣。
註:在4.2源碼中,將系統私人資源分離成了單獨的檔案symbols.xml,公用資源仍然在public.xml中。
原文轉自:http://blog.csdn.net/june5253/article/details/8351448