-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathbuild_android.sh
executable file
·94 lines (75 loc) · 2.33 KB
/
build_android.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
#!/bin/bash
set -e # Exit immediately if a command exits with a non-zero status.
echo "Starting Android build process..."
# Define output directories
BASE_DIR="./bindings/android"
JNILIBS_DIR="$BASE_DIR/jniLibs"
# Create output directories
mkdir -p "$BASE_DIR"
mkdir -p "$JNILIBS_DIR"
# Remove previous build
echo "Removing previous build..."
rm -rf bindings/android/
# Cargo Build
echo "Building Rust libraries..."
cargo build
# Modify Cargo.toml
echo "Updating Cargo.toml..."
sed -i '' 's/crate_type = .*/crate_type = ["cdylib"]/' Cargo.toml
# Build release
echo "Building release version..."
cargo build --release
# Install cargo-ndk if not already installed
if ! command -v cargo-ndk &> /dev/null; then
echo "Installing cargo-ndk..."
cargo install cargo-ndk
fi
# Add Android targets
echo "Adding Android targets..."
rustup target add \
aarch64-linux-android \
armv7-linux-androideabi \
i686-linux-android \
x86_64-linux-android
# Build for all Android architectures
echo "Building for Android architectures..."
cargo ndk \
-o "$JNILIBS_DIR" \
--manifest-path ./Cargo.toml \
-t armeabi-v7a \
-t arm64-v8a \
-t x86 \
-t x86_64 \
build --release
# Generate Kotlin bindings
echo "Generating Kotlin bindings..."
LIBRARY_PATH="./target/release/libpubkycore.dylib"
# Check if the library file exists
if [ ! -f "$LIBRARY_PATH" ]; then
echo "Error: Library file not found at $LIBRARY_PATH"
echo "Available files in target/release:"
ls -l ./target/release/
exit 1
fi
# Create a temporary directory for initial generation
TMP_DIR=$(mktemp -d)
# Generate the bindings to temp directory first
cargo run --bin uniffi-bindgen generate \
--library "$LIBRARY_PATH" \
--language kotlin \
--out-dir "$TMP_DIR"
# Move the Kotlin file from the nested directory to the final location
echo "Moving Kotlin file to final location..."
find "$TMP_DIR" -name "pubkycore.kt" -exec mv {} "$BASE_DIR/" \;
# Clean up temp directory and any remaining uniffi directories
echo "Cleaning up temporary files..."
rm -rf "$TMP_DIR"
rm -rf "$BASE_DIR/uniffi"
# Verify the file was moved correctly
if [ ! -f "$BASE_DIR/pubkycore.kt" ]; then
echo "Error: Kotlin bindings were not moved correctly"
echo "Contents of $BASE_DIR:"
ls -la "$BASE_DIR"
exit 1
fi
echo "Android build process completed successfully!"