Android based on proxy/delegate for bug hot fixes

Source: Internet
Author: User

I. Overview

Now more and more apps are starting to use the local app combined with HTML5 's design structure, which can not only cross the platform, and in a certain business or module has a serious bug, can be directly in the html5+ background real-time repair, Eliminates the steps to publish new packages and new versions. How do I implement a hot fix bug without repackaging the updated version in an Android app that isn't HTML5 structured? One way to do this is by upgrading the Dex file to fix the emergency bug on the online package.

Two. Example

This example is an extension of the previous Android source Deskclock (iii) PROXY/DELEGATE application Framework application.

This talk about heat repair using the proxy/delegate application framework.

The main implementation of the process:

1. dex file replacing the main program Dex file as the agent launcher

2. Dynamic loading of the main program Dex after the agent startup program starts

3.ProxyApplication Replacement eliminates itself as a context reference for MyApplication

4. Start the application of the main program.

After the steps described above, because the program starts Dex is just a proxy, and the main program Dex is dynamically loaded, so you can reach the goal of not upgrading the main program does not change the version number only the Dex file to repair the online emergency bug.

since two DEX files are used here, it is necessary to proxyapplication the entire previous blog, as a module, with the main program peer.


the previous blog because there is no need to replace the ClassLoader, so in the myproxyapplication of an empty Attachbasecontext method, Here it is necessary to replace the ClassLoader of the Myproxyapplication's parent class with the Dexclassloader of the main program Dex in Attachbasecontext reflection, so that both the main Dex can be dynamically loaded, There is the first entry that allows the outside including the delegateapplication itself to think that Delegateapplication is 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 point, the main program's Dex file is placed on the other path, waiting for the agent to start Dex to load him, so that you can download the update Dex from the server to the path OK. This fix is done by simply replacing the Dex file, without updating the resource file, So you can only fix some urgent bugs that don't involve changing existing resources. I believe it is enough in most cases. And based on Proxy/delegate can also be very good to expand, such as plug-in, multi-dex technology.

Reprint Please specify source: http://blog.csdn.net/l2show/article/details/46967987

Android based on proxy/delegate for bug hot fixes

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.