1***@qq.com
1***@qq.com
  • 发布:2025-06-11 11:32
  • 更新:2025-06-13 17:14
  • 阅读:136

【报Bug】HarmonyOS Next wgt 升级之后没效果,app内容不变,版本号也没变

分类:uni-app

产品分类: uniapp/App

PC开发环境操作系统: Mac

PC开发环境操作系统版本号: macOS 15.5

HBuilderX类型: 正式

HBuilderX版本号: 4.66

手机系统: HarmonyOS NEXT

手机系统版本号: HarmonyOS 5.0.1

手机厂商: 华为

手机机型: Mate 70

页面类型: vue

vue版本: vue3

打包方式: 云端

项目创建方式: HBuilderX

示例代码:

首页 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

2025-06-11 11:32 负责人:无 分享
已邀请:
DCloud_UNI_LXH

DCloud_UNI_LXH

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

  • 1***@qq.com (作者)

    可以了,有用

    2025-06-16 10:19

1***@163.com

1***@163.com

请问解决了吗

  • 1***@qq.com (作者)

    没有,目前没官方回复

    2025-06-11 14:59

1***@163.com

1***@163.com

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

要回复问题请先登录注册