Skip to content

Commit 12854a8

Browse files
committed
feat: Add light-client jni bridge for android build
Signed-off-by: Eval EXEC <execvy@gmail.com>
1 parent 778590a commit 12854a8

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

42 files changed

+4911
-7
lines changed

.cargo/config.toml

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
# Android cross-compilation configuration
2+
# The actual toolchain paths are set by build-android.sh via environment variables
3+
4+
[target.aarch64-linux-android]
5+
# Environment variables will set the linker and ar
6+
7+
# Pass Android-specific flags to RocksDB compilation
8+
[env]
9+
# Ensure RocksDB doesn't detect unavailable Android features
10+
ROCKSDB_DISABLE_FALLOCATE = "1"
11+
ROCKSDB_DISABLE_SYNC_FILE_RANGE = "1"
12+
ROCKSDB_DISABLE_PTHREAD_MUTEX_ADAPTIVE_NP = "1"
13+
ROCKSDB_DISABLE_SCHED_GETCPU = "1"
14+
ROCKSDB_DISABLE_AUXV = "1"
15+
ROCKSDB_DISABLE_MALLOC_USABLE_SIZE = "1"

.gitignore

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,3 +7,15 @@
77
/package-lock.json
88
/.vscode
99
/data
10+
11+
# Android/Gradle
12+
android-app/.gradle/
13+
android-app/app/build/
14+
android-app/local.properties
15+
*.apk
16+
*.aab
17+
18+
# Build artifacts
19+
*.o
20+
*.a
21+
*.so

Cargo.lock

Lines changed: 139 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Makefile

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,3 +58,60 @@ coverage-collect-data:
5858

5959
coverage-generate-report:
6060
genhtml -o "${GRCOV_OUTPUT:.info=}" "${GRCOV_OUTPUT}"
61+
62+
63+
android-package:
64+
@echo "======================================"
65+
@echo "Building Android APK"
66+
@echo "======================================"
67+
@echo ""
68+
@echo "📦 Step 1: Building native JNI libraries..."
69+
./build-android-jni.sh
70+
@echo ""
71+
@echo "📦 Step 2: Copying JNI libraries to Android project..."
72+
mkdir -p android-app/app/src/main/jniLibs/arm64-v8a
73+
cp target/aarch64-linux-android/release/libckb_light_client_lib.so android-app/app/src/main/jniLibs/arm64-v8a/
74+
@if [ -f android-app/app/src/main/jniLibs/arm64-v8a/libc++_shared.so ]; then \
75+
echo " ✓ libc++_shared.so already present"; \
76+
else \
77+
echo " ⚠ libc++_shared.so not found (build-android-jni.sh should have copied it)"; \
78+
fi
79+
@echo ""
80+
@echo "📱 Step 3: Building Android APK with Gradle..."
81+
cd android-app && chmod +x gradlew && ANDROID_HOME=$${ANDROID_HOME:-$$HOME/Android/Sdk} ./gradlew assembleDebug
82+
@echo ""
83+
@echo "======================================"
84+
@echo "✅ Build completed successfully!"
85+
@echo "======================================"
86+
@echo ""
87+
@echo "📦 APK location:"
88+
@ls -lh android-app/app/build/outputs/apk/debug/app-debug.apk 2>/dev/null || echo " APK not found"
89+
@echo ""
90+
@echo "To install on device: make android-install"
91+
@echo ""
92+
93+
android-install:
94+
@echo "📲 Installing APK to connected device..."
95+
@if [ ! -f android-app/app/build/outputs/apk/debug/app-debug.apk ]; then \
96+
echo "❌ APK not found. Run 'make android-package' first."; \
97+
exit 1; \
98+
fi
99+
adb install -r android-app/app/build/outputs/apk/debug/app-debug.apk
100+
@echo "✅ APK installed successfully!"
101+
@echo "🚀 Launching app..."
102+
adb shell monkey -p com.nervosnetwork.ckblightclient -c android.intent.category.LAUNCHER 1
103+
@echo ""
104+
@echo "📱 Monitor logs with: adb logcat | grep -i 'ckb\|LightClient'"
105+
@echo ""
106+
107+
android-clean:
108+
@echo "🧹 Cleaning Android build artifacts..."
109+
rm -rf android-app/app/build
110+
rm -rf android-app/app/src/main/jniLibs
111+
rm -rf android-app/.gradle
112+
rm -rf target/aarch64-linux-android
113+
rm -rf target/android-stubs
114+
@echo "✅ Android build artifacts cleaned!"
115+
@echo ""
116+
117+
.PHONY: fmt clippy build build-wasm test test-portable test-wasm coverage-clean coverage-install-tools coverage-run-unittests coverage-collect-data coverage-generate-report android-package android-install android-clean

0 commit comments

Comments
 (0)