Sivan
Sivan
Published on 2024-02-15 / 669 Visits
0
1

Tauri 应用上架 App Store 实用指南

Tauri 应用上架 App Store 实用指南

在写 Tauri 应用时,一心欣喜觉得找到了替代 electron 的大杀器,当应用写完准备上架时,才发现到处都找不到如何正确打包和上架的文档。

谨以此文献给各位踏入 Tauri 领域的勇士,能够帮各位上架这件事情上减少一些困扰,避免“拔剑四顾心茫然”的窘迫感。

上架苹果商店,这里有份清单,供对照使用:

  • 苹果开发者账号
  • 2 个证书
    • Apple Distribution Certificate
    • 3rd Party Mac Developer Installer Certificate
  • 配置文件
    • embedded.provisionprofile
  • 授权文件
    • entitlements.plist
  • 应用程序包
    • Your_App_Name.app
  • 应用程序
    • Xcode(必需)
    • Transporter(可选)

步骤

  • 创建 Certificates
  • 创建 Provisioning File
  • 创建 entitlements.plist
  • 配置 tauri.conf.json
  • 更改版本号
  • 构建软件包
  • 添加 Provisioning Profile
  • 签名软件包
  • 上传

创建 Certificates

通过网页创建

Certificates 创建以下两种 Certificates

Certificates

通过 Xcode 创建

Menu: Xcode -> Settings... -> Accounts (Tab) -> Manage Certificates... (Button)

创建 Provisioning File

Profiles 创建并下载 Provisioning File

Distribution Distribution

创建 entitlements.plist

参考内容如下:

     <?xml version="1.0" encoding="UTF-8"?>
     <!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
     <plist version="1.0">
       <dict>
         <key>com.apple.security.app-sandbox</key>
         <true/>
         <key>com.apple.security.network.client</key>
         <true/>
         <key>com.apple.security.network.server</key>
         <true/>
         <key>com.apple.security.files.user-selected.read-write</key>
         <true/>
         <key>com.apple.security.files.downloads.read-write</key>
         <true/>
       </dict>
     </plist>

配置 tauri.conf.json

修改项目文件 src-tauri/tauri.conf.json

修改对应信息:

{
  "package": {
    "productName": "App Name",
    "version": "1.2.3"
  },
  "tauri": {
    "bundle": {
      "copyright": "Copyright © 2023 ...",
      "identifier": "io.domain.app-name",
      "macOS": {
        "entitlements": "../entitlements.plist",
      },
    },
  }
}

更改版本号

文件属性说明
package.json"version": "1.2.3"NPM 版本号
src-tauri/Cargo.tomlversion = "1.2.3"Cargo 构建版本号
src-tauri/tauri.conf.json"version": "1.2.3"App 版本号

构建版本

$ pnpm add -D @tauri-apps/cli
$ pnpm run tauri build --target universal-apple-darwin

# npm 需额外添加 -- 
$ npm run tauri build -- --target universal-apple-darwin

添加 Provisioning Profile

cp embedded.provisionprofile Your_App.app/Contents/embedded.provisionprofile

签名软件包

codesign --deep --force \
	--sign "Apple Distribution: Sivan (12A3BC4DEF)" \
	--entitlements "entitlements.plist" \
	"Your_App.app"

productbuild \
	--sign "3rd Party Mac Developer Installer: Sivan (12A3BC4DEF)" \
	--component "Your_App.app" "/Applications" \
	"Your_App.pkg"

上传

通过 Transporter 上传

image-20240217215546322

All in one

# 修改应用名、项目路径、证书名称
APP_NAME="Your_App"
PROJECT_DIR="/Your/Project/Dir"

APPLE_DISTRIBUTION_CERT="Apple Distribution: Demo (12A3BC4DEF)"
THIRD_PARTY_MAC_DEVELOPER_CERT="3rd Party Mac Developer Installer: Demo (12A3BC4DEF)"


APP_BUNDLE="$APP_NAME.app"
APP_EXECUTABLE="$APP_BUNDLE/Contents/MacOS/$APP_NAME"
APP_PACKAGE="$APP_NAME.pkg"
APP_PATH="$PROJECT_DIR/src-tauri/target/universal-apple-darwin/release/bundle/macos/$APP_BUNDLE"

# Build, Sign, Package
pnpm tauri build --target universal-apple-darwin

cp "embedded.provisionprofile" "$APP_PATH/Contents/embedded.provisionprofile"

codesign --deep --force \
	--sign "$APPLE_DISTRIBUTION_CERT" \
	--entitlements "entitlements.plist" \
	"$APP_PATH"

cd "$PROJECT_DIR/src-tauri/target/universal-apple-darwin/release/bundle/macos"

productbuild \
	--sign "$THIRD_PARTY_MAC_DEVELOPER_CERT" \
	--component "$APP_PATH" "/Applications" \
	"$APP_PACKAGE"

注意事项

  1. Inter 芯片无法构建 ARM 架构软件包,不支持 universal-apple-darwin,脚本需修改为:

    APP_PATH="$PROJECT_DIR/src-tauri/target/release/bundle/macos/$APP_BUNDLE"
    pnpm tauri build
    
  2. ARM 芯片构建 universal-apple-darwin 需先执行:

    rustup target add x86_64-apple-darwin
    
  3. ARM 芯片构建 universal-apple-darwin 报错时,若已安装 x86_64-apple-darwin,仍提示 x86_64-apple-darwin 未安装:

    卸载由 homebrew 安装的 rust,确保系统中仅存在一个 rust

参考链接

  1. Publishing Tauri to Apple's App Store - ThinkGo
  2. docs macOS app store info · Issue #691 · tauri-apps/tauri-docs (github.com)

Comment