Skip to content

Commit 907b442

Browse files
committed
Build package scr for kotlin: aar, updated the folder structure, optimized for smaller release binaries
Signed-off-by: neoz666 <neoz.blockchain@gmail.com>
1 parent 1fe30eb commit 907b442

File tree

19 files changed

+281
-5205
lines changed

19 files changed

+281
-5205
lines changed

.github/workflows/test-kotlin.yml

Lines changed: 25 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
name: Kotlin Tests
1+
name: Android Tests
22

33
on:
44
push:
@@ -34,14 +34,22 @@ jobs:
3434
with:
3535
submodules: recursive
3636

37-
- name: Install Rust toolchain
38-
uses: dtolnay/rust-toolchain@stable
39-
4037
- name: Setup Java
4138
uses: actions/setup-java@v4
4239
with:
4340
distribution: 'temurin'
44-
java-version: '21'
41+
java-version: 21
42+
43+
- name: "Set up Android SDK"
44+
uses: android-actions/setup-android@v3
45+
46+
- name: "Set up Android NDK"
47+
uses: nttld/setup-ndk@v1
48+
with:
49+
ndk-version: r26c
50+
51+
- name: Install Rust toolchain
52+
uses: dtolnay/rust-toolchain@stable
4553

4654
- name: Cache Rust dependencies
4755
uses: actions/cache@v4
@@ -67,11 +75,17 @@ jobs:
6775
restore-keys: |
6876
${{ runner.os }}-gradle-
6977
70-
- name: Build FFI bindings
71-
working-directory: ./ffi-commons
78+
- name: "Build Android library"
79+
working-directory: ./coinswap-kotlin
80+
run: |
81+
chmod +x build-scripts/development/build-dev-linux-x86_64.sh
82+
bash ./scripts/release/build-dev-linux-x86_64.sh
83+
84+
- name: "Enable KVM"
7285
run: |
73-
chmod +x create_bindings.sh
74-
./create_bindings.sh
86+
echo 'KERNEL=="kvm", GROUP="kvm", MODE="0666", OPTIONS+="static_node=kvm"' | sudo tee /etc/udev/rules.d/99-kvm4all.rules
87+
sudo udevadm control --reload-rules
88+
sudo udevadm trigger --name-match=kvm
7589
7690
- name: Setup Docker environment
7791
working-directory: ./ffi-commons
@@ -98,12 +112,12 @@ jobs:
98112
working-directory: ./coinswap-kotlin
99113
run: |
100114
chmod +x gradlew
101-
./gradlew test --tests "coinswap.StandardSwap" --no-daemon --stacktrace
115+
./gradlew :lib:test --tests "coinswap.StandardSwap" --no-daemon --stacktrace
102116
103117
- name: Run Kotlin Taproot Swap Test (P2TR)
104118
working-directory: ./coinswap-kotlin
105119
run: |
106-
./gradlew test --tests "coinswap.TaprootSwap" --no-daemon --stacktrace
120+
./gradlew :lib:test --tests "coinswap.TaprootSwap" --no-daemon --stacktrace
107121
108122
- name: Cleanup Docker
109123
if: always()

README.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
Coinswap FFI provides Foreign Function Interface (FFI) bindings for the [Coinswap](https://github.com/citadel-tech/coinswap) Bitcoin privacy protocol, enabling integration with multiple programming languages and platforms. This repository contains binding implementations for:
1212

1313
### JavaScript/TypeScript
14-
- **[coinswap-js](./coinswap-js)** - Node.js bindings via NAPI-RS for JavaScript/TypeScript applications
14+
- **[coinswap-js](./coinswap-js)** - Node.js bindings for JavaScript/TypeScript applications
1515

1616
### Multi-Language Bindings (via UniFFI)
1717
Generated from **[ffi-commons](./ffi-commons)** - the core UniFFI binding generator:
@@ -23,7 +23,7 @@ Generated from **[ffi-commons](./ffi-commons)** - the core UniFFI binding genera
2323

2424
## Quick Start
2525

26-
### Node.js (NAPI)
26+
### Node.js (Node add-ons)
2727

2828
```bash
2929
cd coinswap-js
@@ -56,7 +56,7 @@ This generates bindings for all supported languages. See individual language REA
5656

5757
### Reference Implementation
5858

59-
The [taker-app](https://github.com/citadel-tech/taker-app) demonstrates a production-ready desktop GUI built with the NAPI bindings, showcasing wallet management, swap execution, market analytics, and UTXO control. Use it as a reference for your own applications.
59+
The [taker-app](https://github.com/citadel-tech/taker-app) demonstrates a production-ready desktop GUI built with the node-addons, showcasing wallet management, swap execution, market analytics, and UTXO control. Use it as a reference for your own applications.
6060

6161
## Requirementss
6262

@@ -67,7 +67,7 @@ The [taker-app](https://github.com/citadel-tech/taker-app) demonstrates a produc
6767

6868
### Platform-Specific
6969

70-
#### NAPI (Node.js)
70+
#### NAPI (Node addons)
7171
- Node.js 18.0.0 or higher
7272
- Build tools: `build-essential`, `automake`, `libtool`
7373

coinswap-kotlin/README.md

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -213,6 +213,23 @@ enum class AddressType {
213213
Complete examples are available in the [`test/`](test/) directory:
214214
- [`AndroidExample.kt`](test/AndroidExample.kt) - Android integration with coroutines
215215

216+
## Testing
217+
218+
The project includes comprehensive test suites in Kotlin:
219+
220+
### Running Tests
221+
222+
```bash
223+
# Run all tests
224+
./gradlew test
225+
226+
# Run Taproot/Legacy swap tests
227+
./gradlew :lib:test --tests "coinswap.StandardSwap"
228+
./gradlew :lib:test --tests "coinswap.TaprootSwap"
229+
```
230+
231+
See the [CI workflow](.github/workflows/test-kotlin.yml) for complete test setup.
232+
216233
## Requirements
217234

218235
### Android
@@ -252,12 +269,11 @@ Build for Android architectures:
252269

253270
```bash
254271
# Add Android targets
255-
rustup target add aarch64-linux-android armv7-linux-androideabi x86_64-linux-android
272+
rustup target add aarch64-linux-android x86_64-linux-android
256273

257274
# Build for all Android architectures
258275
cd ../ffi-commons
259276
cargo build --release --target aarch64-linux-android
260-
cargo build --release --target armv7-linux-androideabi
261277
cargo build --release --target x86_64-linux-android
262278
```
263279

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
#!/bin/bash
2+
3+
# Test/Development build script - builds only x86_64 for Android Studio Emulator
4+
# Use this for fast local testing and development
5+
6+
if [ -z "$ANDROID_NDK_ROOT" ]; then
7+
echo "Error: ANDROID_NDK_ROOT is not defined in your environment"
8+
exit 1
9+
fi
10+
11+
PATH="$ANDROID_NDK_ROOT/toolchains/llvm/prebuilt/linux-x86_64/bin:$PATH"
12+
CFLAGS="-D__ANDROID_MIN_SDK_VERSION__=24"
13+
AR="llvm-ar"
14+
LIB_NAME="libcoinswap_ffi.so"
15+
16+
COMPILATION_TARGET_X86_64="x86_64-linux-android"
17+
RESOURCE_DIR_X86_64="x86_64"
18+
19+
# Move to the Rust library directory
20+
cd ../../ffi-commons || exit
21+
22+
# Install perl and make (required for building vendored OpenSSL)
23+
# Uncomment if not installed: sudo apt-get install -y perl make
24+
25+
rustup target add $COMPILATION_TARGET_X86_64
26+
CC="x86_64-linux-android24-clang" CARGO_TARGET_X86_64_LINUX_ANDROID_LINKER="x86_64-linux-android24-clang" cargo build --target $COMPILATION_TARGET_X86_64
27+
mkdir -p ../coinswap-kotlin/lib/src/main/jniLibs/$RESOURCE_DIR_X86_64/
28+
cargo run --bin uniffi-bindgen generate --library ./target/$COMPILATION_TARGET_X86_64/debug/$LIB_NAME --language kotlin --out-dir ../coinswap-kotlin/lib/src/main/kotlin/ --no-format
29+
cp ./target/$COMPILATION_TARGET_X86_64/debug/$LIB_NAME ../coinswap-kotlin/lib/src/main/jniLibs/$RESOURCE_DIR_X86_64
30+
cp ./target/$COMPILATION_TARGET_X86_64/debug/libcoinswap_ffi.d ../coinswap-kotlin/lib/src/main/jniLibs/$RESOURCE_DIR_X86_64/
31+
cp ./target/debug/uniffi-bindgen ../coinswap-kotlin/lib/src/main/jniLibs/
32+
cp ./target/debug/uniffi-bindgen.d ../coinswap-kotlin/lib/src/main/jniLibs/
33+
34+
echo ""
35+
echo "====================================="
36+
echo "Built for: x86_64"
37+
echo "Binary location: lib/src/main/jniLibs/$RESOURCE_DIR_X86_64/$LIB_NAME"
38+
echo "====================================="
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
#!/bin/bash
2+
3+
# Test/Development build script - builds only x86_64 for Android Studio Emulator
4+
# Use this for fast local testing and development
5+
6+
if [ -z "$ANDROID_NDK_ROOT" ]; then
7+
echo "Error: ANDROID_NDK_ROOT is not defined in your environment"
8+
exit 1
9+
fi
10+
11+
PATH="$ANDROID_NDK_ROOT/toolchains/llvm/prebuilt/darwin-x86_64/bin:$PATH"
12+
CFLAGS="-D__ANDROID_MIN_SDK_VERSION__=24"
13+
AR="llvm-ar"
14+
LIB_NAME="coinswap_ffi.dylib"
15+
16+
COMPILATION_TARGET_X86_64="x86_64-linux-android"
17+
RESOURCE_DIR_X86_64="x86_64"
18+
19+
# Move to the Rust library directory
20+
cd ../../ffi-commons || exit
21+
22+
# Install perl and make (required for building vendored OpenSSL)
23+
# Uncomment if not installed: sudo apt-get install -y perl make
24+
25+
rustup target add $COMPILATION_TARGET_X86_64
26+
CC="x86_64-linux-android24-clang" CARGO_TARGET_X86_64_LINUX_ANDROID_LINKER="x86_64-linux-android24-clang" cargo build --target $COMPILATION_TARGET_X86_64
27+
mkdir -p ../coinswap-kotlin/lib/src/main/jniLibs/$RESOURCE_DIR_X86_64/
28+
cargo run --bin uniffi-bindgen generate --library ./target/$COMPILATION_TARGET_X86_64/debug/$LIB_NAME --language kotlin --out-dir ../coinswap-kotlin/lib/src/main/kotlin/ --no-format
29+
cp ./target/$COMPILATION_TARGET_X86_64/debug/$LIB_NAME ../coinswap-kotlin/lib/src/main/jniLibs/$RESOURCE_DIR_X86_64
30+
cp ./target/$COMPILATION_TARGET_X86_64/debug/$LIB_NAME ../coinswap-kotlin/lib/src/main/jniLibs/$RESOURCE_DIR_X86_64/
31+
cp ./target/debug/uniffi-bindgen ../coinswap-kotlin/lib/src/main/jniLibs/
32+
cp ./target/debug/uniffi-bindgen.d ../coinswap-kotlin/lib/src/main/jniLibs/
33+
34+
echo ""
35+
echo "====================================="
36+
echo "Built for: x86_64"
37+
echo "Binary location: lib/src/main/jniLibs/$RESOURCE_DIR_X86_64/$LIB_NAME"
38+
echo "====================================="
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
#!/bin/bash
2+
3+
if [ -z "$ANDROID_NDK_ROOT" ]; then
4+
echo "Error: ANDROID_NDK_ROOT is not defined in your environment"
5+
exit 1
6+
fi
7+
8+
PATH="$ANDROID_NDK_ROOT/toolchains/llvm/prebuilt/linux-x86_64/bin:$PATH"
9+
CFLAGS="-D__ANDROID_MIN_SDK_VERSION__=24"
10+
AR="llvm-ar"
11+
LIB_NAME="libcoinswap_ffi.so"
12+
13+
COMPILATION_TARGET_ARM64_V8A="aarch64-linux-android"
14+
COMPILATION_TARGET_X86_64="x86_64-linux-android"
15+
RESOURCE_DIR_ARM64_V8A="arm64-v8a"
16+
RESOURCE_DIR_X86_64="x86_64"
17+
18+
# Move to the Rust library directory
19+
cd ../ffi-commons/ || exit
20+
21+
# Install perl and make (required for building vendored OpenSSL)
22+
# Uncomment if not installed: sudo apt-get install -y perl make
23+
24+
rustup target add $COMPILATION_TARGET_ARM64_V8A $COMPILATION_TARGET_X86_64
25+
26+
# Build the binaries
27+
# The CC and CARGO_TARGET_<TARGET>_LINUX_ANDROID_LINKER environment variables must be declared on the same line as the cargo build command
28+
CC="aarch64-linux-android24-clang" CARGO_TARGET_AARCH64_LINUX_ANDROID_LINKER="aarch64-linux-android24-clang" cargo build --profile release-smaller --target $COMPILATION_TARGET_ARM64_V8A
29+
CC="x86_64-linux-android24-clang" CARGO_TARGET_X86_64_LINUX_ANDROID_LINKER="x86_64-linux-android24-clang" cargo build --profile release-smaller --target $COMPILATION_TARGET_X86_64
30+
31+
# Copy the binaries to their respective resource directories
32+
mkdir -p ../coinswap-kotlin/lib/src/main/jniLibs/$RESOURCE_DIR_ARM64_V8A/
33+
mkdir -p ../coinswap-kotlin/lib/src/main/jniLibs/$RESOURCE_DIR_X86_64/
34+
cp ./target/$COMPILATION_TARGET_ARM64_V8A/release-smaller/$LIB_NAME ../coinswap-kotlin/lib/src/main/jniLibs/$RESOURCE_DIR_ARM64_V8A/
35+
cp ./target/$COMPILATION_TARGET_X86_64/release-smaller/$LIB_NAME ../coinswap-kotlin/lib/src/main/jniLibs/$RESOURCE_DIR_X86_64/
36+
37+
cargo run --bin uniffi-bindgen generate --library ./target/$COMPILATION_TARGET_ARM64_V8A/release-smaller/$LIB_NAME --language kotlin --out-dir ../coinswap-kotlin/lib/src/main/kotlin/ --no-format
38+
cp ./target/$COMPILATION_TARGET_ARM64_V8A/release-smaller/libcoinswap_ffi.d ../coinswap-kotlin/lib/src/main/jniLibs/$RESOURCE_DIR_ARM64_V8A/
39+
cp ./target/$COMPILATION_TARGET_X86_64/release-smaller/libcoinswap_ffi.d ../coinswap-kotlin/lib/src/main/jniLibs/$RESOURCE_DIR_X86_64/
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
#!/bin/bash
2+
3+
if [ -z "$ANDROID_NDK_ROOT" ]; then
4+
echo "Error: ANDROID_NDK_ROOT is not defined in your environment"
5+
exit 1
6+
fi
7+
8+
PATH="$ANDROID_NDK_ROOT/toolchains/llvm/prebuilt/darwin-x86_64/bin:$PATH"
9+
CFLAGS="-D__ANDROID_MIN_SDK_VERSION__=24"
10+
AR="llvm-ar"
11+
LIB_NAME="libcoinswap_ffi.dylib"
12+
COMPILATION_TARGET_ARM64_V8A="aarch64-linux-android"
13+
COMPILATION_TARGET_X86_64="x86_64-linux-android"
14+
RESOURCE_DIR_ARM64_V8A="arm64-v8a"
15+
RESOURCE_DIR_X86_64="x86_64"
16+
17+
# Move to the Rust library directory
18+
cd ../ffi-commons/ || exit
19+
20+
# Install perl and make (required for building vendored OpenSSL)
21+
# Uncomment if not installed: sudo apt-get install -y perl make
22+
23+
rustup target add $COMPILATION_TARGET_ARM64_V8A $COMPILATION_TARGET_X86_64
24+
25+
# Build the binaries
26+
# The CC and CARGO_TARGET_<TARGET>_LINUX_ANDROID_LINKER environment variables must be declared on the same line as the cargo build command
27+
CC="aarch64-linux-android24-clang" CARGO_TARGET_AARCH64_LINUX_ANDROID_LINKER="aarch64-linux-android24-clang" cargo build --profile release-smaller --target $COMPILATION_TARGET_ARM64_V8A
28+
CC="x86_64-linux-android24-clang" CARGO_TARGET_X86_64_LINUX_ANDROID_LINKER="x86_64-linux-android24-clang" cargo build --profile release-smaller --target $COMPILATION_TARGET_X86_64
29+
30+
mkdir -p ../coinswap-kotlin/lib/src/main/jniLibs/$RESOURCE_DIR_ARM64_V8A/
31+
mkdir -p ../coinswap-kotlin/lib/src/main/jniLibs/$RESOURCE_DIR_X86_64/
32+
cp ./target/$COMPILATION_TARGET_ARM64_V8A/release-smaller/$LIB_NAME ../coinswap-kotlin/lib/src/main/jniLibs/$RESOURCE_DIR_ARM64_V8A/
33+
cp ./target/$COMPILATION_TARGET_X86_64/release-smaller/$LIB_NAME ../coinswap-kotlin/lib/src/main/jniLibs/$RESOURCE_DIR_X86_64/
34+
35+
cargo run --bin uniffi-bindgen generate --library ./target/$COMPILATION_TARGET_ARM64_V8A/release-smaller/$LIB_NAME --language kotlin --out-dir ../coinswap-kotlin/lib/src/main/kotlin/ --no-format
36+
cp ./target/$COMPILATION_TARGET_ARM64_V8A/release-smaller/$LIB_NAME ../coinswap-kotlin/lib/src/main/jniLibs/$RESOURCE_DIR_ARM64_V8A/
37+
cp ./target/$COMPILATION_TARGET_X86_64/release-smaller/$LIB_NAME ../coinswap-kotlin/lib/src/main/jniLibs/$RESOURCE_DIR_X86_64/
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
#!/bin/bash
2+
3+
if [ -z "$ANDROID_NDK_ROOT" ]; then
4+
echo "Error: ANDROID_NDK_ROOT is not defined in your environment"
5+
exit 1
6+
fi
7+
8+
PATH="$ANDROID_NDK_ROOT/toolchains/llvm/prebuilt/windows-x86_64/bin:$PATH"
9+
CFLAGS="-D__ANDROID_MIN_SDK_VERSION__=24"
10+
AR="llvm-ar"
11+
LIB_NAME="coinswap_ffi.dll"
12+
COMPILATION_TARGET_ARM64_V8A="aarch64-linux-android"
13+
COMPILATION_TARGET_X86_64="x86_64-linux-android"
14+
RESOURCE_DIR_ARM64_V8A="arm64-v8a"
15+
RESOURCE_DIR_X86_64="x86_64"
16+
17+
# Move to the Rust library directory
18+
cd ../ffi-commons/ || exit
19+
20+
# Install perl and make (required for building vendored OpenSSL)
21+
# Uncomment if not installed: sudo apt-get install -y perl make
22+
23+
rustup target add $COMPILATION_TARGET_ARM64_V8A $COMPILATION_TARGET_X86_64
24+
25+
# Build the binaries
26+
# The CC and CARGO_TARGET_<TARGET>_LINUX_ANDROID_LINKER environment variables must be declared on the same line as the cargo build command
27+
CC="aarch64-linux-android24-clang.cmd" CARGO_TARGET_AARCH64_LINUX_ANDROID_LINKER="aarch64-linux-android24-clang.cmd" cargo build --profile release-smaller --target $COMPILATION_TARGET_ARM64_V8A
28+
CC="x86_64-linux-android24-clang.cmd" CARGO_TARGET_X86_64_LINUX_ANDROID_LINKER="x86_64-linux-android24-clang.cmd" cargo build --profile release-smaller --target $COMPILATION_TARGET_X86_64
29+
30+
# Copy the binaries to their respective resource directories
31+
mkdir -p ../coinswap-kotlin/lib/src/main/jniLibs/$RESOURCE_DIR_ARM64_V8A/
32+
mkdir -p ../coinswap-kotlin/lib/src/main/jniLibs/$RESOURCE_DIR_X86_64/
33+
cp ./target/$COMPILATION_TARGET_ARM64_V8A/release-smaller/$LIB_NAME ../coinswap-kotlin/lib/src/main/jniLibs/$RESOURCE_DIR_ARM64_V8A/
34+
cp ./target/$COMPILATION_TARGET_X86_64/release-smaller/$LIB_NAME ../coinswap-kotlin/lib/src/main/jniLibs/$RESOURCE_DIR_X86_64/
35+
36+
cargo run --bin uniffi-bindgen generate --library ./target/$COMPILATION_TARGET_ARM64_V8A/release-smaller/$LIB_NAME --language kotlin --out-dir ../coinswap-kotlin/lib/src/main/kotlin/ --no-format
37+
cp ./target/$COMPILATION_TARGET_ARM64_V8A/release-smaller/$LIB_NAME ../coinswap-kotlin/lib/src/main/jniLibs/$RESOURCE_DIR_ARM64_V8A/
38+
cp ./target/$COMPILATION_TARGET_X86_64/release-smaller/$LIB_NAME ../coinswap-kotlin/lib/src/main/jniLibs/$RESOURCE_DIR_X86_64/
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,12 @@ kotlin {
2929
jvmToolchain(21)
3030
}
3131

32+
java {
33+
toolchain {
34+
languageVersion.set(JavaLanguageVersion.of(21))
35+
}
36+
}
37+
3238
tasks.test {
3339
useJUnitPlatform()
3440

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
# Add project specific ProGuard rules here.
2+
# You can control the set of applied configuration files using the
3+
# proguardFiles setting in build.gradle.
4+
#
5+
# For more details, see
6+
# http://developer.android.com/guide/developing/tools/proguard.html
7+
8+
# If your project uses WebView with JS, uncomment the following
9+
# and specify the fully qualified class name to the JavaScript interface
10+
# class:
11+
#-keepclassmembers class fqcn.of.javascript.interface.for.webview {
12+
# public *;
13+
#}
14+
15+
# Uncomment this to preserve the line number information for
16+
# debugging stack traces.
17+
#-keepattributes SourceFile,LineNumberTable
18+
19+
# If you keep the line number information, uncomment this to
20+
# hide the original source file name.
21+
#-renamesourcefileattribute SourceFile

0 commit comments

Comments
 (0)