五、修改 Gradle 构建脚本中的文件名称
根据上一步生成的两个文件
app-debug-0423-21-38-18.apk
app-debug-0423-21-38-18-R.txt
修改 app 下的 build.gradle 构建脚本 " tinker-sample-android\app\ build.gradle" , 主要使用 " 0423-21-38-18 " 这个时间参数 ;
在 Gradle 构建脚本中 , 修改如下四个变量中的时间相关值 , 将时间参数修改为 " 0423-21-38-18 " ,
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-debug-0424-15-02-56.apk" //proguard mapping file to build patch apk tinkerApplyMappingPath = "${bakPath}/app-debug-1018-17-32-47-mapping.txt" //resource R.txt to build patch apk, must input if there is resource changed tinkerApplyResourcePath = "${bakPath}/app-debug-0424-15-02-56-R.txt" //only use for build all flavor, if not, just ignore this field tinkerBuildFlavorDirectory = "${bakPath}/app-1018-17-32-47" }
修改后的效果 :
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-debug-0423-21-38-18.apk" //proguard mapping file to build patch apk tinkerApplyMappingPath = "${bakPath}/app-debug-0423-21-38-18-mapping.txt" //resource R.txt to build patch apk, must input if there is resource changed tinkerApplyResourcePath = "${bakPath}/app-debug-0423-21-38-18-R.txt" //only use for build all flavor, if not, just ignore this field tinkerBuildFlavorDirectory = "${bakPath}/app-0423-21-38-18" }
六、修改程序逻辑代码
修改 MainActivity 程序 , 放开该行注释代码 ,
七、生成 patch 包
在 Gradle 面板中 , 运行 " tinker-sample-android / app / Tasks / tinker/ tinkerPatchDebug " 任务 , 双击即可 ;
运行完成后 , 在 " tinker-sample-android\app\build\outputs\apk\tinkerPatch\debug " 目录下生成了 patch 包 ;
八、热修复
将 app-debug-patch_signed_7zip.apk 文件 , 更名为 patch_signed_7zip.apk , 拷贝到手机 SD 卡根目录 ;
点击 " LOAD PATCH " 按钮 , 会有 Toast 提示成功 " patch success, please restart process " , 热修复成功 ;
九、 源码资源
参考资料 :
官方主页 : https://github.com/Tencent/tinker
Tinker 官方 Wiki 地址 : https://github.com/Tencent/tinker/wiki
Tinker 接入指南 : https://github.com/Tencent/tinker/wiki/Tinker-接入指南
Tinker 官方示例 : https://github.com/Tencent/tinker/tree/master/tinker-sample-android
源码资源 :
GitHub 地址 : https://github.com/Tencent/tinker/tree/dev/tinker-sample-android
CSDN 源码快照 : https://download.csdn.net/download/han1202012/17417498
( Tiinker 完整项目 )