編譯android源碼中的資源檔

來源:互聯網
上載者:User

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

相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.