Meituan-Dianping / Robust

Robust is an Android HotFix solution with high compatibility and high stability. Robust can fix bugs immediately without a reboot.
Apache License 2.0
4.42k stars 807 forks source link

onClick 事件中 switch case 中id 被修改 #371

Closed litao0621 closed 4 years ago

litao0621 commented 4 years ago

异常类型:热修复不生效 ,onclick 中 switch case 中id 在patch 中被修改

手机型号:vivo y83

手机系统版本:Android 8.1

Robust版本:0.4.91

Gradle版本:4.10.1

系统:Windows

我的原始伪代码类似这样

@Override
public void onClick(View v) {
    switch (v.getId()) {
        case R.id.toolbar_search: //此处ID为 231297935
        ToastUtils.showToast("toolbar serach");
        break;
        case R.id.toolbar_check:
        ToastUtils.showToast("toolbar check");
         break;
    }
}

修复后伪代码

@Modify
@Override
public void onClick(View v) {
    switch (v.getId()) {
        case R.id.toolbar_search: //此处ID为 231297935
        ToastUtils.showToast("hotfix success");  //此处做了修改
        break;
        case R.id.toolbar_check:
        ToastUtils.showToast("toolbar check");
         break;
    }
}

但反编译patch dex文件后发现 case R.id.toolbar_search ID发生了变化 对应case id 变为了231297900
而且这个ID转为16进制后,在项目中R文件也找不到对应的ID

帮忙分析下,谢谢

weiyixiong commented 4 years ago

因为这个项目不记录资源id。生成补丁相当于二次打包。id会发生变化。如果你要是想修改点击事件。在setOnClickListener(this)处改成以新增类方式的设置监听。因为robust不支持修改匿名对象的方法

litao0621 commented 4 years ago

多谢,明白了