Android热补丁动态修复技术设计与实现

本系统旨在完成Android系统下的APP热补丁,使用AndroidStudio为Android端开发工具,Eclipse为后台开发工具,Java为主要程序设计语言,Groovy为辅助程序设计语言。


摘   要:Android应用在上线之后,往往会出现多种多样的问题。当发现问题时,服务提供商就会开始解决问题,打包新的项目,并对新的应用进行测试,最后通过各个渠道提供商提示用户升级等操作。即使是很小的问题或漏洞,也要付出巨大的成本进行换包和重新发布。少数服务提供商为了避免这种情况,会在终端加入强制更新逻辑,或者加入这个功能的远程控制开关。该方式严重影响用户体验并且需要对程序现有的框架进行大面积修改。因此需要一种实时更新方式,在不影响用户体验的前提下进行本地所有字节码文件的更新,且不影响原本的框架。

本系统旨在完成Android系统下的APP热补丁,使用AndroidStudio为Android端开发工具,Eclipse为后台开发工具,Java为主要程序设计语言,Groovy为辅助程序设计语言。合理设计了字节码注入、dex插入、推送、补丁包管理、Java文件对比及自动打包五大模块,实现了Java文件的自动打包、半自动推送、补丁包管理、dex插入等操作和管理。

文章首先介绍了系统的背景和意义,描述了系统的开发环境设置和相关技术,主体部分讨论和进行了概要设计、详细设计与实施过程,并对开发过程中出现的多种问题进行总结和展望。根据调试与初步测试,系统能够实现预期的目标,运行稳定。

关键词:热更新;字节码;dex插入;反射;

Abstract:Many problems may happen after one Android application is running online, then the service provider is going to resolve the problems. The new project will be packaged, and the new application will be tested. Finally, the channel providers will suggest users upgrade the application. Even a very small problem or bug may produce huge cost to change the package and release it. In order to avoid the situation mentioned above, some service providers may use forced update logics at the terminal or use remote control switch, which are seriously decrease the user experience and need a lot of modifications to the current program framework. So, a real-time update mechanism is needed, which can update local binary classes without any influence to user experience and current framework.

This system is employed to accomplish the hotfix under Android environment. AndroidStudio is used here as the development tool for Android, Eclipse is used here as the development tool for back-end, Java is used here as the main programming language, and Groovy is used here as the auxiliary programming language. The modules of binary codes injection, dex insertion, push, hotfix package management, Java file comparison and automatic packaging are reasonably designed, and their operations and managements are implemented.

First, the background and meaning of the system are introduced, the development environment settings and corresponding technologies are described. Second, the summary design, detailed design and implementation are discussed, then some questions happened during the development are summarized, and some prospects and conclusions are also discussed. With the debugging and primary test, the system achieves the expected targets and runs stably.

Keywords:  hot patch; byte code; dex’s interposition;reflection;

目  录

第一章  绪论 1

1.1 开发背景及意义 1

1.2 系统设计的主要内容 2

1.3 相关技术介绍 2

1.3.1 Java简介 2

1.3.2 Groovy简介 2

1.3.3 JAVAssist库 2

1.3.4 dex插入技术 3

1.3.5 防止CLASS_ISPREVERIFIED化技术 3

1.3.6 自动打包补丁 5

1.3.7 JVM的动态加载类 5

1.4 开发工具介绍 5

1.4.1 Eclipse介绍 5

1.4.2 AndroidStudio介绍 5

第二章  系统概要设计 6

2.1 系统概要设计 6

2.1.1 系统需求 6

2.1.2 系统设计 6

2.2 系统架构概要设计 9

第三章 系统详细设计与实施技术 10