tinker 修复失败

95 篇文章 0 订阅

在集成tinker遇到把生成的修复包放到SD修复失败的问题,百度看了很多资料都是直接加载SD卡路径的修复包,后看文档是建议放到Dir使用目录里面 SD卡目录里面容易被删除,

创建个类把SD卡的修复包复制到Dir文件夹里面;

public class FileUtils {
    /**
     * 复制文件
     * 把一个文件(sourceFile ) 拷贝到另一个文件里面(targetFile)
     * @param sourceFile 源文件
     * @param targetFile 目标文件
     * @throws IOException IO异常
     */
    public static void copyFile(File sourceFile, File targetFile)
            throws IOException {
        // 新建文件输入流并对它进行缓冲
        FileInputStream input = new FileInputStream(sourceFile);
        BufferedInputStream inBuff = new BufferedInputStream(input);

        // 新建文件输出流并对它进行缓冲
        FileOutputStream output = new FileOutputStream(targetFile);
        BufferedOutputStream outBuff = new BufferedOutputStream(output);

        // 缓冲数组
        byte[] b = new byte[1024 * 5];
        int len;
        while ((len = inBuff.read(b)) != -1) {
            outBuff.write(b, 0, len);
        }
        // 刷新此缓冲的输出流
        outBuff.flush();

        // 关闭流
        inBuff.close();
        outBuff.close();
        output.close();
        input.close();
    }
}

 

//使用

//加载补丁包
File sourcesFile = new File(Environment.getExternalStorageDirectory(), "patch_signed_7zip.apk");
File privateFile = new File(getDir("odex", Context.MODE_PRIVATE).getAbsolutePath() + File.separator + "patch_signed_7zip.apk");
//判断私有目录 是否存在 文件
if (privateFile.exists()) {
    privateFile.delete();//存在就删除文件
}

try {
    //使用封装的方法 把 sd卡里面的dex文件 复制到私有目录里面
    FileUtils.copyFile(sourcesFile, privateFile);
    Toast.makeText(this, "复制私有目录成功", Toast.LENGTH_SHORT).show();
    //修复dex文件
    TinkerInstaller.onReceiveUpgradePatch(getApplicationContext(), privateFile.getAbsolutePath());
} catch (IOException e) {
    e.printStackTrace();
}

//修复包没有放到Dir文件夹里面 就会修复失败,把修复包放到Dir就ok

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 4
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 4
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值