Android hotfix bugs Based on Proxy/Delegate and androiddelegate

Source: Internet
Author: User

Android hotfix bugs Based on Proxy/Delegate and androiddelegate
I. Overview

Nowadays, more and more apps begin to use local apps in combination with the html5 design structure. In this way, not only cross-platform applications can be used, but also serious bugs may occur in a service or module, it can be repaired directly in the html5 + background in real time, eliminating the need to release new packages and versions. in android apps that are not html5 structured, how does one implement hotfix without repackaging and updating versions? One method described here is to upgrade the dex file to fix urgent bugs in online packages.

Ii. Instance

This example is an extension of the previous Android source code javasclock (3) Proxy/Delegate Application framework Application.

This article describes the hot fix using the Proxy/Delegate Application framework.

Main implementation process:

1. Replace the dex file of the main program with the dex file of the Agent Startup Program.

2. After the agent starts, the main program dex is dynamically loaded.

3. Replace ProxyApplication to eliminate the reference of Context as MyApplication

4. Start the Application of the main program.

After the above steps, because the program starts dex as a proxy, and the main program's dex is dynamically loaded, therefore, you can fix online emergency bugs by upgrading the dex file without upgrading the main program or changing the version number.

Because two dex files are used here, we need to strip the ProxyApplication in the previous blog as a Module, which is the same as the main program.


The previous blog did not need to replace ClassLoader, so I wrote an empty attachBaseContext method in MyProxyApplication, here, we need to replace the parent class instance of ClassLoader of MyProxyApplication in attachBaseContext reflection as the primary program dex's DexClassLoader, so that the primary dex can be dynamically loaded, it can make the external, including DelegateApplication, think that DelegateApplication is the first entry of the program.

        ClassLoader curLoader = ctx.getClassLoader();        DexClassLoader parentLoader = new DexClassLoader(dexPath, outputDir.getAbsolutePath(), nativeLibraryDir, curLoader.getParent());        Field f = ClassLoader.class.getDeclaredField("parent");        f.setAccessible(true);        f.set(curLoader, parentLoader);
At this time, the dex file of the main program is put down in other paths, waiting for the agent to start dex to load him, so that you can download and update dex from the server to this path and then OK. this method is only used to replace the dex file without updating the resource file. Therefore, you can only fix some urgent bugs that are not involved in changing existing resources. I believe it will be enough in most cases. the Extension Based on Proxy/Delegate can also be very good, such as plug-in and multi-dex technology.

Reprinted please indicate the source: http://blog.csdn.net/l2show/article/details/46967987

Related Article

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.