uniapp 更新apk有缓存点不动,卸载安装apk没有问题。android
·
原因:
-
HBuilderX / uniapp 打包后的 APK,在第一次安装时,会把
pages.json、路由表、静态资源等都缓存到本地的 版本目录(一般在__uniapp__目录下)。 -
如果你只是直接用
manifest.json里相同的版本号重新打包 APK 更新安装,新页面的路由信息不会被覆盖更新,因为 uni-app 认为旧版本已经缓存了,不会去替换。 -
所以卸载或清除缓存后可以跳转,是因为旧缓存被清空,重新加载了新的路由表。
方式一。
每次更新修改版本名称和版本号就可以清缓存,

方式二。
在 App.vue 的 onLaunch 中添加:
onLaunch() {
// 版本变更检测
const currentVersion = plus.runtime.version;
const lastVersion = uni.getStorageSync('app_version');
if (!lastVersion || lastVersion !== currentVersion) {
// 关键操作:清除WebView缓存
const webview = plus.webview.currentWebview();
if (webview) {
webview.clear(); // 清除当前WebView缓存
}
// 清除应用缓存
plus.cache.clear();
// 强制重启(关键!)
setTimeout(() => {
plus.runtime.restart();
}, 500);
// 存储新版本
uni.setStorageSync('app_version', currentVersion);
}
}
更多推荐


所有评论(0)