This series will be tinker from the following three aspects of source code analysis:
- Android Hot update open source project Tinker source Parsing series one: Dex Hot update
- Android Hot update open source project Tinker source Parsing Series II: Resource File Hot update
- Android Hot update open source project Tinker Source parsing system Three: so file hot update
Reprint please indicate the source of this article:http://www.cnblogs.com/yyangblog/p/6252855.html
More content Welcome to star author's GitHub:https://github.com/LaurenceYang/article
If you find any questions or suggestions in this article, please feel free to contact me at any time.
Let's start by talking about the two ways Android has loaded on so:
Method One: System.loadlibrary, this way incoming is the name of so, will directly from the system directory to load so file, the system path includes/data/data/${package_name}/lib,/system/lib,/ Such paths as the Vender/lib.
Mode two: System.load, this method is passed in the absolute path of so, directly from the path to load so file.
The principle of tinker so file hot update is to load the new so implementation directly via mode two.
Compared to Dex and resource updates, it is not much simpler.
The hot update process for so files, like Dex, resource files, contains patch generation, patch synthesis, and patch loading three parts.
Compare new and old so files when generating patches using the BSDIFF algorithm to generate a patch package,
Then, after the patch succeeds, the patch package and the old library are synthesized according to the Bspatch algorithm, and the new library is
and save the updated library library file in the directory below Tinker,
This directory is/data/data/${package_name}/tinker/lib.
It then loads the so file directly from the directory through System.load.
The specific source code is no longer elaborated.
It is important to note that the hot update of so in Tinker is not a user-free, requiring users to load their own library files, the following is a description of the Tinker wiki:
However, Tinker does not directly add the patch Lib path to the dexpathlist, in theory this can be done completely unaware of the program library files to patch. This is mainly because in the case of multi-ABI, some machines get inaccurate.
So you want to load the latest library, you need to use Tinkerinstaller.load*library to load the library file, it will automatically try to go to tinker in the library file loading, loading is not successful will call System.loadlibrary call the system library file.
1 // Load Lib/armeabi Library 2 tinkerinstaller.loadarmlibrary (Getapplicationcontext (), "stlport_shared"); 3 // Load lib/armeabi-v7a Library 4 tinkerinstaller.loadarmv7library (Getapplicationcontext (), "stlport_shared");
In addition, for the loading of third-party library files, Tinker cannot intervene in its loading time, but only if the third-party library file is loaded in our code.
If you want to update the library files for third-party code, you can first use Tinkerinstaller.load*library to load the third-party library in advance!
The current mode of use does not seem to be transparent to developers, because Tinker wants to minimize the problem of compatibility with the hook system framework.
To this, Tinker's source parsing series to this end.
This series provides a brief process analysis from the point of view of Dex, resource file and so patch generation, patch synthesis and patch loading.
Because of their limited level, many places are not too deep.
Students interested in Tinker can go to Tinker's official GitHub to see more documents.
Also welcome everyone to shoot bricks.
Reprint please indicate the source of this article:http://www.cnblogs.com/yyangblog/p/6252855.html
More content Welcome to star author's GitHub:https://github.com/LaurenceYang/article
If you find any questions or suggestions in this article, please feel free to contact me at any time.
The next article will explain the issues that need to be considered in the actual use of the tinker process.
"Original" Android Hot update open source project Tinker Source Parsing series three: so hot update