阿里官方开源项目及文档:AndFix
集成流程
1.添加依赖
dependencies {
compile 'com.alipay.euler:andfix:0.5.0@aar'
}
2.初始化
// 初始化patch管理类
mPatchManager = new PatchManager(context);
// 初始化patch版本
mPatchManager.init("1.0");
// 加载已经添加到PatchManager中的patch
mPatchManager.loadPatch();
3.添加补丁
public static void hotFix(String path){
//添加patch,只需指定patch的路径即可,补丁会立即生效
try {
mPatchManager.addPatch(path);
} catch (IOException e) {
e.printStackTrace();
Log.e("hotFix", "hotFix: "+e.getMessage() );
}
}
4.清除补丁
public static void clear(){
//删除所有已加载的patch文件
mPatchManager.removeAllPatch();
}
5.功能测试
public class Utils {
public void test(Context context){
Toast.makeText(context, "有BUG", Toast.LENGTH_SHORT).show();
// Toast.makeText(context, "已修复", Toast.LENGTH_SHORT).show();
}
}
case R.id.test:
new Utils().test(this);
break;
case R.id.hotfix:
File file = new File(Environment.
getExternalStoragePublicDirectory(Environment.DIRECTORY_DOWNLOADS) + "/new.apatch");
if(file.exists()){
MainApplication.hotFix(file.getAbsolutePath());
KLog.e(file.getAbsolutePath());
}
else
Toast.makeText(this, "无补丁文件", Toast.LENGTH_SHORT).show();
break;
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE"/>