HarmonyOS Next wgt 升级之后没效果 uni-app app内容不变版本号也没变

HarmonyOS Next wgt 升级之后没效果 uni-app app内容不变版本号也没变

开发环境 版本号 项目创建方式
Mac macOS 15.5 HBuilderX

产品分类:uniapp/App

PC开发环境操作系统:Mac

手机系统:HarmonyOS NEXT

手机系统版本号:HarmonyOS 5.0.1

手机厂商:华为

手机机型:Mate 70

页面类型:vue

vue版本:vue3

打包方式:云端

示例代码:

首页 onShow 代码
const systemInfo = uni.getSystemInfoSync()  
console.info('检查更新',systemInfo)  

plus.runtime.getProperty(systemInfo.appId, (widgetInfo) => {  
    console.info('widgetInfo', widgetInfo)  

    let isUpdate = false  
    let uniUpgradeCenterResult = {}  

    IndexService.getNewVersion({  
        type: 'harmonyosnext',  
        version: widgetInfo.version  
    }).then(res => {  
        console.info('检查更新>>>>>', res)  
        // 是否有更新  
        if(res.data.isUpdate){  
            isUpdate = true  
            uniUpgradeCenterResult = {  
                title: '更新',  
                contents: '修复了一些已知问题',  
                url: res.data.url, // 安装包下载地址  
                platform: 'Harmony', // Array<'Android' | 'iOS' | 'Harmony'>  
                is_mandatory: true, // 是否强制更新  
                type: 'wgt', // "native_app" | "wgt"  
            }  
            // 是否整包更新  
            if(res.data.isPackageUpdate){  
                uniUpgradeCenterResult.type = 'native_app'  
                uniUpgradeCenterResult.url = `store://appgallery.huawei.com/app/detail?id=${res.data.appId}`  
            }  
        }  

        if(isUpdate){  
            console.info('更新',uniUpgradeCenterResult)  
            this.$refs.upgradePopup.show(true, uniUpgradeCenterResult)  
        }  
    })  
})  
安装更新代码,参考 升级中心 uni-upgrade-center
installPackage() {  
    if (this.isWGT) {  
        this.installing = true;  
    }  
    plus.runtime.install(  
        this.tempFilePath,  
        {  
            force: false  
        },  
        async (res) => {  
            this.installing = false;  
            this.installed = true;  

            // wgt包,安装后会提示 安装成功,是否重启  
            if (this.isWGT) {  
                // 强制更新安装完成重启  
                if (this.is_mandatory) {  
                    setTimeout(() => {  
                        this.restart();  
                    }, 1000);  
                }  
            } else {  
                const localFilePathRecord = uni.getStorageSync(localFilePathKey);  
                uni.setStorageSync(localFilePathKey, {  
                    ...localFilePathRecord,  
                    installed: true  
                });  
            }  
        },  
        async (err) => {  
            // 如果是安装之前的包,安装失败后删除之前的包  
            if (this.installForBeforeFilePath) {  
                await this.deleteSavedFile(this.installForBeforeFilePath);  
                this.installForBeforeFilePath = '';  
            }  

            // 安装失败需要重新下载安装包  
            this.installing = false;  
            this.installed = false;  

            uni.showModal({  
                title: '更新失败,请重新下载',  
                content: err.message,  
                showCancel: false  
            });  
        }  
    );  

    // 非wgt包,安装跳出覆盖安装,此处直接返回上一页  
    if (!this.isWGT && !this.is_mandatory) {  
        uni.navigateBack();  
    }  
},  
restart() {  
    this.installed = false;  
    uni.showModal({  
        title: '更新完毕',  
        content: '请手动重启',  
        showCancel: false,  
        success(res) {  
            plus.runtime.quit()  
        }  
    })  
},

操作步骤:

  • 安装更新

预期结果:

  • 内容更新

实际结果:

  • 内容不变

bug描述:

首页 onShow 通过 plus.runtime.getProperty 获取版本号
后端接口判断是否更新 uni.downloadFile 下载 wgt 包
plus.runtime.install 安装下载 已经提示 ‘更新完毕’, ‘请手动重启’,不管是直接重新打开还是杀进程打开,app 内容不变,版本号不变,还是提示需要更新
制作 wgt 包已选择 harmony


更多关于HarmonyOS Next wgt 升级之后没效果 uni-app app内容不变版本号也没变的实战教程也可以访问 https://www.itying.com/category-93-b0.html

6 回复

是和本地调试运行时的 hmr 热更新逻辑冲突了,这样在本地测试 wgt 更新

更多关于HarmonyOS Next wgt 升级之后没效果 uni-app app内容不变版本号也没变的实战系列教程也可以访问 https://www.itying.com/category-93-b0.html


可以了,有用

请问解决了吗

没有,目前没官方回复

请问贴主有其他的解决方案吗

根据你提供的代码和问题描述,这是一个典型的HarmonyOS Next环境下wgt热更新安装成功但未生效的问题。主要问题可能出现在以下几个方面:

  1. HarmonyOS Next兼容性问题:HarmonyOS Next对wgt热更新的支持可能存在差异。虽然代码逻辑正确,但plus.runtime.install在HarmonyOS Next环境下可能存在兼容性问题。

  2. wgt包制作配置:确认wgt包制作时是否正确选择了Harmony平台,并且版本号配置正确。检查manifest.json中的版本号是否高于当前安装版本。

  3. 安装路径和权限:在HarmonyOS Next中,临时文件的读写权限可能受到限制。建议在下载完成后验证tempFilePath是否有效:

console.log('wgt文件路径:', this.tempFilePath);
plus.io.resolveLocalFileSystemURL(this.tempFilePath, (entry) => {
    console.log('文件存在,大小:', entry.size);
}, (err) => {
    console.error('文件不存在或无法访问:', err);
});
  1. 重启机制问题:在HarmonyOS Next中,plus.runtime.quit()可能无法完全重启应用。建议使用更彻底的重启方式:
restart() {
    plus.runtime.restart();
}
回到顶部