From d4736a64d19225990d0dbefff9cd857aa1652f87 Mon Sep 17 00:00:00 2001 From: thunderbiscuit Date: Tue, 30 Apr 2024 10:38:07 -0400 Subject: [PATCH] build: stop build if android ndk root is not defined for android lib --- bdk-android/README.md | 11 +++++--- .../kotlin/org/bitcoindevkit/plugins/Enums.kt | 1 - .../plugins/UniFfiAndroidPlugin.kt | 26 ++++--------------- 3 files changed, 13 insertions(+), 25 deletions(-) diff --git a/bdk-android/README.md b/bdk-android/README.md index 3ee70899..ae864d51 100644 --- a/bdk-android/README.md +++ b/bdk-android/README.md @@ -48,12 +48,17 @@ rustup default 1.77.1 rustup target add x86_64-linux-android aarch64-linux-android armv7-linux-androideabi ``` 5. Install Android SDK and Build-Tools for API level 30+ -6. Setup `$ANDROID_SDK_ROOT` and `$ANDROID_NDK_ROOT` path variables (which are required by the - build tool), for example (note that currently, NDK version 25.2.9519653 or above is required): +6. Setup `ANDROID_SDK_ROOT` and `ANDROID_NDK_ROOT` path variables which are required by the build tool. Note that currently, NDK version 25.2.9519653 or above is required. For example: ```shell -export ANDROID_SDK_ROOT=~/Android/Sdk +# macOS +export ANDROID_SDK_ROOT=~/Library/Android/sdk +export ANDROID_NDK_ROOT=$ANDROID_SDK_ROOT/ndk/25.2.9519653 + +# linux +export ANDROID_SDK_ROOT=/usr/local/lib/android/sdk export ANDROID_NDK_ROOT=$ANDROID_SDK_ROOT/ndk/25.2.9519653 ``` + 7. Build kotlin bindings ```sh # build Android library diff --git a/bdk-android/plugins/src/main/kotlin/org/bitcoindevkit/plugins/Enums.kt b/bdk-android/plugins/src/main/kotlin/org/bitcoindevkit/plugins/Enums.kt index 8f586b65..6e7256cb 100644 --- a/bdk-android/plugins/src/main/kotlin/org/bitcoindevkit/plugins/Enums.kt +++ b/bdk-android/plugins/src/main/kotlin/org/bitcoindevkit/plugins/Enums.kt @@ -1,6 +1,5 @@ package org.bitcoindevkit.plugins - val operatingSystem: OS = when { System.getProperty("os.name").contains("mac", ignoreCase = true) -> OS.MAC System.getProperty("os.name").contains("linux", ignoreCase = true) -> OS.LINUX diff --git a/bdk-android/plugins/src/main/kotlin/org/bitcoindevkit/plugins/UniFfiAndroidPlugin.kt b/bdk-android/plugins/src/main/kotlin/org/bitcoindevkit/plugins/UniFfiAndroidPlugin.kt index a16a5ff0..b43d2633 100644 --- a/bdk-android/plugins/src/main/kotlin/org/bitcoindevkit/plugins/UniFfiAndroidPlugin.kt +++ b/bdk-android/plugins/src/main/kotlin/org/bitcoindevkit/plugins/UniFfiAndroidPlugin.kt @@ -17,6 +17,11 @@ internal class UniFfiAndroidPlugin : Plugin { OS.OTHER -> throw Error("Cannot build Android library from current architecture") } + // if ANDROID_NDK_ROOT is not set, stop build + if (System.getenv("ANDROID_NDK_ROOT") == null) { + throw IllegalStateException("ANDROID_NDK_ROOT environment variable is not set; cannot build library") + } + // arm64-v8a is the most popular hardware architecture for Android val buildAndroidAarch64Binary by tasks.register("buildAndroidAarch64Binary") { @@ -26,13 +31,6 @@ internal class UniFfiAndroidPlugin : Plugin { executable("cargo") args(cargoArgs) - // if ANDROID_NDK_ROOT is not set then set it to github actions default - if (System.getenv("ANDROID_NDK_ROOT") == null) { - environment( - Pair("ANDROID_NDK_ROOT", "${System.getenv("ANDROID_SDK_ROOT")}/ndk-bundle") - ) - } - environment( // add build toolchain to PATH Pair("PATH", "${System.getenv("PATH")}:${System.getenv("ANDROID_NDK_ROOT")}/toolchains/llvm/prebuilt/$llvmArchPath/bin"), @@ -56,13 +54,6 @@ internal class UniFfiAndroidPlugin : Plugin { executable("cargo") args(cargoArgs) - // if ANDROID_NDK_ROOT is not set then set it to github actions default - if (System.getenv("ANDROID_NDK_ROOT") == null) { - environment( - Pair("ANDROID_NDK_ROOT", "${System.getenv("ANDROID_SDK_ROOT")}/ndk-bundle") - ) - } - environment( // add build toolchain to PATH Pair("PATH", "${System.getenv("PATH")}:${System.getenv("ANDROID_NDK_ROOT")}/toolchains/llvm/prebuilt/$llvmArchPath/bin"), @@ -86,13 +77,6 @@ internal class UniFfiAndroidPlugin : Plugin { executable("cargo") args(cargoArgs) - // if ANDROID_NDK_ROOT is not set then set it to github actions default - if (System.getenv("ANDROID_NDK_ROOT") == null) { - environment( - Pair("ANDROID_NDK_ROOT", "${System.getenv("ANDROID_SDK_ROOT")}/ndk-bundle") - ) - } - environment( // add build toolchain to PATH Pair("PATH", "${System.getenv("PATH")}:${System.getenv("ANDROID_NDK_ROOT")}/toolchains/llvm/prebuilt/$llvmArchPath/bin"),