第一个想法是直接把热更资源在前端下下来,然后用jszip解压,但是解压的时候会异常的卡顿,所以想把这部分操作,搞到原生那边做, // 1. 解压前检查并删除已存在的 savePath
// 转换路径为 File 对象
File storageFile = new File(storagePath);
File saveDir = new File(savePath);
// 1. 检查 ZIP 文件是否存在且可读
if (!storageFile.exists() || !storageFile.canRead()) {
reportError(callbackId, "ZIP 文件不存在或不可读: " + storageFile.getAbsolutePath());
return;
}else{
long fileSizeBytes = storageFile.length();
String humanReadableSize = formatFileSize(fileSizeBytes); // 转换为易读格式(如 1.23MB)
Log.d(TAG, "ZIP 文件存在,大小: " + fileSizeBytes + " 字节 (" + humanReadableSize + ")");
}
// 2. 校验 ZIP 完整性
try {
ZipFile zipCheck = new ZipFile(storagePath);
if (!zipCheck.isValidZipFile()) {
reportError(callbackId, "ZIP 文件损坏");
return;
}
} catch (Exception e) {
reportError(callbackId, "校验 ZIP 文件失败: " + e.getMessage());
return;
}
// 2. 清理或创建目标目录
if (saveDir.exists()) {
deleteDirectoryRecursive(saveDir);
}
if (!saveDir.mkdirs() || !saveDir.canWrite()) {
reportError(callbackId, "无法创建目标目录: " + saveDir.getAbsolutePath());
return;
}走是走下来了,但是只要执行解压操作,就反馈说, (No such file or directory),看看论坛有大佬碰到过这种问题么