church-core/generate_kotlin_bindings.sh
RTSDA 4d6b23beb3
Some checks are pending
iOS UniFFI Build / build-ios (push) Waiting to run
Initial commit: Church Core Rust library
Add church management API library with cross-platform support for iOS, Android, and WASM.
Features include event management, bulletin handling, contact forms, and authentication.
2025-08-16 19:25:01 -04:00

144 lines
4.4 KiB
Bash
Executable file

#!/bin/bash
# Generate Kotlin bindings only (without native compilation)
# This gives you the Kotlin interface code to use when you set up Android development
set -e
echo "🤖 Generating Kotlin bindings for Android..."
# Clean previous Android bindings
echo "🧹 Cleaning previous Android bindings..."
rm -rf bindings/android/
mkdir -p bindings/android
# Install uniffi_bindgen if not present
if ! command -v uniffi-bindgen &> /dev/null; then
echo "📦 Installing uniffi_bindgen..."
cargo install uniffi_bindgen --bin uniffi-bindgen
fi
echo "⚡ Generating Kotlin bindings..."
# Use an existing iOS library file for binding generation (they're compatible)
if [ -f "bindings/ios/libchurch_core_device.a" ]; then
LIB_FILE="bindings/ios/libchurch_core_device.a"
elif [ -f "target/aarch64-apple-ios/release/libchurch_core.a" ]; then
LIB_FILE="target/aarch64-apple-ios/release/libchurch_core.a"
else
echo "❌ No existing library found. Please run ./build_ios.sh first."
exit 1
fi
# Generate Kotlin bindings using uniffi_bindgen
uniffi-bindgen generate \
src/church_core.udl \
--language kotlin \
--out-dir bindings/android \
--lib-file "$LIB_FILE"
echo "📦 Creating Android integration README..."
cat > bindings/android/README.md << 'EOF'
# Church Core Android Bindings
This directory contains the generated Kotlin bindings for the church-core Rust crate.
## Files:
- `uniffi/church_core/` - Generated Kotlin bindings
## What's Missing:
- Native libraries (.so files) - You need to compile these with Android NDK
- JNI library structure - Will be created when you compile native libraries
## To Complete Android Setup:
### 1. Install Android Development Tools:
```bash
# Install Android SDK/NDK (via Android Studio or command line tools)
# Set environment variables:
export ANDROID_SDK_ROOT=/path/to/android/sdk
export ANDROID_NDK_HOME=$ANDROID_SDK_ROOT/ndk/[version]
```
### 2. Install cargo-ndk:
```bash
cargo install cargo-ndk
```
### 3. Build native libraries:
```bash
# From church-core directory
cargo ndk --target arm64-v8a --platform 21 build --release --features uniffi
cargo ndk --target armeabi-v7a --platform 21 build --release --features uniffi
cargo ndk --target x86_64 --platform 21 build --release --features uniffi
cargo ndk --target x86 --platform 21 build --release --features uniffi
```
### 4. Create JNI structure:
```bash
mkdir -p jniLibs/{arm64-v8a,armeabi-v7a,x86_64,x86}
cp target/aarch64-linux-android/release/libchurch_core.so jniLibs/arm64-v8a/
cp target/armv7-linux-androideabi/release/libchurch_core.so jniLibs/armeabi-v7a/
cp target/x86_64-linux-android/release/libchurch_core.so jniLibs/x86_64/
cp target/i686-linux-android/release/libchurch_core.so jniLibs/x86/
```
## Integration in Android Project:
### 1. Add JNA dependency to your `build.gradle`:
```gradle
implementation 'net.java.dev.jna:jna:5.13.0@aar'
```
### 2. Copy files to your Android project:
- Copy `uniffi/church_core/` to `src/main/java/`
- Copy `jniLibs/` to `src/main/`
### 3. Usage in Kotlin:
```kotlin
import uniffi.church_core.*
class ChurchRepository {
fun fetchEvents(): String {
return fetchEventsJson()
}
fun fetchSermons(): String {
return fetchSermonsJson()
}
fun fetchBulletins(): String {
return fetchBulletinsJson()
}
// All other functions from the UDL file are available
}
```
## Functions Available:
All functions defined in `src/church_core.udl` are available in Kotlin:
- `fetchEventsJson()`
- `fetchSermonsJson()`
- `fetchBulletinsJson()`
- `fetchBibleVerseJson(query: String)`
- `fetchRandomBibleVerseJson()`
- `submitContactV2Json(...)`
- `fetchCachedImageBase64(url: String)`
- `getOptimalStreamingUrl(mediaId: String)`
- `parseEventsFromJson(eventsJson: String)`
- `parseSermonsFromJson(sermonsJson: String)`
- And many more...
## Architecture Notes:
- All business logic is in Rust (networking, parsing, validation, etc.)
- Kotlin only handles UI and calls Rust functions
- Same RTSDA architecture as iOS version
- JSON responses from Rust, parse to data classes in Kotlin
EOF
echo "✅ Kotlin bindings generated!"
echo "📁 Generated files in bindings/android/:"
ls -la bindings/android/
echo ""
echo "📖 See bindings/android/README.md for integration instructions"
echo "💡 You'll need Android SDK/NDK to compile the native libraries"
echo "🎯 But the Kotlin interface code is ready to use!"