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冲突,不好检查,不推荐。

但这并没有结束,google在4.1之后对这部分重新做了整理修改。

来看下做法吧

4.1及以后做法

在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 ***/>

eg.  <public type="string" name="sound\_mute"/>

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

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

然后将<public type="string" name="sound\_mute"/> 修改为<public type="string" name="sound\_mute" id="0x1040019"/>

这就完成了。也就添加了一个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,免得全部手写。

点赞
收藏

评论区

加载中...

相关推荐

MySQL:[Err] 1292 - Incorrect datetime value: ‘0000-00-00 00:00:00‘ for column ‘CREATE_TIME‘ at row 1

文章目录问题用navicat导入数据时,报错:原因这是因为当前的MySQL不支持datetime为0的情况。解决修改sql\mode:sql\mode:SQLMode定义了MySQL应支持的SQL语法、数据校验等,这样可以更容易地在不同的环境中使用MySQL。全局s

Oracle 分组与拼接字符串同时使用

SELECTT.,ROWNUMIDFROM(SELECTT.EMPLID,T.NAME,T.BU,T.REALDEPART,T.FORMATDATE,SUM(T.S0)S0,MAX(UPDATETIME)CREATETIME,LISTAGG(TOCHAR(

MySQL部分从库上面因为大量的临时表tmp_table造成慢查询

背景描述Time:20190124T00:08:14.70572408:00User@Host:@Id:Schema:sentrymetaLast_errno:0Killed:0Query_time:0.315758Lock_

皕杰报表之UUID

​在我们用皕杰报表工具设计填报报表时,如何在新增行里自动增加id呢?能新增整数排序id吗?目前可以在新增行里自动增加id,但只能用uuid函数增加UUID编码,不能新增整数排序id。uuid函数说明:获取一个UUID,可以在填报表中用来创建数据ID语法:uuid()或uuid(sep)参数说明:sep布尔值,生成的uuid中是否包含分隔符'',缺省为

手写Java HashMap源码

HashMap的使用教程HashMap的使用教程HashMap的使用教程HashMap的使用教程HashMap的使用教程22

2020年前端实用代码段,为你的工作保驾护航

有空的时候,自己总结了几个代码段,在开发中也经常使用,谢谢。1、使用解构获取json数据let jsonData  id: 1,status: "OK",data: 'a', 'b';let  id, status, data: number   jsonData;console.log(id, status, number )