我的配置方法
main.js配置
if(cc.sys.isNative){ var list = jsb.fileUtils.getSearchPaths(); list = [jsb.fileUtils.getWritablePath()].concat(list); jsb.fileUtils.setSearchPaths(list); }
热更新场景配置
var manifestPath = “res/project.manifest”;
var storagePath = (jsb.fileUtils ? jsb.fileUtils.getWritablePath() : “/”);
cc.log("Storage path for this test : " + storagePath);
if(jsb.fileUtils.isFileExist(storagePath + “project.manifest”)) {
manifestPath = storagePath + “project.manifest”;
}
this._manifestPath = manifestPath;
this._storagePath = storagePath;
//打印创建热更新对象前的下载目录内容
var fileList = jsb.fileUtils.listFiles(jsb.fileUtils.getWritablePath());
for(var i = 0; i < fileList.length; i++) {
cc.log("fileList begin "+fileList[i]);
}
this._am = new jsb.AssetsManager(this._manifestPath, this._storagePath);
//打印创建热更新对象后的下载目录内容
var fileList = jsb.fileUtils.listFiles(jsb.fileUtils.getWritablePath());
for(var i = 0; i < fileList.length; i++) {
cc.log("fileList end "+fileList[i]);
}
project.manifest配置
`{
“packageUrl” : “http://192.168.0.101:8080/upgrade/”,
“remoteVersionUrl” : “http://192.168.0.101:8080/upgrade/version.manifest”,
“remoteManifestUrl” : “http://192.168.0.101:8080/upgrade/project.manifest”,
“version” : “1.0.0.5”,
"engineVersion" : "3.15",
"assets" : {
"test_update_170714.zip" : {
"size" : 2151965,
"md5" : "F46AB83160667434C0F7B8AC6938F169",
"compressed": true
}
},
"searchPaths" : [
]
}`
热更新回调配置
`case jsb.EventAssetsManager.UPDATE_FINISHED:
var version = this._am.getLocalManifest().getVersion();
if(this._prevVersion != this._am.getLocalManifest().getVersion()) {
//重启生效
cc.game.restart();
}
else {
this.enterGame(version);
}
cc.log("new version = "+this._am.getLocalManifest().getVersion());
cc.log("Update finished. " + event.getMessage());
this._am.release();`
每次重启第一次会正常下载热更新内容,下载后重启热更新资源就会被删除,导致下次重启找不到远程下载的project.manifest而重复热更新
经过测试时发现,第二次重启时创建jsb.AssetsManager对象前,热更新资源还存在,创建后就被删除了,导致无线重复热更新
测试环境安卓
下面是Android studio 第二次重启打印日志
07-15 14:18:18.348 11624-11671/org.cocos2dx.VSPaohuziJS D/cocos2d-x debug info: Cocos2d-JS v3.15 07-15 14:18:18.708 11624-11671/org.cocos2dx.VSPaohuziJS D/cocos2d-x debug info: create rendererRecreatedListener for GLProgramState 07-15 14:18:18.709 11624-11671/org.cocos2dx.VSPaohuziJS D/cocos2d-x debug info: Storage path for this test : /data/user/0/org.cocos2dx.VSPaohuziJS/files/ 07-15 14:18:18.709 11624-11671/org.cocos2dx.VSPaohuziJS D/cocos2d-x debug info: /data/user/0/org.cocos2dx.VSPaohuziJS/files/project.manifest 07-15 14:18:18.714 11624-11671/org.cocos2dx.VSPaohuziJS D/cocos2d-x debug info: create rendererRecreatedListener for GLProgramState 07-15 14:18:18.722 11624-11671/org.cocos2dx.VSPaohuziJS D/cocos2d-x debug info: find in flash memory dirPath(/data/user/0/org.cocos2dx.VSPaohuziJS/files/) 07-15 14:18:18.723 11624-11671/org.cocos2dx.VSPaohuziJS D/cocos2d-x debug info: fileList begin /data/user/0/org.cocos2dx.VSPaohuziJS/files/./ 07-15 14:18:18.723 11624-11671/org.cocos2dx.VSPaohuziJS D/cocos2d-x debug info: fileList begin /data/user/0/org.cocos2dx.VSPaohuziJS/files/../ 07-15 14:18:18.723 11624-11671/org.cocos2dx.VSPaohuziJS D/cocos2d-x debug info: fileList begin /data/user/0/org.cocos2dx.VSPaohuziJS/files/res/ 07-15 14:18:18.723 11624-11671/org.cocos2dx.VSPaohuziJS D/cocos2d-x debug info: fileList begin /data/user/0/org.cocos2dx.VSPaohuziJS/files/src/ 07-15 14:18:18.724 11624-11671/org.cocos2dx.VSPaohuziJS D/cocos2d-x debug info: fileList begin /data/user/0/org.cocos2dx.VSPaohuziJS/files/project.manifest 07-15 14:18:18.725 11624-11671/org.cocos2dx.VSPaohuziJS D/cocos2d-x debug info: find in flash memory dirPath(/data/user/0/org.cocos2dx.VSPaohuziJS/files/) 07-15 14:18:18.725 11624-11671/org.cocos2dx.VSPaohuziJS D/cocos2d-x debug info: find in flash memory dirPath(/data/user/0/org.cocos2dx.VSPaohuziJS/files_temp/) 07-15 14:18:18.784 11624-11671/org.cocos2dx.VSPaohuziJS D/cocos2d-x debug info: find in flash memory dirPath(/data/user/0/org.cocos2dx.VSPaohuziJS/files/) 07-15 14:18:18.786 11624-11671/org.cocos2dx.VSPaohuziJS D/cocos2d-x debug info: find in flash memory dirPath(/data/user/0/org.cocos2dx.VSPaohuziJS/files/) 07-15 14:18:18.786 11624-11671/org.cocos2dx.VSPaohuziJS D/cocos2d-x debug info: fileList end /data/user/0/org.cocos2dx.VSPaohuziJS/files/./ 07-15 14:18:18.786 11624-11671/org.cocos2dx.VSPaohuziJS D/cocos2d-x debug info: fileList end /data/user/0/org.cocos2dx.VSPaohuziJS/files/../ 07-15 14:18:18.786 11624-11671/org.cocos2dx.VSPaohuziJS I/debug info: 版本号:1.0.0.2 07-15 14:18:18.788 11624-11671/org.cocos2dx.VSPaohuziJS D/cocos2d-x debug info: old version 1.0.0.5
可以看到创建jsb.AssetsManager对象前 fileList下是有热更新资源的,创建jsb.AssetsManager对象后,fileList下就不存在热更新资源了,被删除了。
说明:之前这套用法在3.11和3.14.1的项目用了都是正常的没有出过这种问题,这个项目用3.15就不行了