1.7 热更问题

代码基本是复制粘贴的,只是把手动点击 改 自己动检测下载

cc.log(“资源更热完成—重启游戏”);
cc.game.restart();

这个重启后有执行么?
这个本地预置的描述文件可以直接写成json字符串,配置在这个脚本里,就不用load了。

fullPath = cc.url.raw(“resources/project.manifest”);
cc.log(“没有下载配置文件,使用本地配置”);
重启没执行, 这个方法只是读下当前最新的资源 版本

    this._am = new jsb.AssetsManager("", this._storagePath, this.versionCompareHandle);

自己调用的应该是
AssetsManagerEx::AssetsManagerEx(const std::string& manifestUrl, const std::string& storagePath, const VersionCompareHandle& handle)
三个参数,第一个manifestUrl 为空的

if (manifestUrl.size() > 0)
{
    loadLocalManifest(manifestUrl);
}

这段代码不走

但是重启后 自动调用了
AssetsManagerEx* AssetsManagerEx::create(const std::string& manifestUrl, const std::string& storagePath)
manifestUrl是下载后的配置文件,然后 走了 loadLocalManifest(manifestUrl); 把资源删除了

这个是异步的

是重启后 整个 start 都没执行,重启的时候 onDestroy 也没调用,手动调用了,也还是不行

和这个没关系的,我屏蔽测试过了

你说的这个方法在哪个方法里?start没执行的话,重启后执行的最先是哪个方法?

new jsb.AssetsManager(this.manifestUrl, storagePath) 我没有使用这个方法,
只有 new jsb.AssetsManager("", this._storagePath, this.versionCompareHandle);
这个热更新代码 都在这里,其他没地方
图片就是重启后自动调用的断点,
工程是重新build的,用的link

是default

可是这个方法在start里啊,那就是重启后执行start了吧?

你看这个方法是三个参数的 而且 第一个是空的 ,但是自动调用的 是两个参数的,第一个不为空
看屏幕下的log,start的方法也没执行,log没打印,
重启后,整个hotupdate,方法里 就执行一句话
收到消息 jsb.EventAssetsManager.ALREADY_UP_TO_DATE
打印是最新版本 ,然后没了

杀进程,重进游戏,又开始下载资源

Initializing JavaScriptCore
cocos2d: fullPathForFilename: No file found at script/jsb_prepare.jsc. Possible missing file.
cocos2d: fullPathForFilename: No file found at script/jsb_boot.jsc. Possible missing file.
JS: Cocos2d-x-lite v1.7.0
JS: 热更新后搜索目录:null
JS: null
2017-11-23 10:29:11.237949+0800 Lottery-mobile[15577:5331300] cocos2d: surface size: 1242x2208
2017-11-23 10:29:11.298957+0800 Lottery-mobile[15577:5331300] cocos2d: surface size: 1242x2208
2017-11-23 10:29:11.311575+0800 Lottery-mobile[15577:5331300] refreshPreferences: HangTracerEnabled: 0
2017-11-23 10:29:11.311703+0800 Lottery-mobile[15577:5331300] refreshPreferences: HangTracerDuration: 500
2017-11-23 10:29:11.311716+0800 Lottery-mobile[15577:5331300] refreshPreferences: ActivationLoggingEnabled: 0 ActivationLoggingTaskedOffByDA:0
JS: LoadScene cdURckF9dAPLuDioIbyPGN: 59.91500000000002ms
JS: I: 1.372000000000014ms
JS: AR: 0.17000000000001592ms
JS: D: 0.05299999999999727ms
JS: Success to load scene: db://assets/resources/Scene/scene_loading.fire
JS: AP: 0.003999999999962256ms
JS: Create unpacker 0952cecd2 for 30CWY6Hj9KFqIHAISxPedc
JS: Create unpacker 0d3988166 for d1JPIpgk9GjKmNYMKOP1X2
JS: 初始化引擎配置
JS: A: 70.613ms
JS: 没有下载配置文件,使用本地配置
JS: manifestUrl =res/raw-assets/resources/project.manifest
JS: 检测更新
JS: ----------------hotUpdate---------Storage path for remote asset : /var/mobile/Containers/Data/Application/61F68B52-2FA5-4D3D-B372-8DB598C04578/Documents/project-remote-asset
JS: false
JS: 开始检测版本
JS: 资源版本:v1.0.3
JS: JS Custom Version Compare: version A is 1.0.3, version B is 1.0.7
JS: 发现版本需要更新
JS: close loadingview
JS: 需要更新
JS: close loadingview
JS: updateCb1-----percentNaNpercentByFileNaN
JS: updateCb1-----percentNaNpercentByFileNaN
JS: JS Custom Version Compare: version A is 1.0.3, version B is 1.0.7
JS: updateCb1-----percentNaNpercentByFile0
JS: updateCb----- Start to update 35 files from remote package.
JS: updateCb1-----percent0percentByFile0.02857142873108387
JS: updateCb1-----percent0.0000951353067648597percentByFile0.05714285746216774
JS: updateCb1-----percent0.0011889225570484996percentByFile0.08571428805589676
JS: updateCb1-----percent0.0017645718762651086percentByFile0.11428571492433548
JS: updateCb1-----percent0.0018602446652948856percentByFile0.1428571492433548
JS: updateCb1-----percent0.0029529568273574114percentByFile0.17142857611179352
JS: updateCb1-----percent0.0035296811256557703percentByFile0.20000000298023224
JS: updateCb1-----percent0.00557697145268321percentByFile0.22857142984867096
JS: updateCb1-----percent0.03369079902768135percentByFile0.22857142984867096
JS: updateCb1-----percent0.03526241332292557percentByFile0.2571428716182709
JS: updateCb1-----percent0.04538007825613022percentByFile0.2571428716182709
JS: updateCb1-----percent0.07028510421514511percentByFile0.2571428716182709
JS: updateCb1-----percent0.08548955619335175percentByFile0.2571428716182709
JS: updateCb1-----percent0.0909375324845314percentByFile0.2571428716182709
JS: updateCb1-----percent0.0909375324845314percentByFile0.2857142984867096
JS: updateCb1-----percent0.10412747412919998percentByFile0.2857142984867096
JS: updateCb1-----percent0.1065010204911232percentByFile0.3142857253551483
JS: updateCb1-----percent0.1065010204911232percentByFile0.34285715222358704
JS: updateCb1-----percent0.1065010204911232percentByFile0.37142857909202576
JS: updateCb1-----percent0.10659562051296234percentByFile0.4000000059604645
JS: updateCb1-----percent0.121961310505867percentByFile0.4000000059604645
JS: updateCb1-----percent0.1515360325574875percentByFile0.4000000059604645
JS: updateCb1-----percent0.1568087786436081percentByFile0.4285714328289032
JS: updateCb1-----percent0.1568087786436081percentByFile0.4571428596973419
JS: updateCb1-----percent0.1597267985343933percentByFile0.48571428656578064
JS: updateCb1-----percent0.19087368249893188percentByFile0.48571428656578064
JS: updateCb1-----percent0.19087368249893188percentByFile0.5142857432365417
JS: updateCb1-----percent0.19087368249893188percentByFile0.5428571701049805
JS: updateCb1-----percent0.21190449595451355percentByFile0.5428571701049805
JS: updateCb1-----percent0.2134750336408615percentByFile0.5714285969734192
JS: updateCb1-----percent0.23293207585811615percentByFile0.5714285969734192
JS: updateCb1-----percent0.23293207585811615percentByFile0.6000000238418579
JS: updateCb1-----percent0.234990656375885percentByFile0.6285714507102966
JS: updateCb1-----percent0.24195757508277893percentByFile0.6285714507102966
JS: updateCb1-----percent0.242559015750885percentByFile0.6571428775787354
JS: updateCb1-----percent0.2492765486240387percentByFile0.6857143044471741
JS: updateCb1-----percent0.2555027902126312percentByFile0.6857143044471741
JS: updateCb1-----percent0.26639875769615173percentByFile0.6857143044471741
JS: updateCb1-----percent0.267177015542984percentByFile0.7142857313156128
JS: updateCb1-----percent0.2779628038406372percentByFile0.7142857313156128
JS: updateCb1-----percent0.2787410616874695percentByFile0.7428571581840515
JS: updateCb1-----percent0.2809103727340698percentByFile0.7428571581840515
JS: updateCb1-----percent0.2809103727340698percentByFile0.7714285850524902
JS: updateCb1-----percent0.290917307138443percentByFile0.7714285850524902
JS: updateCb1-----percent0.30492639541625977percentByFile0.7714285850524902
JS: updateCb1-----percent0.32282689213752747percentByFile0.7714285850524902
JS: updateCb1-----percent0.33108699321746826percentByFile0.7714285850524902
JS: updateCb1-----percent0.33108699321746826percentByFile0.800000011920929
JS: updateCb1-----percent0.3403629660606384percentByFile0.800000011920929
JS: updateCb1-----percent0.3403629660606384percentByFile0.8285714387893677
JS: updateCb1-----percent0.34147876501083374percentByFile0.8571428656578064
JS: updateCb1-----percent0.3507063686847687percentByFile0.8571428656578064
JS: updateCb1-----percent0.36082401871681213percentByFile0.8571428656578064
JS: updateCb1-----percent0.37794622778892517percentByFile0.8571428656578064
JS: updateCb1-----percent0.38028109073638916percentByFile0.8571428656578064
JS: updateCb1-----percent0.3926427662372589percentByFile0.8571428656578064
JS: updateCb1-----percent0.3926427662372589percentByFile0.8857142925262451
JS: updateCb1-----percent0.40976497530937195percentByFile0.8857142925262451
JS: updateCb1-----percent0.41333281993865967percentByFile0.8857142925262451
JS: updateCb1-----percent0.41333281993865967percentByFile0.9142857193946838
JS: updateCb1-----percent0.42267218232154846percentByFile0.9142857193946838
JS: updateCb1-----percent0.4304550290107727percentByFile0.9142857193946838
JS: updateCb1-----percent0.4421292543411255percentByFile0.9142857193946838
JS: updateCb1-----percent0.450690358877182percentByFile0.9142857193946838
JS: updateCb1-----percent0.46547770500183105percentByFile0.9142857193946838
JS: updateCb1-----percent0.47014740109443665percentByFile0.9142857193946838
JS: updateCb1-----percent0.4802650809288025percentByFile0.9142857193946838
JS: updateCb1-----percent0.49660900235176086percentByFile0.9142857193946838
JS: updateCb1-----percent0.5043917894363403percentByFile0.9142857193946838
JS: updateCb1-----percent0.5160660147666931percentByFile0.9142857193946838
JS: updateCb1-----percent0.5238488912582397percentByFile0.9142857193946838
JS: updateCb1-----percent0.5339665412902832percentByFile0.9142857193946838
JS: updateCb1-----percent0.5432091951370239percentByFile0.9142857193946838
JS: updateCb1-----percent0.5525485277175903percentByFile0.9142857193946838
JS: updateCb1-----percent0.5525485277175903percentByFile0.9428571462631226
JS: updateCb1-----percent0.5563534498214722percentByFile0.9714285731315613
JS: updateCb1-----percent0.5688059329986572percentByFile0.9714285731315613
JS: updateCb1-----percent0.5750321745872498percentByFile0.9714285731315613
JS: updateCb1-----percent0.5882629752159119percentByFile0.9714285731315613
JS: updateCb1-----percent0.5944892764091492percentByFile0.9714285731315613
JS: updateCb1-----percent0.6084983348846436percentByFile0.9714285731315613
JS: updateCb1-----percent0.6155028343200684percentByFile0.9714285731315613
JS: updateCb1-----percent0.6263988018035889percentByFile0.9714285731315613
JS: updateCb1-----percent0.6489689946174622percentByFile0.9714285731315613
JS: updateCb1-----percent0.6878830790519714percentByFile0.9714285731315613
JS: updateCb1-----percent0.7050052881240845percentByFile0.9714285731315613
JS: updateCb1-----percent0.7236840724945068percentByFile0.9714285731315613
JS: updateCb1-----percent0.7439194321632385percentByFile0.9714285731315613
JS: updateCb1-----percent0.7602633237838745percentByFile0.9714285731315613
JS: updateCb1-----percent0.7766072750091553percentByFile0.9714285731315613
JS: updateCb1-----percent0.7843900918960571percentByFile0.9714285731315613
JS: updateCb1-----percent0.7929511666297913percentByFile0.9714285731315613
JS: updateCb1-----percent0.8194127678871155percentByFile0.9714285731315613
JS: updateCb1-----percent0.8201910257339478percentByFile0.9714285731315613
JS: updateCb1-----percent0.8489874601364136percentByFile0.9714285731315613
JS: updateCb1-----percent0.8536571860313416percentByFile0.9714285731315613
JS: updateCb1-----percent0.868444561958313percentByFile0.9714285731315613
JS: updateCb1-----percent0.8816753029823303percentByFile0.9714285731315613
JS: updateCb1-----percent0.8910146951675415percentByFile0.9714285731315613
JS: updateCb1-----percent0.9198111295700073percentByFile0.9714285731315613
JS: updateCb1-----percent0.922924280166626percentByFile0.9714285731315613
JS: updateCb1-----percent0.9447161555290222percentByFile0.9714285731315613
JS: updateCb1-----percent0.9509424567222595percentByFile0.9714285731315613
JS: updateCb1-----percent0.9789605736732483percentByFile0.9714285731315613
JS: updateCb1-----percent0.9805171489715576percentByFile0.9714285731315613
JS: updateCb1-----percent0.995304524898529percentByFile0.9714285731315613
JS: updateCb1-----percent1percentByFile0.9714285731315613
JS: updateCb1-----percent1percentByFile1
JS: 更新完成
JS: ["/var/mobile/Containers/Data/Application/61F68B52-2FA5-4D3D-B372-8DB598C04578/Documents/project-remote-asset/"]
JS: --------------HotUpdateSearchPaths----------------["/var/mobile/Containers/Data/Application/61F68B52-2FA5-4D3D-B372-8DB598C04578/Documents/project-remote-asset/",“res/raw-assets/resources/”,""]
JS: 资源更热完成—重启游戏
ScriptEngine::cleanup begin …
GC begin …, (Native -> JS map) count: 476
GC end …, (Native -> JS map) count: 444
GC begin …, (Native -> JS map) count: 444
GC end …, (Native -> JS map) count: 444
GC begin …, (Native -> JS map) count: 444
GC end …, (Native -> JS map) count: 444
ScriptEngine::cleanup end …
Initializing JavaScriptCore
JS: Cocos2d-x-lite v1.7.0
JS: 热更新后搜索目录:["/var/mobile/Containers/Data/Application/61F68B52-2FA5-4D3D-B372-8DB598C04578/Documents/project-remote-asset/",“res/raw-assets/resources/”,""]
JS: [Object object]
JS: LoadScene cdURckF9dAPLuDioIbyPGN: 37.46800000000002ms
JS: I: 1.2860000000000014ms
JS: AR: 0.09399999999999409ms
JS: D: 0.08100000000001728ms
JS: Success to load scene: db://assets/resources/Scene/scene_loading.fire
JS: AP: 0.004000000000019099ms
JS: Create unpacker 0952cecd2 for 30CWY6Hj9KFqIHAISxPedc
JS: Create unpacker 0d3988166 for d1JPIpgk9GjKmNYMKOP1X2
JS: A: 42.79399999999998ms
JS: 初始化引擎配置
JS: ----------------hotUpdate---------Code: 4
JS: ----------------hotUpdate---------getMessage:
JS: ----------------hotUpdate---------getAssetId:
JS: ----------------hotUpdate---------getCURLECode: 0
JS: ----------------hotUpdate---------getCURLMCode: 0
JS: 已是最新版本
JS: close loadingview
JS: Create unpacker 0773c16d1 for 4eSciH+KtD4o6HfW9Z4Fhw
JS: LoadScene d48TV38G1AcaaOq/YiHK1j: 4.2629999999990105ms
JS: I: 21.85200000000077ms
JS: AR: 0.32300000000032014ms
JS: D: 3.190999999998894ms
JS: AP: 0.12299999999959255ms
JS: close loadingview
JS: A: 67.96899999999914ms

完整的log

那就相当于重启后hotupdate脚本未执行,是不是因为重启之前发送了什么消息导致重启后接着执行相关代码了?我用的是1.5版本的hotupdate脚本,然后结合自己的需求调整了,原始版本也没发现GlobalEventManager.getInstance().emitEvent,这些事件代码是官方新加的么?当初执行官方的例子是没有任何问题的,没遇到你描述的问题,如果还解决不了的话,问问引擎组的大神吧

这个是自己加的消息管理器,只是通知 loadingScene 当前状态 决定时候进下个场景

好的 谢谢

        bool localNewer = _localManifest->versionGreater(cachedManifest, _versionCompareHandle);
        if (localNewer)
        {
            // Recreate storage, to empty the content
            _fileUtils->removeDirectory(_storagePath);
            _fileUtils->createDirectory(_storagePath);
            CC_SAFE_RELEASE(cachedManifest);
        }

这段逻辑只在包内版本比本地缓存版本更高的时候才会触发,这意味着你之前下载下来的版本号没有包内版本高,此时为了避免更高版本的包运行低版本的资源,我们会主动清理本地缓存。

你可以检查一下你的包内版本号以及远程版本号。还可以检查一下你的远程 manifest 下载路径和远程包路径是否匹配,会不会用更高的 manifest 版本去下载旧版本资源

版本对比支持的是纯数字,或者 x.x.x.x 这种格式

找到原因了,有个同事把我服务器的hotupdate 逻辑改了 改出问题了 没更新版本id不知道 , 重更了个版本好了

经测试, 版本号相等也会触发这段逻辑

对没错, 相等也会触发, 但即使这样这也是正确的逻辑.
版本号相等, 意味着包内版本与热更新版本相同, 此时热更新的文件多余了, 应该删掉, 这种情况出现是先更新, 再安装了新包.
否则, 版本号相等, 根本不会热更新, 也就不会在本地出现相同的版本.

(Ps:刚把热更新这块移植到cocos2d-js里, 顺便自己实现了动态cdn地址, 表示比之前的上个版本的热更好用不要太多)

求个思路 谢谢