tauri 在window平台打包遇到的问题
背景
在window平台使用tauri时打包会出现wix314,nsis等问题,即使开了代理,甚至根据其他文章的教程下载对应的包放在指定位置也有可能出现问题,这片文章会提供一个解决思路的参考
tauri打包
…此处省略tauri环境搭建过程,直接进入打包环境
1. wix314等问题解决思路
类似如下这种错误,可以直接根据提示的链接下载对应的包
warning: `app` (bin "app") generated 1 warning
Finished `release` profile [optimized] target(s) in 4.52s
Info Verifying wix package
Downloading https://github.com/wixtoolset/wix3/releases/download/wix3141rtm/wix314-binaries.zip
Error failed to bundle project: `https://github.com/wixtoolset/wix3/releases/download/wix3141rtm/wix314-binaries.zip: Network Error: Network Error: Error encountered in the status line: unexpected end of file`
然后解压在C:\Users\${User}\AppData\Local\tarui\WixTools314这个目录下,然后就可以继续执行npm run tauri build编译,最终文件目录如下
--WixTools314
--doc
--sdk
--x86
--candle.exe
--...
如果还会产生wix之类的问题,那么就可能是tarui\WixTools314这个目录不对,具体查看github中的源码
https://github.com/tauri-apps/tauri/blob/dev/tooling/bundler/src/bundle/windows/msi.rs
pub fn bundle_project(settings: &Settings, updater: bool) -> crate::Result<Vec<PathBuf>> {
let mut wix_path = dirs::cache_dir().unwrap();
wix_path.push("tauri/WixTools314");
if !wix_path.exists() {
wix::get_and_extract_wix(&wix_path)?;
} else if WIX_REQUIRED_FILES
.iter()
.any(|p| !wix_path.join(p).exists())
{
log::warn!("WixTools directory is missing some files. Recreating it.");
std::fs::remove_dir_all(&wix_path)?;
wix::get_and_extract_wix(&wix_path)?;
}
wix::build_wix_app_installer(settings, &wix_path, updater)
}
以上应该基本上就能完美解决这个问题了,即使目录不对,也有思路去找到正确的。
2. nsis问题
类似如下这种错误,可以直接根据提示的链接下载对应的包
Downloading https://github.com/tauri-apps/binary-releases/releases/download/nsis-3/nsis-3.zip
Error failed to bundle project: `https://github.com/tauri-apps/binary-releases/releases/download/nsis-3/nsis-3.zip: Connection Failed: Connect error: 由于连接方在一段时间后没有正确
答复或连接的主机没有反应,连接尝试失败。 (os error 10060)`
-
解压在C:\Users\${User}\AppData\Local\tarui\NSIS这个目录下
-
下载https://github.com/tauri-apps/binary-releases/releases/download/nsis-plugins-v0/NSIS-ApplicationID.zip解压到NSIS/Plugins目录下
-
将NSIS-ApplicationID\ReleaseUnicode\ApplicationID.dll复制到NSIS/Plugins/x86-unicode下
-
下载https://knsay.com/upload/default/20230614/b0c63b57f4729e1d3a245023672df79a.zip,将nsis_tauri_utils.dll复制到NSIS/Plugins/x86-unicode下
最终文件目录如下
--NSIS
--Plugins
--Debug
--DebugUnicode
--Release
--ReleaseUnicode
--x86-ansi
--x86-unicode
--ApplicationID.dll
--nsis_tauri_utils.dll
--...
然后就可以继续执行npm run tauri build编译。
如果产生类似如下错误,通过提示的链接直接下载对应nsis_tauri_utils.dll复制到NSIS/Plugins/x86-unicode下即可,然后就可以继续执行npm run tauri build编译。
Downloading https://github.com/tauri-apps/nsis-tauri-utils/releases/download/nsis_tauri_utils-v0.4.0/nsis_tauri_utils.dll
Error failed to bundle project: `https://github.com/tauri-apps/nsis-tauri-utils/releases/download/nsis_tauri_utils-v0.4.0/nsis_tauri_utils.dll: Network Error: Network Error: Error encountered in the status line: unexpected end of file`
如果还会产生nsis之类的问题,那么就可能是tarui\NSIS这个目录不对,具体查看github中的源码
https://github.com/tauri-apps/tauri/blob/dev/tooling/bundler/src/bundle/windows/msi.rs
pub fn bundle_project(settings: &Settings, updater: bool) -> crate::Result<Vec<PathBuf>> {
let tauri_tools_path = dirs::cache_dir().unwrap().join("tauri");
let nsis_toolset_path = tauri_tools_path.join("NSIS");
if !nsis_toolset_path.exists() {
get_and_extract_nsis(&nsis_toolset_path, &tauri_tools_path)?;
} else if NSIS_REQUIRED_FILES
.iter()
.any(|p| !nsis_toolset_path.join(p).exists())
{
log::warn!("NSIS directory is missing some files. Recreating it.");
std::fs::remove_dir_all(&nsis_toolset_path)?;
get_and_extract_nsis(&nsis_toolset_path, &tauri_tools_path)?;
} else {
let mismatched = NSIS_REQUIRED_FILES_HASH
.iter()
.filter(|(p, _, hash, hash_algorithm)| {
verify_file_hash(nsis_toolset_path.join(p), hash, *hash_algorithm).is_err()
})
.collect::<Vec<_>>();
if !mismatched.is_empty() {
log::warn!("NSIS directory contains mis-hashed files. Redownloading them.");
for (path, url, hash, hash_algorithim) in mismatched {
let data = download_and_verify(url, hash, *hash_algorithim)?;
fs::write(nsis_toolset_path.join(path), data)?;
}
}
}
build_nsis_app_installer(settings, &nsis_toolset_path, &tauri_tools_path, updater)
}
以上应该基本上就能完美解决这个问题了,即使目录不对,也有思路去找到正确的。