fix(build): patch unsigned APK directly instead of re-running Gradle
The previous fix re-ran ./gradlew assembleUniversalRelease to include the missing frontend assets, but BuildTask.kt calls `cargo tauri android android-studio-script` which requires the full Tauri CLI build environment — it fails immediately when invoked standalone. New approach: inject the dist/ files directly into the unsigned APK (which is a ZIP file) using `zip -r`. The existing zipalign + apksigner step re-aligns and signs the result, producing a valid APK. No extra Gradle invocation needed. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -322,21 +322,28 @@ for ARCH in $ARCHS; do
|
|||||||
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
|
# ─── Workaround: Tauri CLI 2.10.x does not copy frontendDist to the
|
||||||
# Android assets folder (gen/android/app/src/main/assets/). The Rust
|
# Android assets folder. The Rust build step writes tauri.conf.json
|
||||||
# build step writes tauri.conf.json there correctly, but index.html
|
# there correctly, but index.html and the JS/CSS assets are never
|
||||||
# and the JS/CSS assets are never transferred, causing the WebView to
|
# transferred, causing the WebView to fail with "Asset not found:
|
||||||
# fail with "Asset not found: index.html" at runtime.
|
# index.html" at runtime.
|
||||||
#
|
#
|
||||||
# Fix: copy dist/ into the assets folder and re-run Gradle so the APK
|
# Fix: inject the missing files directly into the unsigned APK (which
|
||||||
# picks up the frontend. Gradle is incremental here (no Java/Kotlin
|
# is just a ZIP file). The existing zipalign + apksigner step below
|
||||||
# changed) so this extra pass takes < 30s.
|
# handles realignment and signing, so this produces a valid APK.
|
||||||
ANDROID_ASSETS="gen/android/app/src/main/assets"
|
# Re-running Gradle is NOT used here because the Gradle Rust build
|
||||||
if [ ! -f "$ANDROID_ASSETS/index.html" ]; then
|
# task (BuildTask.kt) calls `cargo tauri android android-studio-script`
|
||||||
echo ">>> frontend assets missing from Android project — copying dist/ and repackaging"
|
# which requires the full Tauri CLI environment and fails standalone.
|
||||||
mkdir -p "$ANDROID_ASSETS"
|
UNSIGNED_APK_PATH="gen/android/app/build/outputs/apk/universal/release/app-universal-release-unsigned.apk"
|
||||||
cp -r /build/source/desktop/dist/. "$ANDROID_ASSETS/"
|
if [ -f "$UNSIGNED_APK_PATH" ] && ! unzip -l "$UNSIGNED_APK_PATH" 2>/dev/null | grep -q "assets/index.html"; then
|
||||||
echo ">>> re-running Gradle assembleUniversalRelease"
|
echo ">>> frontend assets missing from APK — patching unsigned APK directly"
|
||||||
(cd gen/android && ./gradlew assembleUniversalRelease 2>&1 | tail -15)
|
PATCH_DIR="/tmp/apk-frontend-patch-$$"
|
||||||
|
rm -rf "$PATCH_DIR"
|
||||||
|
mkdir -p "$PATCH_DIR/assets"
|
||||||
|
cp -r /build/source/desktop/dist/. "$PATCH_DIR/assets/"
|
||||||
|
(cd "$PATCH_DIR" && zip -r /build/source/desktop/src-tauri/"$UNSIGNED_APK_PATH" assets/)
|
||||||
|
rm -rf "$PATCH_DIR"
|
||||||
|
echo ">>> APK patched: $(ls -lh "$UNSIGNED_APK_PATH" | awk '{print $5}')"
|
||||||
|
echo ">>> assets in APK: $(unzip -l "$UNSIGNED_APK_PATH" | grep 'assets/' | wc -l) entries"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# Copy produced APK with arch suffix
|
# Copy produced APK with arch suffix
|
||||||
|
|||||||
Reference in New Issue
Block a user