为了得到答案,我们应该遍历
.Dex Format.在我们的例子中,最有趣的部分是method_ids数组:
method identifiers list. These are identifiers for all methods
referred to by this file, whether defined in the file or not. This
list must be sorted, where the defining type (by type_id index) is the
major order, method name (by string_id index) is the intermediate
order, and method prototype (by proto_id index) is the minor order.
The list must not contain any duplicate entries.
无论数组记录的数量是否存储为32位无符号整数(请参阅method_ids_size字段),实际上此数组不能包含超过65536个条目.这是因为invoke-xxxx dex指令的method_id操作数是一个16位实体,并且必须是method_ids的有效索引.因此,字节码无法访问索引大于65535的记录.所有这些导致众所周知的“64K方法”问题.
因此,正如文档所说 – method_ids每个方法由dex和外部方法定义一个记录,由定义方法的代码引用.
因此,每次添加代码如下:
public native void foo();
到你的一个类 – 你在method_ids中得到一个额外的记录.对于抽象方法的声明也是如此.然后,每次添加一些常规方法的实现,如:
public void baz() {
/* ... */
}
你得到一个baz()本身的新记录和baz()引用的所有方法的记录,并且还没有添加到method_ids.
本机代码对dex内容完全没有影响,因为所有C/C++源都被编译成机器代码,通过.so文件分发.这些使用ELF格式,它有自己的局限性,完全独立于DEX.