张峥
张峥
  • 发布:2025-12-18 19:57
  • 更新:2025-12-18 20:31
  • 阅读:21

我在调试可以获取的本地html地址,到了真机打包运行就打不开了。

分类:5+ SDK
var relativePath = '_www/tab-webview-subpage-index.html';  
                    var localPath = plus.io.convertLocalFileSystemURL(relativePath);  
                    // 补全协议头(兼容模拟器/真机)  
                    if (!localPath.startsWith('file://')) {  
                        localPath = 'file://' + localPath;  
                    }  
                    console.log('最终访问路径:', localPath); // 真机日志确认路径是 file:///apps/H50849CDF/www/...  
                    plus.webview.getWebviewById('tab-webview-subpage-index.html').loadURL(localPath);  
                    plus.webview.getWebviewById('tab-webview-subpage-index.html').show();  

这段代码在 真机调试模式就没问题。可以正常打开 tab-webview-subpage-index.html 页面,并且打印日志
最终访问路径: file:///storage/emulated/0/Android/data/io.dcloud.HBuilder/apps/HBuilder/www/tab-webview-subpage-index.html at index.html:220

打包之后,就变成了We are sorry
请求页面file:///apps/xxxxxxx/www/tab-webview-subpage-index.html 无法打开

2025-12-18 19:57 负责人:无 分享
已邀请:
爱豆豆

爱豆豆 - 办法总比困难多

真机下是私有目录 不加file:// 直接用'_www/tab-webview-subpage-index.html'试试

要回复问题请先登录注册