3.x热更新问题 checkUpdate返回时间码=5

  • Creator 版本: 3.8.0

  • 目标平台:Android

  • 重现方式:必现

  • 首个报错: image

  • 手机型号: 模拟器

  • 逻辑代码:

init (manifestUrl: Asset) {
        // Hot update is only available in Native build
        if (!jsb) {
            return;
        }
        this.initManifest(manifestUrl);

        this._storagePath = ((jsb.fileUtils ? jsb.fileUtils.getWritablePath() : '/') + 'blackjack-remote-asset');
        console.log('[HotUpdate] Storage path for remote asset : ' + this._storagePath);

        if (jsb.fileUtils.isDirectoryExist(this._storagePath)) {
            console.warn(" delete hotupdate directory ")
            jsb.fileUtils.removeDirectory(this._storagePath);
        }

        // Setup your own version compare handler, versionA and B is versions in string
        // if the return value greater than 0, versionA is greater than B,
        // if the return value equals 0, versionA equals to B,
        // if the return value smaller than 0, versionA is smaller than B.
        this.versionCompareHandle = function (versionA: string, versionB: string) {
            // if (this._isChecked) return;
            console.log("[HotUpdate] Version Compare: version A is " + versionA + ', version B is ' + versionB);
            // this._isChecked = true;
            let vA = versionA.split('.');
            let vB = versionB.split('.');
            for( let i = 0 ; i < vA.length && i < vB.length ; ++i ){
                let a = parseInt(vA[i]);
                let b = parseInt(vB[i]);
                if ( a === b ){
                    continue;
                }
                else{
                    console.log(`[HotUpdate] version check -1 `)
                    return  -1;//这里直接返回-1 
                }
            }
            if ( vB.length > vA.length){
                console.log(`[HotUpdate] version check -1 `)
                return -1;
            }
            console.log(`[HotUpdate] version check 0 `)
            return 0;
        };

        // Init with empty manifest url for testing custom manifest
        this._am = new jsb.AssetsManager('', this._storagePath);

        this._am.setVersionCompareHandle(this.versionCompareHandle.bind(this));

        // Setup the verification callback, but we don't have md5 check function yet, so only print some message
        // Return true if the verification passed, otherwise return false
        this._am.setVerifyCallback(function (path: string, asset: any) {
            // When asset is compressed, we don't need to check its md5, because zip file have been deleted.
            var compressed = asset.compressed;
            // Retrieve the correct md5 value.
            var expectedMD5 = asset.md5;
            // asset.path is relative path and path is absolute.
            var relativePath = asset.path;
            // The size of asset file, but this value could be absent.
            var size = asset.size;
            if (compressed) {
                // panel.info.string = "Verification passed : " + relativePath;
                console.log("[HotUpdate] " + "Verification passed : " + relativePath)
                return true;
            }
            else {
                // panel.info.string = "Verification passed : " + relativePath + ' (' + expectedMD5 + ')';
                console.log("[HotUpdate] " + "Verification passed : " + relativePath + ' (' + expectedMD5 + ')')
                return true;
            }
        });
    }

    checkCb(event: any) {
        console.log(`[HotUpdate] checkCb `, event.getEventCode());
        let isHaveNewVersion = false;
        switch (event.getEventCode()) {
            case jsb.EventAssetsManager.ERROR_NO_LOCAL_MANIFEST:
                // this.panel.info.string = "No local manifest file found, hot update skipped.";
                break;
            case jsb.EventAssetsManager.ERROR_DOWNLOAD_MANIFEST:
            case jsb.EventAssetsManager.ERROR_PARSE_MANIFEST:
                // this.panel.info.string = "Fail to download manifest file, hot update skipped.";
                break;
            case jsb.EventAssetsManager.ALREADY_UP_TO_DATE:
                // this.panel.info.string = "Already up to date with the latest remote version.";
                break;
            case jsb.EventAssetsManager.NEW_VERSION_FOUND:
                // this.panel.info.string = 'New version found, please try to update. (' + Math.ceil(this._am.getTotalBytes() / 1024) + 'kb)';
                // this.panel.checkBtn.active = false;
                // this.panel.fileProgress.progress = 0;
                // this.panel.byteProgress.progress = 0;
                isHaveNewVersion = true;
                console.log("[HotUpdate] have new version ")
                break;
            default:
                return;
        }

        // this._am.setVersionCompareHandle(null!);
        this._am.setEventCallback(null!);
        this._checkListener = null;
        this._updating = false;

        EventManager.emit(EventType.HOTUPDATE_CHECK_RESULT, isHaveNewVersion);
    }

    // 检测是否有新版本
    checkUpdate() {
        console.log(`[HotUpdate] checkUpdate `, this._am.getState());
        if (this._updating) {
            // this.panel.info.string = 'Checking or updating ...';
            return false;
        }
        
        if (this._am.getState() === jsb.AssetsManager.State.UNINITED) {
            var url = this.manifestUrl.nativeUrl;
            this._am.loadLocalManifest(url);
        }
        if (!this._am.getLocalManifest() || !this._am.getLocalManifest().isLoaded()) {
            // this.panel.info.string = 'Failed to load local manifest ...';
            return false;
        }
        this._am.setEventCallback(this.checkCb.bind(this));

        this._am.checkUpdate();
        this._updating = true;
        return true;
    }

有没有大佬指导一下是哪里的问题,万分感谢!!!

image 进度更新而已,问题不大

已解决 project.manifest和version.manifest里的version字段必须要大于本地版本