Hotfix-Nuwa learning, Hotfix-nuwa

Source: Internet
Author: User

Hotfix-Nuwa learning, Hotfix-nuwa

Nuwa hotfix is based on the idea of the QQ space team. It has been a hot topic recently. There are many kinds of solutions. I have studied several solutions first, and basically each has its own advantages, I have to pick a soft persimmon for learning. I compared it myself and found that the nuwa code is a little small, so I decided to study nuwa first.

 

First, gradle.

The examples are also available on github. You can also download other projects for reference.

Then go to the application to check the details.

Follow the process to see

The following method is the focus

/**
* Notes
* ClassLoader is used to dynamically load Class files. Each ClassLoader object must specify the Class file path during initialization.
* Generally, when you need a class, you only need to use the import keyword to include the class. However, there are two prerequisites for import:
* 1. It must exist locally. When this class is required for running a program, the internal class loader will automatically load this class, which is transparent to programmers,
* That Is, programmers cannot perceive this process,
* 2. The compilation must be performed on the site. Otherwise, the compilation will fail because the referenced file cannot be found and the plug-in class file does not meet this requirement.
*
* In general, the application does not need to create a new ClassLoader object, but uses the ClassLoader that already exists in the current environment.
* Because the Runtime environment of Javad is initialized, A ClassLoader object is created internally to load various Java classes required for Runtime.
* Each ClassLoader must have a parent ClassLoader. when loading the Class file, the sub-ClassLoader first requests the parent ClassLoader to load the Class.
* File. The sub-ClassLoader will continue to load the Class only when its parent ClassLoader cannot find the Class file. This is a security mechanism.
*
* The dex file is used to repackage all the required Class files. The packaging rules are not simple compression, but completely for the various function tables in the Class file,
* Optimize the variable table and generate a new file, which is the dex file.
* Because the dex file is an optimized Class file, a special Class loader is required to load such a special Class file.
* DexClassLoader: The DexClassLoader class provided by the Android SDK is for this purpose.
*/

/**
* Classloader has three levels, with the highest level: bootstrap classLoader intermediate level: extension classLoader
* The lowest-level app classLoader. When a class needs to be loaded, it will check whether the class has been loaded. If not, it will request the app level to load it,
* App requests extension-level extension requests are at the bootstrap level, and the highest level is responsible for loading
* (This is the parent-parent assignment, which delegates the loader of the last two levels for loading). If the advanced loader cannot be loaded, the character will be returned to the next level, and so on.
* At last, if neither parent nor parent can, load it by yourself.
* Why is this mechanism used? For example, java. lang. String is a class provided by jdk. If we customize a package name:
* Java. lang then creates a String class in it. When I use the String class, it is a bootstrap-level loader.
* To load. At this time, it finds that the jdk String has been loaded, so it will not load the custom String, preventing repeated
* Loading also increases security.
*/

The next step is to use it. After you know what the situation is, you have prepared according to the instructions in the document.

Run the nuwa project, run it, and generate a nuwa folder under outputs, copy it to the D Drive, as you like (your project \ app \ build \ outputs \ nuwa)

Then modify some content in it, for example, change an output in it, and then generate a jar package using the command (gradlew clean nuwaQihooDebugPatch-P NuwaDir = D:/nuwa)

The execution result is as follows:

 

Next, you will find the generated jar file in app \ build \ outputs \ nuwa \ qihoo \ debug in your project folder and copy the file to the root directory of your mobile phone.

 

 

Next, restart the program and find that the code has been updated.

This is the power of open-source. If it's just a matter of time, it's just a matter of time to study it. I haven't understood many details yet, but at least I have to get through the process, running is the foundation

When people planted trees, I felt quite cool. I recorded my learning path and provided it for reference.

 

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.