美团robust使用
最近在整理各个热修复的使用方法和原理,第一个研究的是美团的robust
github地址为robust
基本的使用方法其实github上面有,但是我发现我集成花费了一天的时间,还有是有很多坑的所以才写了这篇文章记录一下
首先是APP目录的build里面增加我红色箭头标记的
带箭头的就是新增的
出了增加美团的热修复包外,还增加了权限库和分包库multidex
apply plugin: 'com.android.application'
//制作补丁时将这个打开,auto-patch-plugin紧跟着com.android.application
//apply plugin: 'auto-patch-plugin'
apply plugin: 'robust'implementation 'com.meituan.robust:robust:0.4.99'implementation 'com.github.tbruyelle:rxpermissions:0.12'implementation 'io.reactivex.rxjava3:rxandroid:3.0.0'implementation 'io.reactivex.rxjava3:rxjava:3.0.5'implementation 'com.android.support:multidex:1.0.3'
接下来是配置根目录的build
注意如果是用kotlin开发的话,这里的gradle版本和kotlin版本不能太高,否则会报错
第一个错误
java.lang.RuntimeException: java.io.IOException: invalid constant type: 19 at 5
第二个错误
Caused by: org.codehaus.groovy.runtime.typehandling.GroovyCastException: Cannot cast object 'task ':app:packageNjfBetaRelease' property 'resourceFiles'' with class 'org.gradle.api.internal.file.DefaultFilePropertyFactory$DefaultDirectoryVar' to class 'java.io.File'
在github的issue里面有解决办法
issue439
另外一个解决办法就是降低你的gradle版本
这里是第一个容易出问题的地方
继续看APP的build里面
分包记得打开
配置好签名,到时候测试的时候最好是打release包带签名的
配置签名,打开混淆
混淆文件中记得添加
-keepclassmembers class **{
public static com.meituan.robust.ChangeQuickRedirect *;
}
接下来在APP的目录下面新建robust.xml文件
里面的具体配置直接copy github里面的
robust.xml
注意上面几个地方修改成你自己的
接下来manifest记得配置权限
<uses-permission android:name="android.permission.INTERNET" /><uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" /><uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
接下来开始写测试布局
mainActivity
lateinit var textView: TextViewoverridefun onCreate(savedInstanceState: Bundle?) {super.onCreate(savedInstanceState)setContentView(R.layout.activity_main)textView = findViewById(R.id.content_tv)val file =File(externalCacheDir?.absolutePath + File.separator + "robust" + File.separator + "patch ")if (!file.exists()) {file.mkdirs()}RxPermissions(this).request(Manifest.permission.READ_EXTERNAL_STORAGE,Manifest.permission.WRITE_EXTERNAL_STORAGE).subscribe { granted ->}}fun getString(): String {return "111"}fun loadPatch(view: View) {PatchExecutor(this, PatchManipulateImp(), object : RobustCallBack {override fun onPatchListFetched(result: Boolean,isNet: Boolean,patches: MutableList<Patch>?) {}override fun onPatchFetched(result: Boolean, isNet: Boolean, patch: Patch?) {Log.d("swt", "onPatchFetched")}override fun onPatchApplied(result: Boolean, patch: Patch?) {Log.d("swt", "onPatchApplied")}override fun logNotify(log: String?, where: String?) {Log.d("swt", "logNotify")}override fun exceptionNotify(throwable: Throwable?, where: String?) {Log.d("swt", "exceptionNotify")}}).start()}fun setTV(view: View) {textView.text = getString()}
loadPatch里面有一个PatchExecutor最后记得start
主要看下第二个参数
PatchManipulateImp
class PatchManipulateImp : PatchManipulate() {override fun fetchPatchList(context: Context): MutableList<Patch> {val patch = Patch()patch.name = "test"patch.tempPath =context.externalCacheDir?.absolutePath + File.separator + "robust" + File.separator + "patch"patch.localPath =context.externalCacheDir?.absolutePath + File.separator + "robust" + File.separator + "patch"patch.patchesInfoImplClassFullName = "com.freebrio.robustdemo.PatchesInfoImpl"val list = arrayListOf<Patch>()list.add(patch)return list}override fun verifyPatch(context: Context?, patch: Patch?): Boolean {return true}override fun ensurePatchExist(patch: Patch?): Boolean {return true}
}
这里的temppath和localpath最好都设置一下吧,我没测试localpath不设置会不会有问题了,就都写了,反正temppath要设置的
然后下面俩个方法都返回true,后面导入手机的patch文件名字要改成patch_temp.jar
划重点
patch.patchesInfoImplClassFullName = “com.freebrio.robustdemo.PatchesInfoImpl”
这个包名和robust.xml里面patchPackname的配置要一样
然后最后的PatchesInfoImpl一定要写死
这里我们的类名是PatchManipulateImp但是这个地方一定要写死PatchesInfoImpl
不然会到时候抱错
PatchsInfoImpl failed,cause of java.lang.ClassNotFoundException:
到这里基本的配置就弄完了,开始打release包
./gradlew assembleRelease
打到成功后如果能出现下面几个文件那就说明前面配置的没什么大问题了
接下来在APP的目录下面新建robust文件夹把那俩个文件放进去
把APK安装到手机里面,这个APK就是我们未修复的版本
接下来我们修改mainActivity
在修改的地方添加@modify注释
同事新增一个方法,点击按钮的时候,调用getstring1方法返回222
@Modifyfun setTV(view: View) {textView.text = getString1()}@Addfun getString1(): String {return "222"}
然后把APP的build文件中的
这个插件打开
就下来继续执行
./gradlew assembleRelease
打包会失败但是没关系出现了下面的这个就可以了
然后再build目录下面会看到这个文件
将这个文件push到我们的手机中
adb push /Users/yanzhe/android/hotfixAll/robust/app/build/outputs/robust/patch.jar /storage/emulated/0/Android/data/com.freebrio.robustdemo/cache/robust/patch_temp.jar
这是我的路径你们修改成自己的路径就可以了
记得push的jar包名字为patch_temp.jar
不要问我为什么
接下来打开我们未修复的APP,点击按钮
我们第一下点击的时候textview是111,加载补丁之后,在点击就变成了222
同时log里面会有这个提示
就证明这次补丁加载成功了
我的代码地址为
github
美团robust使用相关推荐
- Android 美团Robust热更新 使用入门
Android热更新方案Robust 相信很多人都认识了解过 热修复.热更新.热补丁(对于这个技术也没有特别标准的一种叫法,下面我统一叫热更新),之后的一年里,各种热更新方案如雨后春笋般出现,比较耳熟 ...
- 框架手写系列---javassist修改字节码方式,实现美团Robust热修复框架
本文用javassist方式,模拟美团Robust插件的前置处理:用插入代码的方式,针对apk中的每个方法都插入一段静态代码判断语句,用于控制是否启用热修复fix(也就是动态加载patch包到原apk ...
- 美团 Robust 热更异常 haven‘t insert code by Robust.Cannot patch this method, method.signature
最近在研究热更,接入美团热更Robust,在打热更包时报错部分如下: at org.gradle.internal.concurrent.ThreadFactoryImpl$ManagedThread ...
- Android 热修复总结
热修复总结 平台 阿里 AndFix 阿里 HotFix1.x Nuwa 微信Tinker 美团Robust 阿里 HotFix2.x 即时生效 yes yes no no yes 看情况 性能损耗 ...
- 深入解析阿里Android热修复技术原理
前言:本文框架 什么是热修复? 热修复框架分类 技术原理及特点 Tinker框架解析 各框架对比图 总结 通过阅读本文,你会对热修复技术有更深的认知,本文会列出各类框架的优缺点以及技术原理,文章末尾简 ...
- Android热修复技术原理详解(最新最全版本)
本文框架 什么是热修复? 热修复框架分类 技术原理及特点 Tinker框架解析 各框架对比图 总结 通过阅读本文,你会对热修复技术有更深的认知,本文会列出各类框架的优缺点以及技术原理,文章末尾简单 ...
- android高级篇收录
Android运行时性能优化 1.android启动优化 支付宝客户端架构解析:Android 客户端启动速度优化之「垃圾回收」 支付宝 App 构建优化解析:通过安装包重排布优化 Android 端 ...
- 插件修复数据_APP 热修复都懂了,你会 SDK 热修复吗?最全方案在这里!
前言 刚开始要做 SDK 热修复,我是拒绝的 ~ 某日,解决完一个线上 bug 后,我冒出了一个念头:让我们的 SDK 也具有热修复的能力呗! 但是查了查,网上资料少.很多热修复方案只针对app-- ...
- 介绍自己的一个Android插桩热修复框架项目QuickPatch
QuickPatch项目地址: https://gitee.com/egg90/QuickPatch 和 https://github.com/eggfly/QuickPatch 同步更新 类似于美团 ...
最新文章
- Hibernate实现limit查询报错 unexpected token: ? near line 1, column 30 [from cn.com.bean.Layer limit ? ,
- 超详细!各种内部排序算法的比较
- 靠谱推荐 | 我读完了所有数据产品经理的书?!
- python小技巧:获取字典中值最大者的key
- python 装饰器分类_Python 装饰器(Decorators) 超详细分类实例
- Tomcat启动Name or service not known错误解决
- java 在线支付_java如何实现在线支付讲解
- 错误录入 算法_如何使用验证错误率确定算法输出之间的关系
- 不经意传输(oblivious transfer)
- Apache从入门到精通
- ACE网络编程思考(二)
- phoenix hbase java_spark通过phoenix读写hbase(Java版)
- 互联网日报 | 6月13日 星期日 | 腾讯开展“饭圈乱象”专项整治;端午档单日放映场次刷新纪录;湖北取消除武汉外落户限制...
- 宝, 来学习一下CSS中的宽高比,让 h5 开发更想你的夜!
- 如何提供网络冗余和稳定连接
- 期货反向跟单—日内交易是否合适
- word选择性粘贴没有HTML选项,Word选择性粘贴如何使用?Word选择性粘贴的快捷键是什么?...
- 对偶(duality)的含义
- 392高校毕业设计选题
- Gocv图片合成视频(无音频)