uni-app 云打包升级app后新增功能需手动清理内存并杀死进程才生效

uni-app 云打包升级app后新增功能需手动清理内存并杀死进程才生效

示例代码:

{
"path": "pages/garden/gardenback4",
"style": {
"navigationBarTitleText": "打印送货单",
"enablePullDownRefresh": false,
"app-plus": {
"titleNView": {
"titleAlign": "left",
"buttons": [{
"fontSrc": "/static/uni.ttf",
"text": "\ue404"
}]
}
}
}
let that = this
let downloadurl = that.wgt_flag == 1 ? that.wgt_url : that.version_url
//let downloadurl = that.version_url
this.update_confirm = true
this.downloadTask = uni.downloadFile({
url: downloadurl,
success: function(res) {
console.error(res);
if (res.statusCode == 200) {
//开始安装
plus.runtime.install(res.tempFilePath, {
force: false
}, function() {
//console.log('install success...');
plus.runtime.restart();
}, function(e) {
console.error(e);
uni.showToast({
title: '升级失败:'+e.message,
icon: 'none'
});
});
} else {
uni.showToast({
title: '下载失败,网络错误',
icon: 'none'
});
}
},
fail: function(e) {
//console.log("下载失败",e)
uni.showToast({
title: '下载失败:' + e.errMsg,
icon: 'none'
});
this.update_flag = false
},
complete: function() {}
})
this.downloadTask.onProgressUpdate(function(res) {
that.update_process = res.progress
if (res.progress == Infinity) {
//使用size计算
//console.log("计算size");
let progress = (res.totalBytesWritten / that.size) * 100
if (progress > 100) {
progress = 100
}
that.update_process = progress
}
})

升级代码插件地址

https://ext.dcloud.net.cn/plugin?id=3931

bug描述:

app升级后新修改的功能,例如在pages.json中增加页面,或者增加tabBar,这些都不能立即更新,需要手动结束进程后再打开app才能正常,这是什么原因?

项目信息 详情
产品分类 uniapp/App
PC开发环境 Windows
PC开发环境版本 windows 10 HOME
HBuilderX类型 正式
HBuilderX版本 3.1.22
手机系统 Android
手机系统版本 Android 7.0
手机厂商 小米
手机机型 红米4x
页面类型 vue
打包方式 云端
项目创建方式 HBuilderX

更多关于uni-app 云打包升级app后新增功能需手动清理内存并杀死进程才生效的实战教程也可以访问 https://www.itying.com/category-93-b0.html

2 回复

解决了嘛,我也遇到了类似问题

更多关于uni-app 云打包升级app后新增功能需手动清理内存并杀死进程才生效的实战教程也可以访问 https://www.itying.com/category-93-b0.html


这是一个典型的资源更新缓存问题。在uni-app中,pages.json等配置文件在应用启动时会被缓存,热更新后新配置不会立即生效。

主要原因:

  1. 应用启动缓存机制:uni-app框架在启动时会缓存pages.json等配置文件,以提高启动性能
  2. 资源包更新时机:wgt资源包更新后,新的pages.json需要下次冷启动才能加载

解决方案:

方案一:强制重启应用(推荐)

plus.runtime.install(res.tempFilePath, {
    force: false
}, function() {
    // 使用quit方法完全退出应用
    plus.runtime.quit();
    // 延迟重启确保进程完全结束
    setTimeout(() => {
        plus.runtime.restart();
    }, 100);
});

方案二:修改升级流程

// 安装成功后提示用户重启
plus.runtime.install(res.tempFilePath, {
    force: false
}, function() {
    uni.showModal({
        title: '更新完成',
        content: '新功能需要重启应用才能生效',
        showCancel: false,
        success: function(res) {
            if (res.confirm) {
                plus.runtime.restart();
            }
        }
    });
});
回到顶部