GitHub - iReaderAndroid/ZeusHotfix: android-app热修复

  • 将项目中的zeushotfix下的类拷贝到你的项目中。

  • 在你的项目的AndroidManifest.xml中添加如下代码:

    InstallHotfixService为安装的service,在独立进程中进行安装,安装完成后自动杀死当前进程,对主进程无影响 HOTFIX_VERSION为当前的热修复版本,只有该值相同的apk才能进行更新,每次更新了以下信息时请增加该值:

     1.AndroidManifest.xml中的除了version code 和version name的其他信息;
     2.Window启动动画,即activity/Dialog/window/popupWindow;
     3.Activity的theme中的style;
     4.通知栏图标;
     5.桌面widget资源;
     6.apk名称;
    
  • 将HotfixLoaderUtil.java中的APPLICATION_NAME替换为你apk中的Application,如果你没有自己的application则不用替换,如果apk加固了就替换为加固后的Application。 APPLICATION_NAME_DEBUG为调试时的Application,如果没加固就跟APPLICATION_NAME相同即可。

  • 在你的项目中添加新apk的下载逻辑,请自行实现。

  • 将下载完成的apk进行安装,调用方式类似MainActivity.java中的copyHotfixApkAndInstall()方法,具体请参考该方法实现。

  • 安装完成后,重启主进程即可使用安装的新版本apk。

  • 如果apk被加固,请将com.zeushotfix.wrap放到加固壳的外部,inside与wrap代码是相互隔离的,方法不能相互调用,所以有重复代码,如果不需要加固,直接删除其中重复的类即可。

  • 该框架主要提供两个方法,即补丁apk的安装和加载。HotfixLoaderUtil.java中加载补丁attachBaseContext()方法和HotfixInstallerUtil.java中的安装补丁installHotfix()方法。

  • MIT LICENSE 
    Copyright (c) 2016 zhangyue
    
    Permission is hereby granted, free of charge, to any person obtaining
    a copy of this software and associated documentation files (the
    "Software"), to deal in the Software without restriction, including
    without limitation the rights to use, copy, modify, merge, publish,
    distribute, sublicense, and/or sell copies of the Software, and to
    permit persons to whom the Software is furnished to do so, subject to
    the following conditions:
    
    The above copyright notice and this permission notice shall be
    included in all copies or substantial portions of the Software.
    
    THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
    EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
    MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
    NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
    LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
    OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
    WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.