关于热更新的学习记录
来源:互联网 发布:win7 445端口入侵教程 编辑:程序博客网 时间:2024/05/21 11:06
关于AndFix的实现原理。
1. 创建无bug的dex。
2. 放入到工程中。
3. 通过java代码把dex存放到安装目录的文件夹下。
4. 加载dex。
5. 通过jni层进行方法替换。
java层关键代码:
DexFile dexFile1 = DexFile.loadDex(dexFile.getAbsolutePath(),okDexFile.getAbsolutePath(),Context.MODE_PRIVATE);// load dex
Enumeration<String> entries = dexFile1.entries();// 对load的类进行遍历。 while ( entries.hasMoreElements()){// 遍历类 String key = entries.nextElement(); Class<?> okClass = dexFile1.loadClass(key,getClass().getClassLoader());// 获取类 if(okClass ==null ){ continue; } findBugMethod(okClass); }
private void findBugMethod(Class<?> okClass){ // 获取该类中的所有方法。 Method[] methods = okClass.getDeclaredMethods(); for(Method method:methods){ // 获取注解。已经指明注解类型。 MethodReplace methodReplace = method.getAnnotation(MethodReplace.class); if(methodReplace == null){ continue; } // 将要修复的错误类和错误方法 String bugClassName = methodReplace.className(); String bugMethodName = methodReplace.methodName(); // 获取Bug Method 实例.也就是该方法的标识。不一定是实例参数. // 该方法在内存卡的映射地址 try { Method bugMethod = Class.forName(bugClassName).getDeclaredMethod(bugMethodName,method.getParameterTypes()); if(bugMethod != null){ replaceArt(bugMethod,method); } } catch (NoSuchMethodException e) { e.printStackTrace(); } catch (ClassNotFoundException e) { e.printStackTrace(); } } }
C层实现。进行方法替换。
ArtMethod* smeth = (ArtMethod*)env->FromReflectedMethod(jobject2); ArtMethod* dmeth = (ArtMethod*)env->FromReflectedMethod(jobject3); smeth->declaring_class_=dmeth->declaring_class_; smeth->dex_cache_resolved_types_=dmeth->dex_cache_resolved_types_; smeth->access_flags_=dmeth->access_flags_; smeth->dex_cache_resolved_methods_=dmeth->dex_cache_resolved_methods_; smeth->dex_code_item_offset_=dmeth->dex_code_item_offset_; smeth->method_index_=dmeth->method_index_; smeth->dex_method_index_=dmeth->dex_method_index_; smeth->ptr_sized_fields_.entry_point_from_interpreter_=dmeth->ptr_sized_fields_.entry_point_from_interpreter_; smeth->ptr_sized_fields_.entry_point_from_jni_=dmeth->ptr_sized_fields_.entry_point_from_jni_; smeth->ptr_sized_fields_.entry_point_from_quick_compiled_code_=dmeth->ptr_sized_fields_.entry_point_from_quick_compiled_code_;
注意点:
1. 需要错误类已经有实例。也就是已经实例化。静态的未尝试。
0 0
- 关于热更新的学习记录
- Android 热更新学习记录
- 关于热更新的东西
- reactnative 热更新记录
- cocos2d-x 关于热更新的文章
- 关于andfix热更新的配置
- 关于热更新的一些分享
- 关于erlang热更新
- 关于U3D热更新
- Android热更新原理记录
- 热更新JSPatch学习:
- 关于动态加载机制的热更新的小结
- 关于AssetBundle、热更新、BestHttp
- 关于JSPatch 热更新配置
- 关于lua语言及热更新的研究一
- JSPatch技术文档(关于ios的热更新)
- 关于VUE-CLI脚手架热更新不起效的原因
- 关于Bugly热更新sdk使用的一些小细节
- 如何让webview显示中文不乱码
- 移动端H5开发遇到问题及解决办法总结
- Python入门:条件控制
- 鬼斧神工-正则表达式☞实战应用
- typedef复习
- 关于热更新的学习记录
- 基于注解的SpringMVC开发
- 打开图库的第二种意图
- 《Android源码设计模式解析与实战》读书笔记(五)——工厂方法模式
- 杭电2149 Public Sale 巴什博弈
- 用java如何解析(任意)一句话中的词
- org.testng.TestNGException: Cannot find class in classpath
- lintcode/leetcode由易至难第3题:选择排序
- 信号与命名管道