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 <noreply@anthropic.com>
This commit is contained in:
@@ -321,6 +321,24 @@ for ARCH in $ARCHS; do
|
|||||||
echo ">>> cargo tauri android build ${PROFILE_FLAG} --target $TARGET --apk"
|
echo ">>> cargo tauri android build ${PROFILE_FLAG} --target $TARGET --apk"
|
||||||
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
|
# Copy produced APK with arch suffix
|
||||||
BUILT_APK=$(find gen/android -name "*.apk" -newer "$APK_OUTPUT_DIR" -type f 2>/dev/null | head -1)
|
BUILT_APK=$(find gen/android -name "*.apk" -newer "$APK_OUTPUT_DIR" -type f 2>/dev/null | head -1)
|
||||||
if [ -z "$BUILT_APK" ]; then
|
if [ -z "$BUILT_APK" ]; then
|
||||||
|
|||||||
Reference in New Issue
Block a user