2022-11-15 20:29:58 -05:00
# bdk-android
2022-11-30 12:20:48 -05:00
This project builds an .aar package for the Android platform that provide Kotlin language bindings for the [`bdk` ] library. The Kotlin language bindings are created by the [`bdk-ffi` ] project which is included in the root of this repository.
2022-11-15 20:29:58 -05:00
## How to Use
2022-11-30 12:20:48 -05:00
To use the Kotlin language bindings for [`bdk` ] in your Android project add the following to your gradle dependencies:
```kotlin
2022-11-15 20:29:58 -05:00
repositories {
mavenCentral()
}
2023-09-06 14:13:15 -04:00
dependencies {
implementation("org.bitcoindevkit:bdk-android:< version > ")
2022-11-15 20:29:58 -05:00
}
```
2022-11-30 12:20:48 -05:00
### Snapshot releases
To use a snapshot release, specify the snapshot repository url in the `repositories` block and use the snapshot version in the `dependencies` block:
```kotlin
repositories {
maven("https://s01.oss.sonatype.org/content/repositories/snapshots/")
}
2023-09-06 14:13:15 -04:00
dependencies {
implementation("org.bitcoindevkit:bdk-android:< version-SNAPSHOT > ")
2022-11-30 12:20:48 -05:00
}
```
2022-11-15 20:29:58 -05:00
### Example Projects
2023-11-16 09:40:52 -06:00
* [bdk-kotlin-example-wallet ](https://github.com/bitcoindevkit/bdk-kotlin-example-wallet )
2022-11-15 20:29:58 -05:00
* [Devkit Wallet ](https://github.com/thunderbiscuit/devkit-wallet )
* [Padawan Wallet ](https://github.com/thunderbiscuit/padawan-wallet )
### How to build
2024-03-28 13:05:07 -04:00
_Note that Kotlin version `1.9.23` or later is required to build the library._
2022-11-15 20:29:58 -05:00
1. Clone this repository.
```shell
git clone https://github.com/bitcoindevkit/bdk-ffi
```
2023-06-15 10:57:53 -04:00
2. Follow the "General" bdk-ffi ["Getting Started (Developer)"] instructions.
2023-11-09 15:08:14 -06:00
3. Install Rust (note that we are currently building using Rust 1.73.0):
2023-06-15 10:57:53 -04:00
```shell
curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh
2023-11-09 15:08:14 -06:00
rustup default 1.73.0
2023-06-15 10:57:53 -04:00
```
2022-11-15 20:29:58 -05:00
4. Install required targets
2023-06-15 10:57:53 -04:00
```sh
rustup target add x86_64-linux-android aarch64-linux-android armv7-linux-androideabi
```
2022-11-15 20:29:58 -05:00
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
2023-11-09 15:08:14 -06:00
build tool), for example (note that currently, NDK version 25.2.9519653 or above is required):
2023-06-15 10:57:53 -04:00
```shell
export ANDROID_SDK_ROOT=~/Android/Sdk
2023-11-09 15:08:14 -06:00
export ANDROID_NDK_ROOT=$ANDROID_SDK_ROOT/ndk/25.2.9519653
2023-06-15 10:57:53 -04:00
```
2022-11-15 20:29:58 -05:00
7. Build kotlin bindings
```sh
# build Android library
cd bdk-android
./gradlew buildAndroidLib
```
2024-03-26 11:22:37 -04:00
1. Start android emulator and run tests
2022-11-15 20:29:58 -05:00
```sh
2022-12-06 15:42:29 -05:00
./gradlew connectedAndroidTest
2022-11-15 20:29:58 -05:00
```
2022-11-30 12:20:48 -05:00
## How to publish to your local Maven repo
2022-11-15 20:29:58 -05:00
```shell
cd bdk-android
2024-04-10 11:37:53 -04:00
./gradlew publishToMavenLocal -P localBuild
2022-11-15 20:29:58 -05:00
```
Note that the commands assume you don't need the local libraries to be signed. If you do wish to sign them, simply set your `~/.gradle/gradle.properties` signing key values like so:
```properties
signing.gnupg.keyName=< YOUR_GNUPG_ID >
signing.gnupg.passphrase=< YOUR_GNUPG_PASSPHRASE >
```
2024-04-10 11:37:53 -04:00
and use the `publishToMavenLocal` task without the `localBuild` flag:
2022-11-15 20:29:58 -05:00
```shell
./gradlew publishToMavenLocal
```
2022-11-30 12:20:48 -05:00
2022-12-14 14:43:39 -05:00
## Known issues
2023-02-17 16:00:41 -05:00
### JNA dependency
2022-12-14 14:43:39 -05:00
Depending on the JVM version you use, you might not have the JNA dependency on your classpath. The exception thrown will be
```shell
class file for com.sun.jna.Pointer not found
```
The solution is to add JNA as a dependency like so:
```kotlin
dependencies {
// ...
implementation("net.java.dev.jna:jna:5.12.1")
}
```
2023-02-17 16:00:41 -05:00
### x86 emulators
For some older versions of macOS, Android Studio will recommend users install the x86 version of the emulator by default. This will not work with the bdk-android library, as we do not support 32-bit architectures. Make sure you install an x86_64 emulator to work with bdk-android.
2022-11-30 12:20:48 -05:00
[`bdk` ]: https://github.com/bitcoindevkit/bdk
[`bdk-ffi` ]: https://github.com/bitcoindevkit/bdk-ffi