android使用tinker对app进行热修复

记录一下热更新流程,方便以后使用。
tinker项目地址:
https://github.com/Tencent/tinker
项目里包含了lib的源码和sample,下下来,然后打开tinker-sample-android:
这里写图片描述

修改mainActivity中textview:

    <TextView
        android:id="@+id/textView"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="This is old apk"/>

通过gradle生成release版的apk:
这里写图片描述
在app/build/bakApk目录下会生成apk,混淆映射文件和资源文件:
这里写图片描述

通过adb运行:

adb install -r -d F:\AndroidProgram\Demo\tinker\tinker-sample-android\app\build\bakApk\app-release-1025-10-46-35.apk

这里写图片描述

下面修改app的build.gradle文件:

ext {
    //for some reason, you may want to ignore tinkerBuild, such as instant run debug build?
    tinkerEnabled = true

    //for normal build
    //old apk file to build patch apk
    tinkerOldApkPath = "${bakPath}/app-release-1025-10-46-35.apk"
    //proguard mapping file to build patch apk
    tinkerApplyMappingPath = "${bakPath}/app-release-1025-10-46-35-mapping.txt"
    //resource R.txt to build patch apk, must input if there is resource changed
    tinkerApplyResourcePath = "${bakPath}/app-release-1025-10-46-35-R.txt"

    //only use for build all flavor, if not, just ignore this field
    tinkerBuildFlavorDirectory = "${bakPath}/app-1018-17-32-47"
}

将打包生成的老apk的三个文件对应填入tinkerOldApkPath、tinkerApplyMappingPath、tinkerApplyResourcePath,然后我们准备新版本apk,修改代码,也是改mainactivity中的textview:

    <TextView
        android:id="@+id/textView"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="This is new apk"/>

不要clean,不然android studio会删除之前打包好的apk,然后用gradle里的tinker打包:
这里写图片描述

会生成新的release版apk:
这里写图片描述
tinker对比新旧apk的差异生成一个补丁文件patch_signed_7zip.apk:
这里写图片描述
把这个补丁文件push到手机内存根目录:

adb push F:\AndroidProgram\Demo\tinker\tinker-sample-android\app\build\outputs\tinkerPatch\release\patch_signed_7zip.apk /sdcard/

回到运行的app中,点击LOAD PATCH:
这里写图片描述

然后点击KILL SELF,再次进入app,改动就生效了,同时删除了存储卡上的补丁文件:
这里写图片描述

demo里还提供了去掉补丁功能,点击CLEAN PATCH,再KILL SELF,重启app就是旧的版本。

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值