Android 热修复框架RocooFix

    xiaoxiao2021-03-25  43

    官方链接:https://github.com/dodola/RocooFix

    开发bug汇总链接:https://github.com/shoyu666/derocoodemo

    RocooFix

    支持两种模式: 静态修复某种情况下需要重启应用。动态修复,无需重启应用即可生效。新增so修复,beta中 支持DalvikVM和ART VM制作补丁更加方便支持com.android.tools.build:gradle:1.3.0->com.android.tools.build:gradle:2.1.2 (解决了Nuwa 这个issue)支持混淆和Mulitdex无需关注hash.txt和mapping.txt文件的生成和保存

    使用方法:

    public class RocooApplication extends Application { @Override protected void attachBaseContext(Context base) { super.attachBaseContext(base); //初始化 RocooFix.init(this); } } //方案1:静态启用,一般在Application里加载补丁 /** * 从Assets里取出补丁,一般用于测试 * * @param context * @param assetName */ RocooFix.initPathFromAssets(Context context, String assetName); /** * 从指定目录加载补丁 * @param context * @param dexPath */ RocooFix.applyPatch(Context context, String dexPath); //方案2:动态打补丁,立即生效,有性能问题,适用于补丁方法数较少的情况,建议在ART虚拟机里启用该模式 /** * 从Asset里加载补丁,一般用于本地测试 * @param context * @param assetName */ RocooFix.initPathFromAssetsRuntime(Context context, String assetName) ; /** * 从指定目录加载补丁 * @param context * @param dexPath */ RocooFix.applyPatchRuntime(Context context, String dexPath) ; /** * * new Feature beta 中 * 从指定目录加载so补丁,使用so还需调用System.loadLibrary("xx") * @param context * @param soDirPath so补丁路径(这里是dir) */ RocooSoFix.applyPatch(Context context, String soDirPath);

    android studio配置:

    在root的build.gradle增加如下内容:

    // Top-level build file where you can add configuration options common to all sub-projects/modules. buildscript { repositories { jcenter() } dependencies { classpath 'com.android.tools.build:gradle:2.1.2' classpath 'com.dodola:rocoofix:1.2.2' // NOTE: Do not place your application dependencies here; they belong // in the individual module build.gradle files } } allprojects { repositories { jcenter() } } task clean(type: Delete) { delete rootProject.buildDir }

    在你项目的build.gradle文件里添加如下配置

    apply plugin: 'com.android.application' apply plugin: 'com.dodola.rocoofix' repositories { jcenter() } android { compileSdkVersion 22 buildToolsVersion "22.0.1" dexOptions { javaMaxHeapSize "4g" } defaultConfig { applicationId "com.demo.test" minSdkVersion 15 targetSdkVersion 22 versionCode 3 versionName "1.2.0" multiDexEnabled true } compileOptions { sourceCompatibility JavaVersion.VERSION_1_7 targetCompatibility JavaVersion.VERSION_1_7 } buildTypes { release { minifyEnabled true proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro' } debug { minifyEnabled true proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro' } } } /** * * preVersionPath = '1'//注意:此项属性只在需要制作补丁的时候才需开启!!如果不需要制作补丁则需要去掉此项 **/ rocoo_fix { // includePackage = ['com/cidtech/acrowd']//指定将来可能需要制作补丁的package(就是指定插庄的范围) // excludeClass = ['BaseApplication.class']//将不需要加到patch里的类写在这里(不需要插庄的类) preVersionPath = '1' enable = true//注意:关掉此项会无法生成Hash.txt文件 // scanref=true//默认为 false,开启这个选项会将与补丁 class 相引用的 class 都打入包中来解决 ART 虚拟机崩溃问题,功能 Beta 中 } dependencies { compile fileTree(include: ['*.jar'], dir: 'libs') compile 'com.dodola:rocoo:1.1' }

    这里主要介绍一下preVersionPath这个属性的作用。

    rocoo_fix将制作补丁的步骤透明化,用户无需手动备份hash.txt文件,插件会自动根据当前的versionCode生成hash.txt和mapping.txt文件到指定目录,比如:

    注意:上一个版本发布的时候版本号是1,那么生成的文件会放在app源码目录/rocooFix/version1/[debug]|[release]的目录下,如果需要制作补丁那么在配置里指定preVersionPath 属性,它的值是上一个版本的版本号,这里的值是1

    然后将build.gradle的versionCode的号码修改,这里修改成2,只要和之前的版本不同就可以,没有具体值的要求

    生成操作流程:

    转载请注明原文地址: https://ju.6miu.com/read-50167.html

    最新回复(0)