From 2b93bd4b45d986f29e4b179467998bddd96edfab Mon Sep 17 00:00:00 2001 From: Siavash Sameni Date: Mon, 25 May 2026 09:51:48 +0400 Subject: [PATCH] fix(build): copy frontendDist to Android assets after cargo tauri build Tauri CLI 2.10.x silently skips copying the frontendDist (desktop/dist/) to gen/android/app/src/main/assets/ on Android builds. The WebView then fails at runtime with "Asset not found: index.html". After cargo tauri android build, check if index.html landed in the Android assets folder. If not (the bug path), copy dist/ manually and re-run ./gradlew assembleUniversalRelease. Gradle is incremental here (no Java/Kotlin changed) so the extra pass takes < 30s. Co-Authored-By: Claude Sonnet 4.6 --- scripts/build-tauri-android.sh | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/scripts/build-tauri-android.sh b/scripts/build-tauri-android.sh index 1be9bf7..c3a5c27 100755 --- a/scripts/build-tauri-android.sh +++ b/scripts/build-tauri-android.sh @@ -321,6 +321,24 @@ for ARCH in $ARCHS; do echo ">>> cargo tauri android build ${PROFILE_FLAG} --target $TARGET --apk" cargo tauri android build ${PROFILE_FLAG} --target "$TARGET" --apk + # ─── Workaround: Tauri CLI 2.10.x does not copy frontendDist to the + # Android assets folder (gen/android/app/src/main/assets/). The Rust + # build step writes tauri.conf.json there correctly, but index.html + # and the JS/CSS assets are never transferred, causing the WebView to + # fail with "Asset not found: index.html" at runtime. + # + # Fix: copy dist/ into the assets folder and re-run Gradle so the APK + # picks up the frontend. Gradle is incremental here (no Java/Kotlin + # changed) so this extra pass takes < 30s. + ANDROID_ASSETS="gen/android/app/src/main/assets" + if [ ! -f "$ANDROID_ASSETS/index.html" ]; then + echo ">>> frontend assets missing from Android project — copying dist/ and repackaging" + mkdir -p "$ANDROID_ASSETS" + cp -r /build/source/desktop/dist/. "$ANDROID_ASSETS/" + echo ">>> re-running Gradle assembleUniversalRelease" + (cd gen/android && ./gradlew assembleUniversalRelease 2>&1 | tail -15) + fi + # Copy produced APK with arch suffix BUILT_APK=$(find gen/android -name "*.apk" -newer "$APK_OUTPUT_DIR" -type f 2>/dev/null | head -1) if [ -z "$BUILT_APK" ]; then