3.8.3热更新失败

  • Creator 版本: 3.8.3

  • 目标平台: Android

  • 重现方式:必现

  • 首个报错:


    下载文件都报错找不到,但是在浏览器输入地址是可以下载的。
    if (this._am.getState() === native.AssetsManager.State.UNINITED) {

              return;
    
          }
    
          this._am.setEventCallback(this.updateCb.bind(this))
    
          this._am.update();
    

updateCb(event: any) {

    let failed = false;

    let msg = '';

    console.log('HotUpdateMgr updateCb Code: ' + event.getEventCode());

    switch (event.getEventCode()) {

        case native.EventAssetsManager.ERROR_NO_LOCAL_MANIFEST:

            msg = 'No local manifest file found, hot update skipped.';

            console.log('HotUpdateMgr No local manifest file found, hot update skipped.');

            failed = true;

            break;

        case native.EventAssetsManager.UPDATE_PROGRESSION:

            // event.getPercent();

            // event.getPercentByFile()

            // event.getDownloadedFiles()

            // event.getTotalFiles()

            // event.getMessage()

            if (this.onProgress) {

                var precent = event.getPercent()

                precent = precent < 0 ? 0 : precent;

                precent = precent > 1 ? 1 : precent;

                this.onProgress(precent, this.bundle);

            }

            break;

        case native.EventAssetsManager.ERROR_DOWNLOAD_MANIFEST:

        case native.EventAssetsManager.ERROR_PARSE_MANIFEST:

            console.log('HotUpdateMgr Fail to download manifest file, hot update skipped.');

            msg = 'HotUpdateMgr Fail to download manifest file, hot update skipped.';

            failed = true;

            break;

        case native.EventAssetsManager.ALREADY_UP_TO_DATE:

            console.log('HotUpdateMgr Already up to date with the latest remote version.');

            break;

        case native.EventAssetsManager.UPDATE_FINISHED:

            console.log('HotUpdateMgr Update finished. ' + event.getMessage());

            this.onDownloadSuccess();

            break;

        case native.EventAssetsManager.UPDATE_FAILED:

            if (this._maxRetry > 0) {

                this.retry();

            }

            else {

                failed = true;

            }

            break;

        case native.EventAssetsManager.ERROR_UPDATING:

            console.log('HotUpdateMgr Asset update error: ' + event.getAssetId() + ', ' + event.getMessage());

            break;

        case native.EventAssetsManager.ERROR_DECOMPRESS:

            console.log('HotUpdateMgr ' + event.getMessage());

            break;

        default:

            break;

    }

    if (failed) {

        this.onDownloadFailed();

    }

}

本地project.manifest中的地址是不是下面的网址

cocos的远程服务器资源地址必须是固定的一个值,每次打包导出 project.manifest 文件时,该路径都必须一致:

  • 版本检测时,是根据本地文件中指定的 remoteVersionUrl 字段对应的值获取远端资源版本信息的;
  • 资源下载时,是根据远端文件中指定的 packageUrlremoteManifestUrl 比对然后下载对应资源的。

如果是基于版本存放的热更资源(地址为 https://XXXX/v1、https://XXXX/v2 之类),这种就没法直接套用cocos的热更方案,而是需要通过额外的服务或者存放在固定OSS上的版本信息文件自行解析出对应的版本号,再走cocos的热更。

版本检测服务或借助OSS进行版本检测市面上方案挺多就不细说了。下面主要说一下cocos里面的修改点:

  1. 创建 native.AssetsManager 对象时,绑定的版本检测句柄固定返回-1,即为需要更新(逻辑能走到这里就都是需要更新的了);
  2. 自行构建native.Manifest对象,将本地的清单文件及远端清单文件序列化为json字符串传入,其中第二个参数对应项目存放更新资源的目录;
  3. 注意,构建native.Manifest对象时,packageUrlremoteManifestUrl两个地址需保持一致,且指向正确的新版本的CDN地址!
  4. 使用loadLocalManifestloadRemoteManifest接口分别加载前面步骤构建出的native.Manifest对象;
  5. 绑定校验句柄、事件句柄等之后调用update开始更新即可,这边的步骤就和文档里差不多了。

这个是动态更换地址的, let localMainfest = new native.Manifest(localManifestContent, this._storagePath);
this._am.loadLocalManifest(localMainfest, this._storagePath);

    let manifest = this._am.getLocalManifest();
    manifest.parseJSONString(content, this._storagePath)
    if (!this._am.getLocalManifest() || !this._am.getLocalManifest().isLoaded()) {
        console.log(`${this.bundle} Failed to load local manifest ....`);
        ToastCtrl.showToast('Failed to load local manifest ....');
        return false;
    }
    console.log(`${this.bundle} load local manifest success ....`);
    console.log("##### Hotupdate 获取远程资源配置文件地址=========111 : " + this._am.getLocalManifest().getPackageUrl());
    console.log("##### Hotupdate 获取远程资源配置文件地址=========222 : " + this._am.getLocalManifest().getManifestFileUrl());
    console.log("##### Hotupdate 获取远程资源配置文件地址=========333 : " + this._am.getLocalManifest().getVersionFileUrl() );
    console.log("##### Hotupdate 获取远程资源配置文件地址=========444 : " + this._am.getLocalManifest().getVersion());

感谢回复,之前3.8.1版本是好的。3.8.3下载就是报错找不到文件,我看手机内是有下载到manifest的tmp文件的

同问,请问解决了吗,我是从resource移动一个预制物到res的bundle里面再热更就NotFound了