Android AndFix初体验
2016-11-14 18:27
260 查看
AndFix是阿里开源的一个热修复框架
github地址:https://github.com/alibaba/AndFix
如何使用:
1.依赖AndFix
compile 'com.alipay.euler:andfix:0.5.0@aar'
2.在项目的application类里面初始化:
@Override
public void onCreate() {
super.onCreate();
initLib();
}
private void initLib() {
initOkHttpUtils();
initAndFix();
}
/**
* 初始化andfix
*/
private void initAndFix() {
// 初始化patch管理类
mPatchManager = new PatchManager(this);
// 初始化patch版本
mPatchManager.init("1.0");
// 加载已经添加到PatchManager中的patch
mPatchManager.loadPatch();
}
3.旧版本和新版本比较 得到补丁文件
用到的软件为apkpatch,下载地址:https://raw.githubusercontent.com/alibaba/AndFix/master/tools/apkpatch-1.0.3.zip
4.把补丁文件放到服务器.前端进行下载.并修复
/**
* 下载补丁
*
* @param url 补丁路径
* @param filePath 补丁存放路径
* @param fileName 补丁名字
*/
private void downloadPatch(String url, String filePath, String fileName) {
OkHttpUtils//
.get()//
.url(url)//
.build()//
.execute(new FileCallBack(filePath, fileName)//
{
@Override
public void onError(Call call, Exception e, int id) {
Toast.makeText(getApplicationContext(), "补丁下载出错", Toast.LENGTH_SHORT).show();
}
@Override
public void onResponse(File response, int id) {
Toast.makeText(getApplicationContext(), "补丁下载成功,安装ing", Toast.LENGTH_SHORT).show();
if (null != response && response.exists()) {
try {
MyApp.getmPatchManager().addPatch(response.getAbsolutePath());
Toast.makeText(getApplicationContext(), "补丁安装成功", Toast.LENGTH_SHORT).show();
} catch (IOException e) {
e.printStackTrace();
Toast.makeText(getApplicationContext(), "补丁安装失败", Toast.LENGTH_SHORT).show();
}
}
}
});
}完整代码地址:
https://github.com/imgod1/TestAndFix
注意点:
1.不要用run得到的old.apk以及new.apk(instant run在这里就是个坑)
2.在主线程进行addpatch
github地址:https://github.com/alibaba/AndFix
如何使用:
1.依赖AndFix
compile 'com.alipay.euler:andfix:0.5.0@aar'
2.在项目的application类里面初始化:
@Override
public void onCreate() {
super.onCreate();
initLib();
}
private void initLib() {
initOkHttpUtils();
initAndFix();
}
/**
* 初始化andfix
*/
private void initAndFix() {
// 初始化patch管理类
mPatchManager = new PatchManager(this);
// 初始化patch版本
mPatchManager.init("1.0");
// 加载已经添加到PatchManager中的patch
mPatchManager.loadPatch();
}
3.旧版本和新版本比较 得到补丁文件
用到的软件为apkpatch,下载地址:https://raw.githubusercontent.com/alibaba/AndFix/master/tools/apkpatch-1.0.3.zip
4.把补丁文件放到服务器.前端进行下载.并修复
/**
* 下载补丁
*
* @param url 补丁路径
* @param filePath 补丁存放路径
* @param fileName 补丁名字
*/
private void downloadPatch(String url, String filePath, String fileName) {
OkHttpUtils//
.get()//
.url(url)//
.build()//
.execute(new FileCallBack(filePath, fileName)//
{
@Override
public void onError(Call call, Exception e, int id) {
Toast.makeText(getApplicationContext(), "补丁下载出错", Toast.LENGTH_SHORT).show();
}
@Override
public void onResponse(File response, int id) {
Toast.makeText(getApplicationContext(), "补丁下载成功,安装ing", Toast.LENGTH_SHORT).show();
if (null != response && response.exists()) {
try {
MyApp.getmPatchManager().addPatch(response.getAbsolutePath());
Toast.makeText(getApplicationContext(), "补丁安装成功", Toast.LENGTH_SHORT).show();
} catch (IOException e) {
e.printStackTrace();
Toast.makeText(getApplicationContext(), "补丁安装失败", Toast.LENGTH_SHORT).show();
}
}
}
});
}完整代码地址:
https://github.com/imgod1/TestAndFix
注意点:
1.不要用run得到的old.apk以及new.apk(instant run在这里就是个坑)
2.在主线程进行addpatch
相关文章推荐
- 体验Android
- Android源码各个击破之-系统属性
- Study on Android【一】--概述
- 机器人Android在呼唤!
- Google Android IDE-eclipse plugin 预览
- 为什么是java,google的android策略
- Android Developer Challenge
- Google Calling: Inside Android, the gPhone SDK
- Android程序开发初级教程(三)
- Android程序开发初级教程(二)
- 什么是google的Android操作系统?
- Google手机操作系统Android应用开发入门
- Android程序开发初级教程(一)
- Android 入门开发指南之一 -- Android简介
- Android 原代码下载路径
- 体验Android:个人所得税计算器 含源码
- Android判断字符串中是否含字母、中文或数字
- 体验Android
- Google 1000万美元重奖Android开发者
- Android安装以及Eclipse插件(Google Android) ,在Android 中google搜索 博客园界面