Skip to content

armgit / ente

Public Imported from GitHub
0

💚 End-to-end encrypted cloud for everything.

[workflow] fix ensu android bindings and signing flow

Prateek Sunalcdc9a0ce85f4
diff --git a/.github/workflows/ensu-release.yml b/.github/workflows/ensu-release.yml
index abb5e1e3b0..9e78672625 100644
--- a/.github/workflows/ensu-release.yml
+++ b/.github/workflows/ensu-release.yml
@@ -179,37 +179,26 @@ jobs:
keyPassword=${{ secrets.SIGNING_KEY_PASSWORD_ENSU }}
EOF
- - name: Build signed release APK
+ - name: Build signed Android artifacts
if: env.HAS_ANDROID_SIGNING == 'true'
- run: ./gradlew :app-ui:assembleRelease
-
- - name: Build signed release AAB (PlayStore)
- if: env.HAS_ANDROID_SIGNING == 'true' && env.HAS_PLAYSTORE_SERVICE_ACCOUNT == 'true'
- run: ./gradlew :app-ui:bundleRelease
-
- - name: Build unsigned debug APK (fallback)
- if: env.HAS_ANDROID_SIGNING != 'true'
- run: ./gradlew :app-ui:assembleDebug
+ run: |
+ if [ "${HAS_PLAYSTORE_SERVICE_ACCOUNT}" = "true" ]; then
+ ./gradlew :app-ui:assembleRelease :app-ui:bundleRelease
+ else
+ ./gradlew :app-ui:assembleRelease
+ fi
- - name: Collect Android artifacts (signed APK)
+ - name: Collect Android artifacts (signed)
if: env.HAS_ANDROID_SIGNING == 'true'
run: |
mkdir -p artifacts
cp app-ui/build/outputs/apk/release/app-ui-release.apk artifacts/ensu-${{ github.ref_name }}.apk
-
- - name: Collect Android artifacts (signed AAB)
- if: env.HAS_ANDROID_SIGNING == 'true' && env.HAS_PLAYSTORE_SERVICE_ACCOUNT == 'true'
- run: |
- cp app-ui/build/outputs/bundle/release/app-ui-release.aab artifacts/ensu-${{ github.ref_name }}.aab
-
- - name: Collect Android artifacts (unsigned fallback)
- if: env.HAS_ANDROID_SIGNING != 'true'
- run: |
- mkdir -p artifacts
- cp app-ui/build/outputs/apk/debug/app-ui-debug.apk artifacts/ensu-${{ github.ref_name }}-unsigned.apk
+ if [ "${HAS_PLAYSTORE_SERVICE_ACCOUNT}" = "true" ]; then
+ cp app-ui/build/outputs/bundle/release/app-ui-release.aab artifacts/ensu-${{ github.ref_name }}.aab
+ fi
- name: Attach Android artifacts to draft GitHub release
- if: startsWith(github.ref, 'refs/tags/ensu-v')
+ if: startsWith(github.ref, 'refs/tags/ensu-v') && env.HAS_ANDROID_SIGNING == 'true'
uses: ncipollo/release-action@v1
with:
artifacts: "mobile/native/android/apps/ensu/artifacts/*"
@@ -218,6 +207,7 @@ jobs:
updateOnlyUnreleased: true
- name: Upload Android artifacts
+ if: env.HAS_ANDROID_SIGNING == 'true'
uses: actions/upload-artifact@v4
with:
name: ensu-android-artifacts
diff --git a/mobile/native/android/apps/ensu/README.md b/mobile/native/android/apps/ensu/README.md
index d65c1c0fec..1b6f685403 100644
--- a/mobile/native/android/apps/ensu/README.md
+++ b/mobile/native/android/apps/ensu/README.md
@@ -21,15 +21,13 @@ cd mobile/native/android/packages/rust/tool
```
This script produces the JNI `.so` artifacts in `android/packages/rust/src/main/jniLibs/` (including `libcore.so`, `libinference.so`, `libdb.so`, and `libsync.so`).
-The UniFFI Kotlin bindings are generated separately into:
+It also generates the UniFFI Kotlin bindings into:
- `android/apps/ensu/crypto-auth-core/src/main/java/io/ente/ensu/crypto/core.kt`
- `android/packages/rust/src/main/kotlin/io/ente/labs/ensu_db/db.kt`
- `android/packages/rust/src/main/kotlin/io/ente/labs/ensu_sync/sync.kt`
- `android/packages/rust/src/main/kotlin/io/ente/labs/inference_rs/inference.kt`
-These generated files are gitignored. If bindings are missing, rebuild the corresponding
-`rust/uniffi/core` and `rust/uniffi/ensu/*` crates and run `uniffi-bindgen generate` for Kotlin (see each crate’s
-`uniffi.toml` for package names).
+These generated files are gitignored and are refreshed each time `build_android.sh` runs.
### 2. Build Debug APK
diff --git a/mobile/native/android/packages/rust/tool/build_android.sh b/mobile/native/android/packages/rust/tool/build_android.sh
index 0023cd87be..5af8340969 100755
--- a/mobile/native/android/packages/rust/tool/build_android.sh
+++ b/mobile/native/android/packages/rust/tool/build_android.sh
@@ -11,10 +11,52 @@ CHAT_SYNC_UNIFFI_RUST_DIR="$REPO_ROOT/rust/uniffi/ensu/sync"
PATCH_SCRIPT="$REPO_ROOT/rust/ensu/inference/tool/patch_llama_mtmd.sh"
APPLY_LLAMA_MTMD_PATCH="${APPLY_LLAMA_MTMD_PATCH:-1}"
OUT_DIR="$ROOT/src/main/jniLibs"
+CORE_KOTLIN_OUT_DIR="$REPO_ROOT/mobile/native/android/apps/ensu/crypto-auth-core/src/main/java"
+RUST_KOTLIN_OUT_DIR="$ROOT/src/main/kotlin"
SDK_ROOT="${ANDROID_HOME:-${ANDROID_SDK_ROOT:-}}"
NDK_VERSION="${NDK_VERSION:-}"
NDK_ROOT_PATH=""
+if [[ "$(uname -s)" == "Darwin" ]]; then
+ HOST_LIB_EXT="dylib"
+elif [[ "$(uname -s)" == "Linux" ]]; then
+ HOST_LIB_EXT="so"
+else
+ HOST_LIB_EXT="dll"
+fi
+
+ensure_uniffi_bindgen() {
+ if command -v uniffi-bindgen >/dev/null 2>&1; then
+ local version
+ version="$(uniffi-bindgen --version 2>/dev/null || true)"
+ if [[ "$version" == *"0.31."* ]]; then
+ return
+ fi
+ echo "Found incompatible $version, installing uniffi-bindgen 0.31.x"
+ fi
+
+ cargo install --locked --version 0.31.0 uniffi_bindgen
+}
+
+generate_kotlin_bindings() {
+ local crate_dir="$1"
+ local lib_name="$2"
+ local out_dir="$3"
+
+ pushd "$crate_dir" >/dev/null
+ cargo build --release
+
+ local lib_path="$crate_dir/target/release/lib${lib_name}.${HOST_LIB_EXT}"
+ if [[ ! -f "$lib_path" ]]; then
+ echo "Expected $lib_path to exist" >&2
+ exit 1
+ fi
+
+ mkdir -p "$out_dir"
+ uniffi-bindgen generate "$lib_path" --language kotlin --out-dir "$out_dir"
+ popd >/dev/null
+}
+
if [[ -z "$SDK_ROOT" ]]; then
for candidate in "$HOME/Library/Android/sdk" "$HOME/Android/Sdk" "$HOME/Android/sdk"; do
if [[ -d "$candidate" ]]; then
@@ -74,3 +116,19 @@ for CRATE_DIR in "$CORE_UNIFFI_RUST_DIR" "$INFERENCE_UNIFFI_RUST_DIR" "$CHATDB_U
build --release
popd >/dev/null
done
+
+ensure_uniffi_bindgen
+
+# Remove stale generated bindings to avoid duplicate symbol conflicts.
+rm -f "$CORE_KOTLIN_OUT_DIR/io/ente/ensu/crypto/core.kt"
+rm -f "$RUST_KOTLIN_OUT_DIR/io/ente/labs/inference_rs/inference.kt"
+rm -f "$RUST_KOTLIN_OUT_DIR/io/ente/labs/inference_rs/inference_rs_uniffi.kt"
+rm -f "$RUST_KOTLIN_OUT_DIR/io/ente/labs/ensu_db/db.kt"
+rm -f "$RUST_KOTLIN_OUT_DIR/io/ente/labs/llmchat_db/llmchat_db_uniffi.kt"
+rm -f "$RUST_KOTLIN_OUT_DIR/io/ente/labs/ensu_sync/sync.kt"
+rm -f "$RUST_KOTLIN_OUT_DIR/io/ente/labs/llmchat_sync/llmchat_sync_uniffi.kt"
+
+generate_kotlin_bindings "$CORE_UNIFFI_RUST_DIR" "core" "$CORE_KOTLIN_OUT_DIR"
+generate_kotlin_bindings "$INFERENCE_UNIFFI_RUST_DIR" "inference" "$RUST_KOTLIN_OUT_DIR"
+generate_kotlin_bindings "$CHATDB_UNIFFI_RUST_DIR" "db" "$RUST_KOTLIN_OUT_DIR"
+generate_kotlin_bindings "$CHAT_SYNC_UNIFFI_RUST_DIR" "sync" "$RUST_KOTLIN_OUT_DIR"