Skip to content

Commit

Permalink
build: stop build if android ndk root is not defined for android lib
Browse files Browse the repository at this point in the history
  • Loading branch information
thunderbiscuit committed Apr 30, 2024
1 parent f31678b commit d4736a6
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 25 deletions.
11 changes: 8 additions & 3 deletions bdk-android/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
@@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,11 @@ internal class UniFfiAndroidPlugin : Plugin<Project> {
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<Exec>("buildAndroidAarch64Binary") {

Expand All @@ -26,13 +31,6 @@ internal class UniFfiAndroidPlugin : Plugin<Project> {
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"),
Expand All @@ -56,13 +54,6 @@ internal class UniFfiAndroidPlugin : Plugin<Project> {
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"),
Expand All @@ -86,13 +77,6 @@ internal class UniFfiAndroidPlugin : Plugin<Project> {
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"),
Expand Down

0 comments on commit d4736a6

Please sign in to comment.