Android Hot patch Dynamic Repair

Source: Internet
Author: User

1. Preface

Because of the use of thermal repair technology in the company's projects, there was little knowledge of the technology before, so there was time to learn.

2. Learning Resources

2.1 Hot Fix Introduction

Or the brilliant explanation of the teacher, the middle cited the Andorid Dex subcontracting scheme and the QQ space of the hot repair technology paste.

2.2 Other relevant knowledge

The differences between Pathclassloader and Dexclassloader are as follows:
Both 1.DexClassLoader and Pathclassloader belong to class loaders that conform to the parental delegation model (because they do not have the LoadClass method overloaded). That is, before they load a class, they go back to check themselves and whether the class loader has already loaded the class. If it has already been loaded, it will be returned directly instead of being loaded repeatedly.
Both 2.DexClassLoader and Pathclassloader actually implement class loading by Dexfile this class. By the way, the Dalvik virtual machine recognizes the Dex file instead of the class file. Therefore, the file that we are loading for the class can only be a Dex file or an. apk or. jar file that contains a Dex file.
3.PathClassLoader generates Dexfile objects through the constructor new Dexfile (path), while Dexclassloader is loaddex through its static method (path, Outpath, 0) Get Dexfile object. The difference between the two is that Dexclassloader needs to provide a writable Outpath path to release the. apk package or the Dex file in the. jar package. In other words, Pathclassloader cannot voluntarily release Dex from the ZIP package, so it only supports the direct operation of the DEX format file, or the installed APK (since the installed apk has a cached Dex file in the cache). Dexclassloader can support. APK,. jar, and. dex files, and the Dex file is released in the specified Outpath path.

4. In addition, Pathclassloader calls the Dexfile Loadclassbinaryname when the class is loaded, and Dexclassloader calls LoadClass. Therefore, the class full name needs to be replaced with "/" when using Pathclassloader.

3. Summary

Through the study of materials, I summarize from the following aspects:

3.1, the purpose of hot repair: To achieve the release of the new version of the situation in the repair of some bugs in the app, thereby reducing production costs.

3.2. The principle of heat repair: Dynamically inject the dexfile contained in the patch (Jar package) into the ClassLoader dexelements.

3.3, the thermal repair implementation of the steps:

Package the modified class as a Dex file, and then write the Dex file to a file in the app's private directory. Then use Pathclassloader and Dexclassloader to get the original Dexelements object and the Dexelements object of the patch and merge the two, the dexelements of the patch is placed at the top of the merge. Finally, the new array dexelements is set to PathList by reflection.

Android Hot patch Dynamic Repair

Contact Us

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.

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.