热更新完成后重启游戏,加载的还是旧的资源,求解.

现在的问题是 热更新完成自动重启游戏 不再提示更新资源 ,但是资源还是加载的旧的。修改版本号后重新发布服务器的 remote-assets ,会再次提示更新,更新完成后重启游戏 还是加载的旧的资源。求大神能给看看出啥毛病了。
ccc 版本是 1.4.2;

特别感谢一下QQ群: ccc游戏开发实战 中 @旧城凉 大神的耐心支援。我也知道肯定是我哪没搞对,但就是不知道哪没搞对。懵了。

附上我的的操作步骤,大家看看是不是有毛病:
生成基础包:
1 生成 manifest
node version_generator.js -v 1.5.11 -u http://192.168.1.3/remote-assets/ -s build/jsb-default/ -d assets/
2 构建
3 修改 build\jsb-default 目录下的 main.js
4 编译
5 用android studio 打包(直接用ccc生成的包也是同样的问题)

生成更新包:
先修改一下UI的内容 我是修改了lable的文字。
1 构建
2 修改main.js
3 编译
4 生成 manifest
修改版本号
执行 node version_generator.js -v 1.5.12 -u http://192.168.1.3/remote-assets/ -s build/jsb-default/ -d assets/

5 复制assets 中 新生成的 project.manifest 和 version.manifest 到 remote-assets 下

6 复制 \build\jsb-default 下的 res 和 src 文件夹到 remote-assets 下

其中 在main.js中添加的代码是:
if (cc.sys.isNative) {
var hotUpdateSearchPaths = cc.sys.localStorage.getItem(‘HotUpdateSearchPaths’);
console.log("================1cc.sys.localStorage.getItemHotUpdateSearchPaths:"+hotUpdateSearchPaths);
if (hotUpdateSearchPaths) {
console.log("================2jsb.fileUtils.setSearchPaths(JSON.parse(hotUpdateSearchPaths)):"+JSON.parse(hotUpdateSearchPaths));
jsb.fileUtils.setSearchPaths(JSON.parse(hotUpdateSearchPaths));
}
}
用 android studio 调试 控制台也会输出

05-17 16:13:27.495 7673-7708/com.papaqipai.chesspre D/cocos2d-x debug info: ================1cc.sys.localStorage.getItem HotUpdateSearchPaths:["assets/res/raw-assets/","/data/data/com.papaqipai.chesspre/files/papaqipai-asset/","assets/res/raw-assets/","assets/"]
05-17 16:13:27.495 7673-7708/com.papaqipai.chesspre D/cocos2d-x debug info: ================2jsb.fileUtils.setSearchPaths(JSON.parse(hotUpdateSearchPaths)):assets/res/raw-assets/,/data/data/com.papaqipai.chesspre/files/papaqipai-asset/,assets/res/raw-assets/,assets/
05-17 16:14:35.525 9582-9615/com.papaqipai.chesspre D/cocos2d-x debug info: ================1cc.sys.localStorage.getItem HotUpdateSearchPaths:["assets/res/raw-assets/","/data/data/com.papaqipai.chesspre/files/papaqipai-asset/","assets/res/raw-assets/","assets/"]
05-17 16:14:35.525 9582-9615/com.papaqipai.chesspre D/cocos2d-x debug info: ================2jsb.fileUtils.setSearchPaths(JSON.parse(hotUpdateSearchPaths)):assets/res/raw-assets/,/data/data/com.papaqipai.chesspre/files/papaqipai-asset/,assets/res/raw-assets/,assets/

所以应该不是这个环节出问题了。

再附上hotupdate代码:

cc.Class({
    extends: cc.Component,

    properties: {
        updatePanel: {
            default: null,
            type: cc.Node
        },
        manifestUrl: {
            default: null,
            url: cc.RawAsset
        },
        percent: {
            default: null,
            type: cc.Label
        },
         percentBar: {
            default: null,
            type: cc.Node,
        },
        lblErr: {
            default: null,
            type: cc.Label
        }
    },

    checkCb: function (event) {
        cc.log('Code: ' + event.getEventCode());
        switch (event.getEventCode())
        {
            case jsb.EventAssetsManager.ERROR_NO_LOCAL_MANIFEST:
                cc.log("No local manifest file found, hot update skipped.");
                cc.eventManager.removeListener(this._checkListener);
                break;
            case jsb.EventAssetsManager.ERROR_DOWNLOAD_MANIFEST:
            case jsb.EventAssetsManager.ERROR_PARSE_MANIFEST:
                cc.log("Fail to download manifest file, hot update skipped.");
                cc.eventManager.removeListener(this._checkListener);
                break;
            case jsb.EventAssetsManager.ALREADY_UP_TO_DATE:
                cc.log("Already up to date with the latest remote version.");
                cc.eventManager.removeListener(this._checkListener);
                this.lblErr.string += "游戏不需要更新\n";
                    this.percentBar.width=430;
                window.updateOK = true;
              //  cc.director.loadScene("loading");
                break;
            case jsb.EventAssetsManager.NEW_VERSION_FOUND:
                this._needUpdate = true;
                this.updatePanel.active = true;
                this.percent.string = '00.00%';
            
                cc.eventManager.removeListener(this._checkListener);
                break;
            default:
                break;
        }
        this.hotUpdate();
    },

    updateCb: function (event) {
        var needRestart = false;
        var failed = false;
        switch (event.getEventCode())
        {
            case jsb.EventAssetsManager.ERROR_NO_LOCAL_MANIFEST:
                cc.log('No local manifest file found, hot update skipped.');
                console.log("=============No local manifest file found, hot update skipped." );
                failed = true;
                break;
            case jsb.EventAssetsManager.UPDATE_PROGRESSION:
                var percent = event.getPercent();
                var percentByFile = event.getPercentByFile();

                var msg = event.getMessage();
                if (msg) {
                    cc.log(msg);
                }
                cc.log(percent.toFixed(2) + '%');
                this.percent.string = percent + '%';
                    this.percentBar.width=430*percent.toFixed(2)/100;
                break;
            case jsb.EventAssetsManager.ERROR_DOWNLOAD_MANIFEST:
            case jsb.EventAssetsManager.ERROR_PARSE_MANIFEST:
                cc.log('Fail to download manifest file, hot update skipped.');
                console.log("=============Fail to download manifest file, hot update skipped." );
                failed = true;
                break;
            case jsb.EventAssetsManager.ALREADY_UP_TO_DATE:
                cc.log('Already up to date with the latest remote version.');
                      console.log("=============Already up to date with the latest remote version." );
                failed = true;
                break;
            case jsb.EventAssetsManager.UPDATE_FINISHED:
                cc.log('Update finished. ' + event.getMessage());
        console.log("=============Update finished."+ event.getMessage() );
                needRestart = true;
                break;
            case jsb.EventAssetsManager.UPDATE_FAILED:
                cc.log('Update failed. ' + event.getMessage());
                console.log("=============Update failed."+ event.getMessage() );
         
                this._failCount ++;
                if (this._failCount < 5)
                {
                    this._am.downloadFailedAssets();
                }
                else
                {
                    cc.log('Reach maximum fail count, exit update process');
                    console.log("=============Reach maximum fail count, exit update process." );
                    this._failCount = 0;
                    failed = true;
                }
                break;
            case jsb.EventAssetsManager.ERROR_UPDATING:
            console.log('=============Asset update error: ' + event.getAssetId() + ', ' + event.getMessage());
                break;
            case jsb.EventAssetsManager.ERROR_DECOMPRESS:
                cc.log(event.getMessage());
                break;
            default:
                break;
        }

        if (failed) {
            cc.eventManager.removeListener(this._updateListener);
            this.updatePanel.active = false;
        }

        if (needRestart) {
            cc.eventManager.removeListener(this._updateListener);
            // Prepend the manifest's search path
            var searchPaths = jsb.fileUtils.getSearchPaths();
            console.log("=====needRestart_searchPaths:"+searchPaths);
            var newPaths = this._am.getLocalManifest().getSearchPaths();
                 console.log("=====newPaths:"+JSON.stringify(newPaths));
            Array.prototype.unshift(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.
            cc.sys.localStorage.setItem('HotUpdateSearchPaths', JSON.stringify(searchPaths));

            jsb.fileUtils.setSearchPaths(searchPaths);
            this.lblErr.string += "游戏资源更新完毕\n";
            cc.game.restart();
        }
    },

    hotUpdate: function () {
        if (this._am && this._needUpdate) {
            this.lblErr.string += "开始更新游戏资源...\n";
            this._updateListener = new jsb.EventListenerAssetsManager(this._am, this.updateCb.bind(this));
            cc.eventManager.addListener(this._updateListener, 1);

            this._failCount = 0;
            this._am.update();
        }
    },

    // use this for initialization
    onLoad: function () {
        // Hot update is only available in Native build
           cc.log("加载Update");
        if (!cc.sys.isNative) {
            window.updateOK = true;
            return;
        }
        this.lblErr.string += "检查游戏资源...\n";
        var storagePath = ((jsb.fileUtils ? jsb.fileUtils.getWritablePath() : '/') + 'papaqipai-asset');
        cc.log('Storage path for remote asset : ' + storagePath);
        this.lblErr.string += storagePath + "\n";
        cc.log('Local manifest URL : ' + this.manifestUrl);
        this._am = new jsb.AssetsManager(this.manifestUrl, storagePath);
        this._am.retain();

        this._needUpdate = false;
        if (this._am.getLocalManifest().isLoaded())
        {
            this._checkListener = new jsb.EventListenerAssetsManager(this._am, this.checkCb.bind(this));
            cc.eventManager.addListener(this._checkListener, 1);

            this._am.checkUpdate();
        }
    },

    onDestroy: function () {
        this._am && this._am.release();
    }
});

一眼看不到问题,这是我之前写的3.15的热更,你可以参考下
http://forum.cocos.com/t/cocos3-15/46211

这里是附了完整的代码 和 工具 包括 工具所有的模块包
ps:生成之后的manifest文件 最好还是自己检查下,看下是否有问题
附mainifest文件一只
project.zip (49.1 KB)

1赞

我跟你操作是一样的,最后也是 加载的旧的资源,你是怎么解决的?

我的是没有在main.js加这段代码,加了就好了
if (cc.sys.isNative) {
var hotUpdateSearchPaths = cc.sys.localStorage.getItem(‘HotUpdateSearchPaths’);
if (hotUpdateSearchPaths) {
jsb.fileUtils.setSearchPaths(JSON.parse(hotUpdateSearchPaths));
}
}