Open8
tauri-mobileでwasmを動かす(失敗)
わりといいところまでいったんだけど挫折。そのうち役に立つかもしれないのでメモ
2.0 ベータ版ドキュメント
1.0 正式版ドキュメント
- Android Studio
- Android SDK Platform
- Android SDK Platform-Tools
- NDK (Side by side)
- Android SDK Build-Tools
- Android SDK Command-line Tools
- Java Standard Edition 19
- pnpm
- tauri-cli --version ^2.0.0-beta
- frontend : Tauri in vanilla HTML, CSS and Typescript
Environment & Setup
$ export ANDROID_HOME=$HOME/Android/Sdk
$ export NDK_HOME=$HOME/Android/Sdk/ndk/26.1.10909125
$ export JAVA_HOME=$HOME/OpenJDK/jdk-19
$ pnpm install
$nvm use v20.10.0
$ cargo create-tauri-app --beta
✔ Project name · tauri-mobile-app
✔ Choose which language to use for your frontend · TypeScript / JavaScript - (pnpm, yarn, npm, bun)
✔ Choose your package manager · pnpm
✔ Choose your UI template · Vanilla
✔ Choose your UI flavor · TypeScript
✔ Would you like to setup the project for mobile as well? · yes
Template created! To get started run:
cd tauri-mobile-app
pnpm install
pnpm tauri android init
For Desktop development, run:
pnpm tauri dev
For Android development, run:
pnpm tauri android dev
$ cd tauri-mobile-app/
$ ll
Permissions Size User Group Date Modified Name
.rw-r--r-- 1.5k botamotch wheel 14 2月 11:06 index.html
.rw-r--r-- 478 botamotch wheel 14 2月 11:06 package.json
.rw-r--r-- 376 botamotch wheel 14 2月 11:06 README.md
drwxr-xr-x - botamotch wheel 14 2月 11:06 src
drwxr-xr-x - botamotch wheel 14 2月 11:06 src-tauri
.rw-r--r-- 527 botamotch wheel 14 2月 11:06 tsconfig.json
.rw-r--r-- 865 botamotch wheel 14 2月 11:06 vite.config.ts
Info
$ pnpm tauri info
> tauri-mobile-app@0.0.0 tauri /home/botamotch/Git/botamotch/Rust/tauri-mobile-app
> tauri "info"
[✔] Environment
- OS: Arch Linux Rolling Release X64
✔ webkit2gtk-4.1: 2.42.4
✔ rsvg2: 2.57.1
✔ rustc: 1.75.0 (82e1608df 2023-12-21)
✔ cargo: 1.75.0 (1d8b05cdd 2023-11-20)
✔ rustup: 1.26.0 (2023-11-14)
✔ Rust toolchain: stable-x86_64-unknown-linux-gnu (default)
- node: 20.10.0
- pnpm: 8.15.1
- yarn: 1.22.21
- npm: 10.2.3
- bun: 1.0.17
[-] Packages
- tauri [RUST]: 2.0.0-beta.2
- tauri-build [RUST]: 2.0.0-beta.1
- wry [RUST]: 0.35.2
- tao [RUST]: 0.25.0
- tauri-cli [RUST]: 2.0.0-beta.1
- @tauri-apps/api [NPM]: 2.0.0-beta.0
- @tauri-apps/cli [NPM]: 2.0.0-beta.1
[-] App
- build-type: bundle
- CSP: unset
- frontendDist: ../dist
- devUrl: http://localhost:1420/
- bundler: Vite
Build and Install
$ pnpm tauri android build --debug
$ cd ${SDK platform-tools}
$ ./adb -s ${SERIAL NUMBER} install ${PROJECT}/src-tauri/gen/android/app/build/outputs/apk/universal/debug/app-universal-debug.apk
ここまでならできる。Vannila HTMLをapkにビルドしてインストール。これにwasmを追加しようとすると失敗する
$ cargo new --lib src-game
Created library `src-game` package
$ cd src-game/
src-game/Cargo.toml
[package]
name = "src-game"
version = "0.1.0"
edition = "2021"
[lib]
crate-type = ["cdylib"]
[dependencies]
bevy = "0.12.1"
wasm-bindgen = "0.2.91"
$ wasm-pack build --target web --dev ../static
$ cd ..
$ lt -L 2
drwxr-xr-x - botamotch 14 2月 10:44 .
drwxr-xr-x - botamotch 9 2月 10:44 ├── dist
.rw-r--r-- 8.5k botamotch 9 2月 10:44 │ └──
.rw-r--r-- 845 botamotch 14 2月 10:34 ├── index.html
drwxr-xr-x - botamotch 9 2月 10:02 ├── node_modules
lrwxrwxrwx - botamotch 9 2月 10:02 │ └──
.rw-r--r-- 478 botamotch 9 2月 10:00 ├── package.json
.rw-r--r-- 24k botamotch 9 2月 10:00 ├── pnpm-lock.yaml
.rw-r--r-- 2.0k botamotch 14 2月 10:12 ├── README.md
drwxr-xr-x - botamotch 14 2月 09:52 ├── src
drwxr-xr-x - botamotch 9 2月 10:00 │ ├── assets
.rw-r--r-- 662 botamotch 14 2月 09:52 │ ├── main.ts
.rw-r--r-- 1.6k botamotch 9 2月 10:00 │ └── styles.css
drwxr-xr-x - botamotch 14 2月 10:09 ├── src-game
.rw-r--r-- 96k botamotch 14 2月 09:52 │ ├── Cargo.lock
.rw-r--r-- 248 botamotch 14 2月 09:52 │ ├── Cargo.toml
drwxr-xr-x - botamotch 14 2月 10:11 │ ├── pkg
drwxr-xr-x - botamotch 14 2月 09:52 │ ├── src
drwxr-xr-x - botamotch 14 2月 10:06 │ └── target
drwxr-xr-x - botamotch 14 2月 10:56 ├── src-tauri
.rw-r--r-- 39 botamotch 9 2月 10:00 │ ├── build.rs
.rw-r--r-- 122k botamotch 14 2月 09:52 │ ├── Cargo.lock
.rw-r--r-- 656 botamotch 14 2月 10:44 │ ├── Cargo.toml
drwxr-xr-x - botamotch 9 2月 10:14 │ ├── gen
drwxr-xr-x - botamotch 9 2月 10:00 │ ├── icons
drwxr-xr-x - botamotch 14 2月 09:52 │ ├── src
drwxr-xr-x - botamotch 12 2月 16:19 │ ├── target
.rw-r--r-- 773 botamotch 14 2月 10:56 │ └── tauri.conf.json
drwxr-xr-x - botamotch 14 2月 10:33 ├── static
.rw-r--r-- 225 botamotch 14 2月 10:33 │ ├── package.json
.rw-r--r-- 7.8k botamotch 14 2月 10:33 │ ├── src_game.d.ts
.rw-r--r-- 109k botamotch 14 2月 10:33 │ ├── src_game.js
.rw-r--r-- 100M botamotch 14 2月 10:33 │ ├── src_game_bg.wasm
.rw-r--r-- 7.1k botamotch 14 2月 10:33 │ └── src_game_bg.wasm.d.ts
.rw-r--r-- 527 botamotch 9 2月 10:00 ├── tsconfig.json
.rw-r--r-- 865 botamotch 9 2月 10:00 └── vite.config.ts
static配下のwasmファイルをリソースに追加しようとするところで失敗する。どうやら2.0-alphaの時に発生してたエラーっぽい。全てをプラグインに移行するってどいういうことだ?
tauri.conf.json
{
"productName": "tauri-mobile-app",
"version": "0.0.0",
"identifier": "com.tauri.mobuie.app",
"build": {
},
"app": {
},
"bundle": {
"active": true,
"targets": "all",
"resources": [ "static/*" ],
"icon": [
]
}
}
$ pnpm tauri dev
> tauri-mobile-app@0.0.0 tauri /home/botamotch/Git/botamotch/Rust/tauri-mobile-app
> tauri "dev"
Running BeforeDevCommand (`pnpm dev`)
> tauri-mobile-app@0.0.0 dev /home/botamotch/Git/botamotch/Rust/tauri-mobile-app
> vite
VITE v5.1.0 ready in 115 ms
➜ Local: http://localhost:1420/
Info Watching /home/botamotch/Git/botamotch/Rust/tauri-mobile-app/src-tauri for changes...
Compiling tauri-mobile-app v0.0.0 (/home/botamotch/Git/botamotch/Rust/tauri-mobile-app/src-tauri)
error: failed to run custom build command for `tauri-mobile-app v0.0.0 (/home/botamotch/Git/botamotch/Rust/tauri-mobile-app/src-tauri)`
Caused by:
process didn't exit successfully: `/home/botamotch/Git/botamotch/Rust/tauri-mobile-app/src-tauri/target/debug/build/tauri-mobile-app-7ee2d391a9409e56/build-script-build` (exit status: 1)
--- stdout
cargo:rerun-if-env-changed=TAURI_CONFIG
cargo:rerun-if-changed=tauri.conf.json
cargo:rustc-cfg=desktop
cargo:rustc-env=TAURI_ANDROID_PACKAGE_PREFIX=com_tauri_mobuie
cargo:rustc-cfg=dev
cargo:rerun-if-changed=capabilities
cargo:rustc-env=TAURI_ENV_TARGET_TRIPLE=x86_64-unknown-linux-gnu
path matching static/* not found.
間違えてた。tauri.conf.json
からの相対パスに設定すればビルドはできた。デスクトップでは動いたけどmobileでは動かなかった。
普通のJSを外部から呼ぶ方式でもうまくいってないのでwasmの問題ではないのかもしれない