There is a Dexclassloader class on the Android system that can dynamically load DEX files, but there is a flaw in this class, which is that the first time you start and load a Dex file, you perform a dex2oat or dexopt operation, which normally doesn't feel like it's deficient, However, if you use it for reinforcement, you will have a very long initial startup time problem, for which you can use the following methods to increase the speed of the first boot:
The first is art mode, art mode to support the interpretation of the implementation of Dex file, do not need to compile, and do not need oat file, so direct hook execv function, so that the process of invoking dex2oat directly exit the good,
The hook callback function code is as follows:
int hook_execv (const char *name, char **argv) {
int ret = 0;
Char tmp[512];
if (! Isdex2oat (name)) {
Return Ori_execv (name, argv);
}
Exit (0);
}
Hook Way is got hook, the code is as follows:
void* Gothook (Soinfo *si, Char *target_name, void* hook_callback) {
Elf32_rel *rel = (elf32_rel*) si->plt_rela;
int count = si->plt_rela_count;
void *target_addr = 0;
int idx = 0;
for (idx = 0; idx<count; ++idx, ++rel) {
unsigned type = Elf32_r_type (Rel->r_info);
unsigned sym = Elf32_r_sym (Rel->r_info);
The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion;
products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the
content of the page makes you feel confusing, please write us an email, we will handle the problem
within 5 days after receiving your email.
If you find any instances of plagiarism from the community, please send an email to:
info-contact@alibabacloud.com
and provide relevant evidence. A staff member will contact you within 5 working days.