From b2ddaa08d512ca2ed9e7df2582b281a9a4c49e11 Mon Sep 17 00:00:00 2001 From: neodiX42 Date: Wed, 2 Nov 2022 19:27:30 +0100 Subject: [PATCH] Add GitHub action to build Tonlib for Android OS (#517) * GitHub action to build native-lib (tonlibjson) JNI library for Android (x86, x86_64, armeabi-v7a, arm64-v8a); Cleanup fossil actions; * update actions/checkout to v3 * update actions/checkout to v3 * silent removal of TonApi.java * remove *.debug files * minor fix * strip files; add README.md * put back ninja * correct spelling * correct README.md * fix README.md --- .github/workflows/tonlib-android-jni.yml | 56 ++++++++++++++++++++++++ example/android/README.md | 48 ++++++++++++++++++++ example/android/build.sh | 3 +- 3 files changed, 105 insertions(+), 2 deletions(-) create mode 100644 .github/workflows/tonlib-android-jni.yml create mode 100644 example/android/README.md diff --git a/.github/workflows/tonlib-android-jni.yml b/.github/workflows/tonlib-android-jni.yml new file mode 100644 index 00000000..cdc16841 --- /dev/null +++ b/.github/workflows/tonlib-android-jni.yml @@ -0,0 +1,56 @@ +name: Tonlib Android JNI + +on: [push,workflow_dispatch,workflow_call] + +jobs: + build: + + runs-on: ubuntu-22.04 + + steps: + - name: Check out repository + uses: actions/checkout@v3 + with: + submodules: 'recursive' + + - name: Install libraries + run: | + sudo apt update + sudo apt install -y build-essential git make cmake clang libgflags-dev zlib1g-dev libssl-dev libreadline-dev libmicrohttpd-dev pkg-config libgsl-dev python3 python3-dev ninja-build + + - name: Configure & Build + run: | + wget https://dl.google.com/android/repository/android-ndk-r25b-linux.zip + unzip android-ndk-r25b-linux.zip + export JAVA_AWT_LIBRARY=NotNeeded + export JAVA_JVM_LIBRARY=NotNeeded + export JAVA_INCLUDE_PATH=${JAVA_HOME}/include + export JAVA_AWT_INCLUDE_PATH=${JAVA_HOME}/include + export JAVA_INCLUDE_PATH2=${JAVA_HOME}/include/linux + + export ANDROID_NDK_ROOT=$(pwd)/android-ndk-r25b + export OPENSSL_DIR=$(pwd)/example/android/third_party/crypto + + rm -rf example/android/src/drinkless/org/ton/TonApi.java + cd example/android/ + cmake -GNinja -DTON_ONLY_TONLIB=ON . + ninja prepare_cross_compiling + rm CMakeCache.txt + ./build-all.sh + ../../android-ndk-r25b/toolchains/llvm/prebuilt/linux-x86_64/bin/llvm-strip libs/x86/libnative-lib.so + ../../android-ndk-r25b/toolchains/llvm/prebuilt/linux-x86_64/bin/llvm-strip libs/x86_64/libnative-lib.so + ../../android-ndk-r25b/toolchains/llvm/prebuilt/linux-x86_64/bin/llvm-strip libs/armeabi-v7a/libnative-lib.so + ../../android-ndk-r25b/toolchains/llvm/prebuilt/linux-x86_64/bin/llvm-strip libs/arm64-v8a/libnative-lib.so + find . -name "*.debug" -type f -delete + + - name: Find & copy binaries + run: | + mkdir -p artifacts/tonlib-android-jni + cp example/android/src/drinkless/org/ton/TonApi.java artifacts/tonlib-android-jni/ + cp -R example/android/libs/* artifacts/tonlib-android-jni/ + + - name: Upload artifacts + uses: actions/upload-artifact@master + with: + name: Tonlib JNI libraries for Android + path: artifacts \ No newline at end of file diff --git a/example/android/README.md b/example/android/README.md new file mode 100644 index 00000000..0d10ff1e --- /dev/null +++ b/example/android/README.md @@ -0,0 +1,48 @@ +# Generation of Tonlib libraries for Android OS +**Tl;dr** Download the latest version of Tonlib libraries for Android from TON release page or check the artifacts from [Android JNI GitHub action](https://github.com/ton-blockchain/ton/actions/workflows/tonlib-android-jni.yml). + +## Compile Tonlib for Android manually +Prerequisite: installed Java and set environment variable JAVA_HOME. +```bash +git clone --recursive https://github.com/ton-blockchain/ton.git +cd ton +wget https://dl.google.com/android/repository/android-ndk-r25b-linux.zip +unzip android-ndk-r25b-linux.zip +export JAVA_AWT_LIBRARY=NotNeeded +export JAVA_JVM_LIBRARY=NotNeeded +export JAVA_INCLUDE_PATH=${JAVA_HOME}/include +export JAVA_AWT_INCLUDE_PATH=${JAVA_HOME}/include +export JAVA_INCLUDE_PATH2=${JAVA_HOME}/include/linux + +export ANDROID_NDK_ROOT=$(pwd)/android-ndk-r25b +export OPENSSL_DIR=$(pwd)/example/android/third_party/crypto + +rm -rf example/android/src/drinkless/org/ton/TonApi.java +cd example/android/ +cmake -GNinja -DTON_ONLY_TONLIB=ON . +ninja prepare_cross_compiling +rm CMakeCache.txt +./build-all.sh +``` +# Generation of Tonlib libraries for iOS in Xcode + +1. Clone repository https://github.com/labraburn/tonlib-xcframework +2. Open repository directory in Terminal +3. Run command: +```bash +swift run builder --output ./build --clean +``` +5. Run command: +```bash +echo ./build/TON.xcframework/* | xargs -n 1 cp -R ./Resources/Headers +```` +7. Import **OpenSSL.xcframework** and **TON.xcframework** in XCode in section _"Frameworks, Libraries, and Embedded Content"_ +8. Now you can start using Tonlib client by importing it in C or Objective-C source files: +```objective-c +#import +``` + +# Generation of Tonlib libraries for Desktop applications +You can use Tonlib compiled in an ordinary way for desktop applications. If you use Java you can load the library using JNA. + +The latest Tonlib library can be found among other TON artifacts either on TON release page or inside the [appropriate GitHub action](https://github.com/ton-blockchain/ton/actions/). \ No newline at end of file diff --git a/example/android/build.sh b/example/android/build.sh index aa6dddea..b16a9df9 100755 --- a/example/android/build.sh +++ b/example/android/build.sh @@ -33,8 +33,7 @@ mkdir -p build-$ARCH cd build-$ARCH -cmake .. \ - -DCMAKE_TOOLCHAIN_FILE=${ANDROID_NDK_ROOT}/build/cmake/android.toolchain.cmake -DCMAKE_BUILD_TYPE=Release -GNinja -DANDROID_ABI=${ABI} -DOPENSSL_ROOT_DIR=${OPENSSL_DIR}/${ARCH} -DTON_ARCH="" -DTON_ONLY_TONLIB=ON || exit 1 +cmake .. -DCMAKE_TOOLCHAIN_FILE=${ANDROID_NDK_ROOT}/build/cmake/android.toolchain.cmake -DCMAKE_BUILD_TYPE=Release -GNinja -DANDROID_ABI=${ABI} -DOPENSSL_ROOT_DIR=${OPENSSL_DIR}/${ARCH} -DTON_ARCH="" -DTON_ONLY_TONLIB=ON || exit 1 ninja native-lib || exit 1 popd