android framework 私有res添加

在4.1之前,在系统framewor中添加资源文件
经过Eclipse的通常应,咱们能够联想到是否就是简单的把字符串放在res的各个文件夹里面。先来试试看,编译,系统当即报错。
它提示你利用make update-api这个命令来更新public.xml文件或者把这个声明称hide类型。这怎么办呢?
方法有二:
方法1:正常添加完资源后,执行make update-api函数。系统更新res/values/public.xml文件。
方法2:正常添加完资源后,手动更改/res/values/public.xml文件。打开public.xml文件。发现结构以下:



     1. <resources> 
     2.   <!-- We don't want to publish private symbols in Android.R as part of the  
     3.        SDK.  Instead, put them here. --> 
     4.   <private-symbols package="com.android.internal" /> 
     5.   <!-- AndroidManifest.xml attributes. --> 
     6.   <eat-comment /> 
     7. <!-- ===============================================================  
     8.      Resources for version 1 of the platform. 
     9.      =============================================================== --> 
     10.   <eat-comment /> 
     11.   <public type="string" name="cancel" id="0x01040000" /> 
     12.   <public type="string" name="copy" id="0x01040001" /> 
     13.   <public type="string" name="copyUrl" id="0x01040002" /> 
     14.    <public type="style" name="TextAppearance.Widget.TextView.SpinnerItem" id="0x01030052" /> 
     15.   <public type="style" name="TextAppearance.WindowTitle" id="0x01030053" /> 
     16.   <public type="attr" name="theme" id="0x01010000" /> 
     17.   <public type="attr" name="label" id="0x01010001" /> 
     18.   <public type="attr" name="icon" id="0x01010002" /> 
     19.   <public type="attr" name="name" id="0x01010003" /> 
     20.   <public type="attr" name="manageSpaceActivity" id="0x01010004" /> 
     21.   <public type="attr" name="allowClearUserData" id="0x01010005" /> 
     22.   <public type="attr" name="permission" id="0x01010006" /> 
     23.   <public type="attr" name="readPermission" id="0x01010007" /> 
     24.   <public type="attr" name="writePermission" id="0x01010008" /> 
     25.   <public type="attr" name="protectionLevel" id="0x01010009" /> 
     26. <!-- ===============================================================  
     27.      Resources added in version 7 of the platform (Eclair MR1). 
     28.      =============================================================== --> 
     29.   <eat-comment /> 
     30.   <public type="attr" name="author" id="0x010102b4" /> 
     31.   <public type="attr" name="autoStart" id="0x010102b5" /> 
     32.     
     33. </resources> 


能够本身动手添加,但比较麻烦,容易引发id冲突,很差检查,不推荐。java

但这并无结束,google在4.1以后对这部分从新作了整理修改。android

来看下作法吧ubuntu

4.1及之后作法 api

在Androird JellyBean 4.1.0的framework里面添加一个res,把xml写好之后编译时候报错以下的错误

        int ticker = com.android.internal.R.string.xxxxxxxxxx;
                                                  ^
frameworks/base/services/java/com/android/server/StatusBarManagerService.java:143: cannot find symbol
symbol  : variable xxxxxxxxxx
location: class com.android.internal.R.drawable安全

 

1,在public.xml 里添加一项<public ***/>ide

eg.  <public type="string" name="sound_mute"/>函数

而后make update-api,这时在api/current.txt中生成this

field public static final int sound_mute = 17039385; // 0x1040019google

而后将<public type="string" name="sound_mute"/> 修改成<public type="string" name="sound_mute" id="0x1040019"/>code

这就完成了。也就添加了一个public的属性,但出于安全考虑,建议用下面方式。


2,解决办法很简单,在MakeJavaSymbols.sed里面有:
# Run this on the errors output by javac of missing resource symbols, 
# to generate the set of <java-symbol> commands to have aapt generate
# the symbol for them.

# For example: make framework 2>&1 | sed -n -f MakeJavaSymbols.sed | sort -u
编译方法 在 jb下, make framework 2>&1 | sed -n -f frameworks/base/core/res/MakeJavaSymbols.sed | sort -u

eg.  

hanhy@ubuntu11:~/ice2-901/trunk/jb$ make framework 2>&1 | sed -n -f frameworks/base/core/res/MakeJavaSymbols.sed | sort -u  

编译会产生
  <java-symbol type="string" name="xxxxxxxxxx" /> 
把这个copy到publlic.xml。再从新编译一次就搞定了。

public.xml也提到
<!-- Private symbols that we need to reference from framework code.  See
       frameworks/base/core/res/MakeJavaSymbols.sed for how to easily generate
       this.
  -->

4.2里把private部分的单独分离出来了,在symbols.xml里 看起来全部private的internal res都必须在这里声明一下。JellyBean之前貌似没有这么麻烦。好在他提供了一个sed,省得所有手写。

相关文章
相关标签/搜索