creator 2.4.9热更下载成功重启后使用的还是旧资源

已经设置了搜索路径
this._am.setEventCallback(null!);
this._updateListener = null;
// Prepend the manifest’s search path
var searchPaths = jsb.fileUtils.getSearchPaths();
var newPaths = this._am.getLocalManifest().getSearchPaths();
console.log(JSON.stringify(newPaths));
Array.prototype.unshift.apply(searchPaths, newPaths);
// This value will be retrieved and appended to the default search path during game startup,
// please refer to samples/js-tests/main.js for detailed usage.
// !!! Re-add the search paths in main.js is very important, otherwise, new scripts won’t take effect.
localStorage.setItem(‘HotUpdateSearchPaths’, JSON.stringify(searchPaths));
jsb.fileUtils.setSearchPaths(searchPaths);

main.js:
window.boot = function () {
var settings = window._CCSettings;
window._CCSettings = undefined;
var onProgress = null;
var RESOURCES = cc.AssetManager.BuiltinBundleName.RESOURCES;
var INTERNAL = cc.AssetManager.BuiltinBundleName.INTERNAL;
var MAIN = cc.AssetManager.BuiltinBundleName.MAIN;
function setLoadingDisplay () {
// Loading splash scene
var splash = document.getElementById(‘splash’);
var progressBar = splash.querySelector(’.progress-bar span’);
onProgress = function (finish, total) {
var percent = 100 * finish / total;
if (progressBar) {
progressBar.style.width = percent.toFixed(2) + ‘'; } }; splash.style.display = 'block'; progressBar.style.width = '0’;
cc.director.once(cc.Director.EVENT_AFTER_SCENE_LAUNCH, function () {
splash.style.display = ‘none’;
});
}
var onStart = function () {
cc.view.enableRetina(true);
cc.view.resizeWithBrowserSize(true);
if (cc.sys.isBrowser) {
setLoadingDisplay();
}
if (cc.sys.isMobile) {
if (settings.orientation === ‘landscape’) {
cc.view.setOrientation(cc.macro.ORIENTATION_LANDSCAPE);
}
else if (settings.orientation === ‘portrait’) {
cc.view.setOrientation(cc.macro.ORIENTATION_PORTRAIT);
}
cc.view.enableAutoFullScreen([
cc.sys.BROWSER_TYPE_BAIDU,
cc.sys.BROWSER_TYPE_BAIDU_APP,
cc.sys.BROWSER_TYPE_WECHAT,
cc.sys.BROWSER_TYPE_MOBILE_QQ,
cc.sys.BROWSER_TYPE_MIUI,
cc.sys.BROWSER_TYPE_HUAWEI,
cc.sys.BROWSER_TYPE_UC,
].indexOf(cc.sys.browserType) < 0);
}
// Limit downloading max concurrent task to 2,
// more tasks simultaneously may cause performance draw back on some android system / browsers.
// You can adjust the number based on your own test result, you have to set it before any loading process to take effect.
if (cc.sys.isBrowser && cc.sys.os === cc.sys.OS_ANDROID) {
cc.assetManager.downloader.maxConcurrency = 2;
cc.assetManager.downloader.maxRequestsPerFrame = 2;
}
var launchScene = settings.launchScene;
var bundle = cc.assetManager.bundles.find(function (b) {
return b.getSceneInfo(launchScene);
});
bundle.loadScene(launchScene, null, onProgress,
function (err, scene) {
if (!err) {
cc.director.runSceneImmediate(scene);
if (cc.sys.isBrowser) {
// show canvas
var canvas = document.getElementById(‘GameCanvas’);
canvas.style.visibility = ‘’;
var div = document.getElementById(‘GameDiv’);
if (div) {
div.style.backgroundImage = ‘’;
}
console.log('Success to load scene: ’ + launchScene);
}
}
}
);
};
var option = {
id: ‘GameCanvas’,
debugMode: settings.debug ? cc.debug.DebugMode.INFO : cc.debug.DebugMode.ERROR,
showFPS: settings.debug,
frameRate: 60,
groupList: settings.groupList,
collisionMatrix: settings.collisionMatrix,
};
cc.assetManager.init({
bundleVers: settings.bundleVers,
remoteBundles: settings.remoteBundles,
server: settings.server
});
var bundleRoot = [INTERNAL];
settings.hasResourcesBundle && bundleRoot.push(RESOURCES);
var count = 0;
function cb (err) {
if (err) return console.error(err.message, err.stack);
count++;
if (count === bundleRoot.length + 1) {
cc.assetManager.loadBundle(MAIN, function (err) {
if (!err) cc.game.run(option, onStart);
});
}
}
cc.assetManager.loadScript(settings.jsList.map(function (x) { return ‘src/’ + x;}), cb);
for (var i = 0; i < bundleRoot.length; i++) {
cc.assetManager.loadBundle(bundleRoot[i], cb);
}
};
if (window.jsb) {
let hotUpdateVersion = ‘27759576’
let _hotUpdateVersion = localStorage.getItem(‘kHotUpdateVersion’);
if (!_hotUpdateVersion || parseInt(_hotUpdateVersion) < parseInt(hotUpdateVersion)) {
var hotUpdateSearchPaths = localStorage.getItem(‘HotUpdateSearchPaths’);
if (hotUpdateSearchPaths) {
JSON.parse(hotUpdateSearchPaths).forEach(path => {
console.log(‘删除资源路径:’,path)
jsb.fileUtils.removeDirectory(path);
});
}
localStorage.removeItem(‘HotUpdateSearchPaths’);
localStorage.setItem(‘kHotUpdateVersion’, hotUpdateVersion);
}
var hotUpdateSearchPaths = localStorage.getItem(‘HotUpdateSearchPaths’);
if (hotUpdateSearchPaths) {
console.log(‘设置资源路径:’,JSON.parse(hotUpdateSearchPaths))
jsb.fileUtils.setSearchPaths(JSON.parse(hotUpdateSearchPaths));
}
var isRuntime = (typeof loadRuntime === ‘function’);
if (isRuntime) {
require(‘src/settings.js’);
require(‘src/cocos2d-runtime.js’);
if (CC_PHYSICS_BUILTIN || CC_PHYSICS_CANNON) {
require(‘src/physics.js’);
}
require(‘jsb-adapter/engine/index.js’);
}
else {
require(‘src/settings.js’);
require(‘src/cocos2d-jsb.js’);
if (CC_PHYSICS_BUILTIN || CC_PHYSICS_CANNON) {
require(‘src/physics.js’);
}
require(‘jsb-adapter/jsb-engine.js’);
}
cc.macro.CLEANUP_IMAGE_CACHE = true;
window.boot();
}

cocos官方的写法也试过 放在main.js的第一行重启后也是旧资源
禁用md5cache、使用了加密脚本密钥和zip压缩

LOG:
10-12 20:05:13.042 1068 1193 D jswrapper: JS: 当前进度: 1 当前字节数: 1
10-12 20:05:13.042 1068 1193 D jswrapper: JS: 1380 / 1380
10-12 20:05:13.042 1068 1193 D jswrapper: JS: 137987751 / 137987752
10-12 20:05:13.042 1068 1193 D jswrapper: JS: updateCb:=> 6
10-12 20:05:13.163 1068 1193 D jswrapper: JS: updateCb:=> 8
10-12 20:05:13.164 1068 1193 D jswrapper: JS: Update finished.
10-12 20:05:13.164 1068 1193 D jswrapper: JS: ["/data/user/0/com.arithmet.hero/files/remote-asset/"]
10-12 20:05:14.306 1068 1193 D jswrapper: JS: LoadScene LoginScene: 85.9210000000021ms
10-12 20:05:14.410 1068 1193 D jswrapper: JS: 重启游戏
10-12 20:05:14.494 1068 1193 D jswrapper: JS: Enable batch GL commands optimization!
10-12 20:05:14.496 1068 1193 D jswrapper: JS: 设置资源路径: /data/user/0/com.arithmet.hero/files/remote-asset/,/data/user/0/com.arithmet.hero/files/remote-asset/,@assets/assets/resources/native/a4/,@assets/
10-12 20:05:14.917 1068 1193 D jswrapper: JS: Cocos Creator v2.4.9
10-12 20:05:14.944 1068 1193 D jswrapper: JS: 初始化
10-12 20:05:14.944 1068 1193 D jswrapper: JS: Storage path for remote asset : /data/user/0/com.arithmet.hero/files/remote-asset/
10-12 20:05:14.945 1068 1193 D jswrapper: JS: Hot update is ready, please check or directly update.

求解惑!!!

你这好像木有创建目录。

谢谢啊,不是这里的问题已经找到病因了。

我也出现这样的问题了 什么原因导致的

我踩过这个坑,main.js的问题

能否具体说说 搞二天了 各种调式 发现文件和SearchPaths都是对的

要有这个代码,localStorage.getItem参数要跟热更脚本localStorage.setItem里边的一致

有设置HotUpdateSearchPaths的 不过我的是2.4.0跟你的代码有点不一样

我的是普通热更可以的,压缩成zip后不行。

我也是2.4.9
我的是第一次装APK的时候会热更
之后再有热更资源的时候,偶尔会不热更 :joy:
楼主你遇到的是什么问题 ,怎么解决的呢?

老铁找到原因了也说下是哪里的坑呗

直接上一段代码吧

let readSearchFunc = function () {

let hotUpdateVersion = '1.0.1'

let _hotUpdateVersion = localStorage.getItem('kHotUpdateVersion');

if (!_hotUpdateVersion || parseInt(_hotUpdateVersion) < parseInt(hotUpdateVersion)) {

    var hotUpdateSearchPaths = localStorage.getItem('HotUpdateSearchPaths');

    if (hotUpdateSearchPaths) {

        JSON.parse(hotUpdateSearchPaths).forEach(path => {

            console.log(path)

            jsb.fileUtils.removeDirectory(path);

        });

    }

    localStorage.removeItem('HotUpdateSearchPaths');

    localStorage.setItem('kHotUpdateVersion', hotUpdateVersion);

}

var hotUpdateSearchPaths = localStorage.getItem('HotUpdateSearchPaths');

if (hotUpdateSearchPaths) {

    jsb.fileUtils.setSearchPaths(JSON.parse(hotUpdateSearchPaths));

}

};

cc.macro.CLEANUP_IMAGE_CACHE = true;

readSearchFunc();   //一定要在这个位置调用

window.boot();

支持zip但不支持md5

来挖坟了,我发现这个热更在第一次触发的时候很慢 哪怕两个版本很相近 或者卸载包重新安装的包后的第一次热更也是很慢