【Android 热修复】运行 Tinker 官方示例 ( 处理 TINKER_ID 问题 | 编译 debug 包 | 修改 Gradle 脚本 | 生成 patch 包 | 热修复 )(二)

简介: 【Android 热修复】运行 Tinker 官方示例 ( 处理 TINKER_ID 问题 | 编译 debug 包 | 修改 Gradle 脚本 | 生成 patch 包 | 热修复 )(二)

五、修改 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 程序 , 放开该行注释代码 ,



image.png





七、生成 patch 包


在 Gradle 面板中 , 运行 " tinker-sample-android / app / Tasks / tinker/ tinkerPatchDebug " 任务 , 双击即可 ;

image.png



运行完成后 , 在 " tinker-sample-android\app\build\outputs\apk\tinkerPatch\debug " 目录下生成了 patch 包 ;

image.png







八、热修复


将 app-debug-patch_signed_7zip.apk 文件 , 更名为 patch_signed_7zip.apk , 拷贝到手机 SD 卡根目录 ;

image.png



点击 " LOAD PATCH " 按钮 , 会有 Toast 提示成功 " patch success, please restart process " , 热修复成功 ;

image.png







九、 源码资源


参考资料 :


官方主页 : 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 完整项目 )


目录
相关文章
|
Java 开发工具 Android开发
如何在Eclipse中查看Android源码或者第三方组件包源码(转)
如何在Eclipse中查看Android源码或者第三方组件包源码(转)
155 4
|
存储 前端开发 测试技术
Android kotlin MVVM 架构简单示例入门
Android kotlin MVVM 架构简单示例入门
211 1
|
安全 Java Android开发
【Android P】OTA升级包定制,移除不需要更新的分区,重新打包签名
如何解压OTA升级包、编辑升级包内容(例如移除不需要更新的分区)、重新打包、签名以及验证OTA文件的过程。
1314 2
【Android P】OTA升级包定制,移除不需要更新的分区,重新打包签名
|
Android开发 开发者
Android、Flutter为不同的CPU架构包打包APK(v7a、v8a、x86)
Android、Flutter为不同的CPU架构包打包APK(v7a、v8a、x86)
1149 1
|
存储 数据库 Android开发
🔥Android Jetpack全解析!拥抱Google官方库,让你的开发之旅更加顺畅无阻!🚀
【7月更文挑战第28天】在Android开发中追求高效稳定的路径?Android Jetpack作为Google官方库集合,是你的理想选择。它包含多个独立又协同工作的库,覆盖UI到安全性等多个领域,旨在减少样板代码,提高开发效率与应用质量。Jetpack核心组件如LiveData、ViewModel、Room等简化了数据绑定、状态保存及数据库操作。引入Jetpack只需在`build.gradle`中添加依赖。例如,使用Room进行数据库操作变得异常简单,从定义实体到实现CRUD操作,一切尽在掌握之中。拥抱Jetpack,提升开发效率,构建高质量应用!
440 4
|
C# Android开发 开发者
Android gradle编译时字节码处理
Android gradle编译时字节码处理
210 1
|
Android开发
解决Android、Flutter编译时Gradle报错:javax.net.ssl.SSLException: Connection reset
解决Android、Flutter编译时Gradle报错:javax.net.ssl.SSLException: Connection reset
2119 0
|
Android开发 数据安全/隐私保护 iOS开发
ios和安卓测试包发布网站http://fir.im的注册与常用功能
ios和安卓测试包发布网站http://fir.im的注册与常用功能
858 0
ios和安卓测试包发布网站http://fir.im的注册与常用功能
|
存储 Android开发
详细解读Android获取已安装应用信息(图标,名称,版本号,包)
详细解读Android获取已安装应用信息(图标,名称,版本号,包)
537 0
|
开发工具 Android开发
技术经验分享:Android编译命令m、mm、mmm区别及工程搭建示例
技术经验分享:Android编译命令m、mm、mmm区别及工程搭建示例
1209 0

热门文章

最新文章

推荐镜像

更多