tauri在window平台打包的问题

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)`
  1. 解压在C:\Users\${User}\AppData\Local\tarui\NSIS这个目录下

  2. 下载https://github.com/tauri-apps/binary-releases/releases/download/nsis-plugins-v0/NSIS-ApplicationID.zip解压到NSIS/Plugins目录下

  3. 将NSIS-ApplicationID\ReleaseUnicode\ApplicationID.dll复制到NSIS/Plugins/x86-unicode下

  4. 下载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)
}

以上应该基本上就能完美解决这个问题了,即使目录不对,也有思路去找到正确的。

这是一个 Rust 语言的 API 文档,介绍了 Tauri 库版本 1.3.0 中的 `WindowBuilder` 结构体。`WindowBuilder` 结构体是用于创建 Tauri 应用程序窗口的构建器。以下是该文档的翻译: # `WindowBuilder` 用于创建 Tauri 应用程序窗口的构建器。 ## 结构体成员 ### `width` 窗口的宽度。默认值为 `800`。 ### `height` 窗口的高度。默认值为 `600`。 ### `title` 窗口的标题。默认值为 `Tauri Application`。 ### `resizable` 窗口是否可以调整大小。默认为 `true`。 ### `fullscreen` 窗口是否全屏。默认为 `false`。 ### `fullscreenable` 窗口是否可以全屏。默认为 `true`。 ### `decorations` 窗口是否有装饰。默认为 `true`。 ### `transparent` 窗口是否透明。默认为 `false`。 ### `always_on_top` 窗口是否总在最上层。默认为 `false`。 ### `icon` 窗口的图标。默认为 `None`。 ### `min_width` 窗口的最小宽度。默认为 `None`。 ### `min_height` 窗口的最小高度。默认为 `None`。 ### `max_width` 窗口的最大宽度。默认为 `None`。 ### `max_height` 窗口的最大高度。默认为 `None`。 ### `inner_border` 窗口是否有内边框。默认为 `true`。 ### `platform_specific` 在某些平台上启用特定于平台的外观和行为。默认为 `true`。 ## 方法 ### `new() -> WindowBuilder` 创建新的 `WindowBuilder` 实例。 ### `build(&self) -> Result<Window, String>` 使用该构建器创建并返回一个新的 `Window` 实例。如果构建器的参数不正确,则返回一个 `Err`。 ### `with_title<S: Into<String>>(mut self, title: S) -> Self` 设置窗口标题。 ### `with_width(mut self, width: f64) -> Self` 设置窗口的宽度。 ### `with_height(mut self, height: f64) -> Self` 设置窗口的高度。 ### `with_resizable(mut self, resizable: bool) -> Self` 设置窗口是否可以调整大小。 ### `with_fullscreen(mut self, fullscreen: bool) -> Self` 设置窗口是否全屏。 ### `with_fullscreenable(mut self, fullscreenable: bool) -> Self` 设置窗口是否可以全屏。 ### `with_decorations(mut self, decorations: bool) -> Self` 设置窗口是否有装饰。 ### `with_transparent(mut self, transparent: bool) -> Self` 设置窗口是否透明。 ### `with_always_on_top(mut self, always_on_top: bool) -> Self` 设置窗口是否总在最上层。 ### `with_icon(mut self, icon: Icon) -> Self` 设置窗口的图标。 ### `with_min_width(mut self, min_width: f64) -> Self` 设置窗口的最小宽度。 ### `with_min_height(mut self, min_height: f64) -> Self` 设置窗口的最小高度。 ### `with_max_width(mut self, max_width: f64) -> Self` 设置窗口的最大宽度。 ### `with_max_height(mut self, max_height: f64) -> Self` 设置窗口的最大高度。 ### `with_inner_border(mut self, inner_border: bool) -> Self` 设置窗口是否有内边框。 ### `with_platform_specific(mut self, platform_specific: bool) -> Self` 设置是否在某些平台上启用特定于平台的外观和行为。 ## 示例 ```rust use tauri::WindowBuilder; let builder = WindowBuilder::new() .with_title("My App") .with_width(800.0) .with_height(600.0); let window = builder.build().unwrap(); ```
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值