Add android aar build and connected device test
This commit is contained in:
parent
f556f611b0
commit
c9e8368694
71
bindings/bdk-kotlin/android/build.gradle
Normal file
71
bindings/bdk-kotlin/android/build.gradle
Normal file
@ -0,0 +1,71 @@
|
|||||||
|
apply plugin: 'com.android.library'
|
||||||
|
apply plugin: 'kotlin-android'
|
||||||
|
apply plugin: 'maven-publish'
|
||||||
|
|
||||||
|
android {
|
||||||
|
compileSdkVersion 30
|
||||||
|
|
||||||
|
defaultConfig {
|
||||||
|
minSdkVersion 21
|
||||||
|
targetSdkVersion 30
|
||||||
|
versionCode 1
|
||||||
|
versionName "1.0"
|
||||||
|
|
||||||
|
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
|
||||||
|
consumerProguardFiles 'consumer-rules.pro'
|
||||||
|
}
|
||||||
|
|
||||||
|
buildTypes {
|
||||||
|
release {
|
||||||
|
minifyEnabled false
|
||||||
|
proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
afterEvaluate {
|
||||||
|
|
||||||
|
publishing {
|
||||||
|
publications {
|
||||||
|
// Creates a Maven publication called "release".
|
||||||
|
release(MavenPublication) {
|
||||||
|
// Applies the component for the release build variant.
|
||||||
|
from components.release
|
||||||
|
|
||||||
|
// You can then customize attributes of the publication as shown below.
|
||||||
|
groupId = 'org.bitcoindevkit'
|
||||||
|
artifactId = 'bdk'
|
||||||
|
version = '0.0.1-SNAPSHOT'
|
||||||
|
}
|
||||||
|
// Creates a Maven publication called “debug”.
|
||||||
|
debug(MavenPublication) {
|
||||||
|
// Applies the component for the debug build variant.
|
||||||
|
from components.debug
|
||||||
|
|
||||||
|
groupId = 'org.bitcoindevkit'
|
||||||
|
artifactId = 'bdk-debug'
|
||||||
|
version = '0.0.1-SNAPSHOT'
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
dependencies {
|
||||||
|
implementation(project(':jvm')) {
|
||||||
|
exclude group: 'net.java.dev.jna', module: 'jna'
|
||||||
|
}
|
||||||
|
|
||||||
|
implementation 'net.java.dev.jna:jna:5.8.0@aar'
|
||||||
|
implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"
|
||||||
|
implementation 'androidx.appcompat:appcompat:1.3.0'
|
||||||
|
implementation 'androidx.core:core-ktx:1.5.0'
|
||||||
|
api "org.slf4j:slf4j-api:1.7.30"
|
||||||
|
|
||||||
|
androidTestImplementation 'com.github.tony19:logback-android:2.0.0'
|
||||||
|
androidTestImplementation(project(':test-fixtures')) {
|
||||||
|
exclude group: 'net.java.dev.jna', module: 'jna'
|
||||||
|
}
|
||||||
|
androidTestImplementation 'androidx.test.ext:junit:1.1.2'
|
||||||
|
androidTestImplementation 'androidx.test.espresso:espresso-core:3.3.0'
|
||||||
|
androidTestImplementation 'org.jetbrains.kotlinx:kotlinx-coroutines-core:1.4.1'
|
||||||
|
}
|
26
bindings/bdk-kotlin/android/proguard-rules.pro
vendored
Normal file
26
bindings/bdk-kotlin/android/proguard-rules.pro
vendored
Normal file
@ -0,0 +1,26 @@
|
|||||||
|
# Add project specific ProGuard rules here.
|
||||||
|
# You can control the set of applied configuration files using the
|
||||||
|
# proguardFiles setting in build.gradle.
|
||||||
|
#
|
||||||
|
# For more details, see
|
||||||
|
# http://developer.android.com/guide/developing/tools/proguard.html
|
||||||
|
|
||||||
|
# If your project uses WebView with JS, uncomment the following
|
||||||
|
# and specify the fully qualified class name to the JavaScript interface
|
||||||
|
# class:
|
||||||
|
#-keepclassmembers class fqcn.of.javascript.interface.for.webview {
|
||||||
|
# public *;
|
||||||
|
#}
|
||||||
|
|
||||||
|
# Uncomment this to preserve the line number information for
|
||||||
|
# debugging stack traces.
|
||||||
|
#-keepattributes SourceFile,LineNumberTable
|
||||||
|
|
||||||
|
# If you keep the line number information, uncomment this to
|
||||||
|
# hide the original source file name.
|
||||||
|
#-renamesourcefileattribute SourceFile
|
||||||
|
|
||||||
|
# for JNA
|
||||||
|
-dontwarn java.awt.*
|
||||||
|
-keep class com.sun.jna.* { *; }
|
||||||
|
-keepclassmembers class * extends com.sun.jna.* { public *; }
|
@ -0,0 +1,14 @@
|
|||||||
|
<configuration>
|
||||||
|
<appender name="logcat" class="ch.qos.logback.classic.android.LogcatAppender">
|
||||||
|
<tagEncoder>
|
||||||
|
<pattern>%logger{12}</pattern>
|
||||||
|
</tagEncoder>
|
||||||
|
<encoder>
|
||||||
|
<pattern>[%-20thread] %msg</pattern>
|
||||||
|
</encoder>
|
||||||
|
</appender>
|
||||||
|
|
||||||
|
<root level="DEBUG">
|
||||||
|
<appender-ref ref="logcat" />
|
||||||
|
</root>
|
||||||
|
</configuration>
|
@ -0,0 +1,21 @@
|
|||||||
|
package org.bitcoindevkit.bdk
|
||||||
|
|
||||||
|
import android.app.Application
|
||||||
|
import android.content.Context.MODE_PRIVATE
|
||||||
|
import androidx.test.core.app.ApplicationProvider
|
||||||
|
import androidx.test.ext.junit.runners.AndroidJUnit4
|
||||||
|
import org.junit.runner.RunWith
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Instrumented test, which will execute on an Android device.
|
||||||
|
*
|
||||||
|
* See [testing documentation](http://d.android.com/tools/testing).
|
||||||
|
*/
|
||||||
|
@RunWith(AndroidJUnit4::class)
|
||||||
|
class AndroidLibTest : LibTest() {
|
||||||
|
override fun getTestDataDir(): String {
|
||||||
|
val context = ApplicationProvider.getApplicationContext<Application>()
|
||||||
|
return context.getDir("bdk-test", MODE_PRIVATE).toString()
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
6
bindings/bdk-kotlin/android/src/main/AndroidManifest.xml
Normal file
6
bindings/bdk-kotlin/android/src/main/AndroidManifest.xml
Normal file
@ -0,0 +1,6 @@
|
|||||||
|
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
|
||||||
|
package="org.bitcoindevkit.bdk">
|
||||||
|
|
||||||
|
<uses-permission android:name="android.permission.INTERNET" />
|
||||||
|
|
||||||
|
</manifest>
|
15
build.sh
15
build.sh
@ -49,6 +49,8 @@ build_kotlin() {
|
|||||||
|
|
||||||
## rust android
|
## rust android
|
||||||
build_android() {
|
build_android() {
|
||||||
|
build_kotlin
|
||||||
|
|
||||||
# If ANDROID_NDK_HOME is not set then set it to github actions default
|
# If ANDROID_NDK_HOME is not set then set it to github actions default
|
||||||
[ -z "$ANDROID_NDK_HOME" ] && export ANDROID_NDK_HOME=$ANDROID_HOME/ndk-bundle
|
[ -z "$ANDROID_NDK_HOME" ] && export ANDROID_NDK_HOME=$ANDROID_HOME/ndk-bundle
|
||||||
|
|
||||||
@ -61,27 +63,27 @@ build_android() {
|
|||||||
# IMPORTANT: make sure every target is not a substring of a different one. We check for them with grep later on
|
# IMPORTANT: make sure every target is not a substring of a different one. We check for them with grep later on
|
||||||
BUILD_TARGETS="${BUILD_TARGETS:-aarch64,armv7,x86_64,i686}"
|
BUILD_TARGETS="${BUILD_TARGETS:-aarch64,armv7,x86_64,i686}"
|
||||||
|
|
||||||
mkdir -p bdk-kotlin/android/src/main/jniLibs/ bdk-kotlin/android/src/main/jniLibs/arm64-v8a bdk-kotlin/android/src/main/jniLibs/x86_64 bdk-kotlin/android/src/main/jniLibs/armeabi-v7a bdk-kotlin/android/src/main/jniLibs/x86
|
mkdir -p bindings/bdk-kotlin/android/src/main/jniLibs/ bindings/bdk-kotlin/android/src/main/jniLibs/arm64-v8a bindings/bdk-kotlin/android/src/main/jniLibs/x86_64 bindings/bdk-kotlin/android/src/main/jniLibs/armeabi-v7a bindings/bdk-kotlin/android/src/main/jniLibs/x86
|
||||||
|
|
||||||
if echo $BUILD_TARGETS | grep "aarch64"; then
|
if echo $BUILD_TARGETS | grep "aarch64"; then
|
||||||
CARGO_TARGET_AARCH64_LINUX_ANDROID_LINKER="aarch64-linux-android21-clang" CC="aarch64-linux-android21-clang" cargo build --target=aarch64-linux-android
|
CARGO_TARGET_AARCH64_LINUX_ANDROID_LINKER="aarch64-linux-android21-clang" CC="aarch64-linux-android21-clang" cargo build --target=aarch64-linux-android
|
||||||
cp target/aarch64-linux-android/debug/libbdk_ffi.so bdk-kotlin/android/src/main/jniLibs/arm64-v8a
|
cp target/aarch64-linux-android/debug/libuniffi_bdk.so bindings/bdk-kotlin/android/src/main/jniLibs/arm64-v8a
|
||||||
fi
|
fi
|
||||||
if echo $BUILD_TARGETS | grep "x86_64"; then
|
if echo $BUILD_TARGETS | grep "x86_64"; then
|
||||||
CARGO_TARGET_X86_64_LINUX_ANDROID_LINKER="x86_64-linux-android21-clang" CC="x86_64-linux-android21-clang" cargo build --target=x86_64-linux-android
|
CARGO_TARGET_X86_64_LINUX_ANDROID_LINKER="x86_64-linux-android21-clang" CC="x86_64-linux-android21-clang" cargo build --target=x86_64-linux-android
|
||||||
cp target/x86_64-linux-android/debug/libbdk_ffi.so bdk-kotlin/android/src/main/jniLibs/x86_64
|
cp target/x86_64-linux-android/debug/libuniffi_bdk.so bindings/bdk-kotlin/android/src/main/jniLibs/x86_64
|
||||||
fi
|
fi
|
||||||
if echo $BUILD_TARGETS | grep "armv7"; then
|
if echo $BUILD_TARGETS | grep "armv7"; then
|
||||||
CARGO_TARGET_ARMV7_LINUX_ANDROIDEABI_LINKER="armv7a-linux-androideabi21-clang" CC="armv7a-linux-androideabi21-clang" cargo build --target=armv7-linux-androideabi
|
CARGO_TARGET_ARMV7_LINUX_ANDROIDEABI_LINKER="armv7a-linux-androideabi21-clang" CC="armv7a-linux-androideabi21-clang" cargo build --target=armv7-linux-androideabi
|
||||||
cp target/armv7-linux-androideabi/debug/libbdk_ffi.so bdk-kotlin/android/src/main/jniLibs/armeabi-v7a
|
cp target/armv7-linux-androideabi/debug/libuniffi_bdk.so bindings/bdk-kotlin/android/src/main/jniLibs/armeabi-v7a
|
||||||
fi
|
fi
|
||||||
if echo $BUILD_TARGETS | grep "i686"; then
|
if echo $BUILD_TARGETS | grep "i686"; then
|
||||||
CARGO_TARGET_I686_LINUX_ANDROID_LINKER="i686-linux-android21-clang" CC="i686-linux-android21-clang" cargo build --target=i686-linux-android
|
CARGO_TARGET_I686_LINUX_ANDROID_LINKER="i686-linux-android21-clang" CC="i686-linux-android21-clang" cargo build --target=i686-linux-android
|
||||||
cp target/i686-linux-android/debug/libbdk_ffi.so bdk-kotlin/android/src/main/jniLibs/x86
|
cp target/i686-linux-android/debug/libuniffi_bdk.so bindings/bdk-kotlin/android/src/main/jniLibs/x86
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# bdk-kotlin aar
|
# bdk-kotlin aar
|
||||||
(cd bdk-kotlin && ./gradlew :android:build && ./gradlew :android:publishToMavenLocal)
|
(cd bindings/bdk-kotlin && ./gradlew :android:build && ./gradlew :android:publishToMavenLocal)
|
||||||
}
|
}
|
||||||
|
|
||||||
OS=$(uname)
|
OS=$(uname)
|
||||||
@ -95,6 +97,7 @@ else
|
|||||||
|
|
||||||
while [ -n "$1" ]; do # while loop starts
|
while [ -n "$1" ]; do # while loop starts
|
||||||
case "$1" in
|
case "$1" in
|
||||||
|
-a) build_android ;;
|
||||||
-k) build_kotlin ;;
|
-k) build_kotlin ;;
|
||||||
-h) help ;;
|
-h) help ;;
|
||||||
*) echo "Option $1 not recognized" ;;
|
*) echo "Option $1 not recognized" ;;
|
||||||
|
8
test.sh
8
test.sh
@ -11,13 +11,18 @@ help()
|
|||||||
echo
|
echo
|
||||||
echo "Syntax: build [-a|h|k|v]"
|
echo "Syntax: build [-a|h|k|v]"
|
||||||
echo "options:"
|
echo "options:"
|
||||||
|
echo "-a Android connected device tests."
|
||||||
echo "-h Print this Help."
|
echo "-h Print this Help."
|
||||||
echo "-k Kotlin tests."
|
echo "-k Kotlin tests."
|
||||||
echo
|
echo
|
||||||
}
|
}
|
||||||
|
|
||||||
test_kotlin() {
|
test_kotlin() {
|
||||||
(cd bindings/bdk-kotlin && rm -rf /tmp/testdb && ./gradlew test -Djna.debug_load=true)
|
(cd bindings/bdk-kotlin && ./gradlew :jvm:test -Djna.debug_load=true)
|
||||||
|
}
|
||||||
|
|
||||||
|
test_android() {
|
||||||
|
(cd bindings/bdk-kotlin && ./gradlew :android:connectedDebugAndroidTest)
|
||||||
}
|
}
|
||||||
|
|
||||||
if [ $1 = "-h" ]
|
if [ $1 = "-h" ]
|
||||||
@ -29,6 +34,7 @@ else
|
|||||||
# optional tests
|
# optional tests
|
||||||
while [ -n "$1" ]; do # while loop starts
|
while [ -n "$1" ]; do # while loop starts
|
||||||
case "$1" in
|
case "$1" in
|
||||||
|
-a) test_android ;;
|
||||||
-h) help ;;
|
-h) help ;;
|
||||||
-k) test_kotlin ;;
|
-k) test_kotlin ;;
|
||||||
*) echo "Option $1 not recognized" ;;
|
*) echo "Option $1 not recognized" ;;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user