加载远程 project.manifest报错:Do not know how to serialize a BigInt

project - 副本.zip (5.2 KB)

  • Creator 版本: 3.5.2

  • 目标平台: Android

  • 重现方式:
    加载远程热更描述文件 project.manifest ,此文件具体内容建附件(下载查看时扩展名改为 manifest)

关键代码: let remoteManifest = new jsb.Manifest(“http://10.4.11.65:7879/project.manifest”);


    loadCustomManifest() {
        if (this._am.getState() === jsb.AssetsManager.State.UNINITED) {
            //var manifest = new jsb.Manifest(customManifestStr, this._storagePath);
            //this._am.loadLocalManifest(manifest, this._storagePath);
            this.panel.info.string = 'Using custom manifest';
            this._loadLocalManifest().then((state) => {
                console.debug('assetsManager state: ', state);
                if (!this._am.getLocalManifest() || !this._am.getLocalManifest().isLoaded()) {
                    this.panel.info.string = 'Failed to load local manifest ...';
                    return;
                }

                if (this._am.getState() === jsb.AssetsManager.State.UNCHECKED) {
                    let remoteManifest = new jsb.Manifest("http://10.4.11.65:7879/project.manifest");
                    console.debug('remote manifest: ', JSON.stringify(remoteManifest));
                    if (this._am.loadRemoteManifest(remoteManifest)) {
                        console.debug('_am getRemoteManifest', this._am.getRemoteManifest());
                        this._am.setEventCallback(this.checkCb.bind(this));
                        this._am.checkUpdate();
                        this._updating = true;
                    }
                    else {
                        console.error('加载远程Manifest失败');
                    }
                }
            }).catch( err => {
                    console.error('读取远程 manifest 出错: ', err.message);
                }
            );
        }
    }

  • 首个报错:Do not know how to serialize a BigInt

@7338564 附件有问题? 无法打开

改扩展名->.manifest

你的服务也跑在内网, 麻烦提供一个能复现问题的工程.

tutorial-hot-update-1.rar (2.2 MB)

你好,工程在附件中

复现步骤:

  1. 执行构建android构建

  2. 生成apk,安装到手机

  3. 启动本地http服务:在目标工程data文件夹已经生成了脚本 start-http-server.bat,如图:

  4. 启动app, 点击“使用自定义配置”,如图:
    image

期望结果: 可以得到和点击“检查更新”按钮一样的效果。

当前结果:报错,错误信息:Do not know hot to serialize a BigInt

这样做的目的:可以在运行时自定义远程服务器地址;

可以注释掉这行代码, JSON.stringify 不支持 BigInt

注释后代码会走到 image ,AssetsManager.loadRemoteManifest() 函数会返回false :joy:

检查下资源地址数据看看是否有问题

远程的资源没有问题,是Manifest构造函数的参数不支持网络地址,要先利用assetManager.downloader.downloadfile 下载远程的project.manifest, 然后调用assetManger.loadRemoteManifest(), 这样是可以正确发现新版本,但是无法获得当前需要下载的总容量,这个和c++实现细节相关。代码如下:

所以换一种方案,用当前的本地 project.Manifest + 要替换的服务器地址 生成一个新的本地 project.manifest , 然后按正常的流程做更新。