]> git.bitcoin.ninja Git - ldk-java/blob - android-build.sh
[TS] Add support for one additional call semantic which is now used
[ldk-java] / android-build.sh
1 #!/bin/bash
2 if [ ! -x "$ANDROID_TOOLCHAIN/bin/clang" ]; then
3         echo "Please set ANDROID_TOOLCHAIN to the path to NDK" > /dev/stderr
4         exit 1
5 fi
6
7 if [ "$1" = "" -o ! -f "$1/lightning/Cargo.toml" ]; then
8         echo "Please set first argument to the path to rust-lightning" > /dev/stderr
9         exit 1
10 fi
11
12 if [ "$2" = "" -o ! -d "$2/lightning-c-bindings" ]; then
13         echo "Please set second argument to the path to ldk-c-bindings" > /dev/stderr
14         exit 1
15 fi
16
17 if [ ! -d "$3" -o ! -f "$3/AndroidManifest.xml" ]; then
18         echo "Please set third argument to the path to ldk-java-bins/android-artifacts" > /dev/stderr
19         exit 1
20 fi
21
22 set -e
23 set -x
24
25 LDK_C_BINDINGS="$(realpath $2)"
26 RUST_LIGHTNING="$(realpath $1)"
27 pushd "$2"
28 export LDK_C_BINDINGS_EXTRA_TARGETS="x86_64-linux-android armv7-linux-androideabi aarch64-linux-android"
29 export LDK_C_BINDINGS_EXTRA_TARGET_CCS="x86_64-linux-android24-clang armv7a-linux-androideabi24-clang aarch64-linux-android24-clang"
30 ./genbindings.sh "$RUST_LIGHTNING" true
31 popd
32
33 export PATH=$PATH:$ANDROID_TOOLCHAIN/bin
34 export SYSROOT=$ANDROID_TOOLCHAIN/sysroot/
35
36 # Remove any non-Android libraries installed locally
37 rm -fr src/main/resources
38
39 EXTRA_TARGETS=( $LDK_C_BINDINGS_EXTRA_TARGETS )
40 EXTRA_TARGET_CCS=( $LDK_C_BINDINGS_EXTRA_TARGET_CCS )
41 TARGET_CPUS=( "sandybridge" "generic" "generic" )
42 STRIPS=( "x86_64-linux-android-strip" "arm-linux-androideabi-strip" "aarch64-linux-android-strip" )
43 for IDX in ${!EXTRA_TARGETS[@]}; do
44         export CC="${EXTRA_TARGET_CCS[$IDX]}"
45         export LDK_TARGET="${EXTRA_TARGETS[$IDX]}"
46         export LDK_TARGET_CPU="${TARGET_CPUS[$IDX]}"
47         # Note that we expect to often fail here if we don't have wasm32 bins in the C bindings dir
48         ./genbindings.sh "$LDK_C_BINDINGS" "-lm -llog -I$SYSROOT/usr/include/" false true || echo
49         ${STRIPS[$IDX]} liblightningjni_release_${LDK_TARGET}.so
50 done
51
52 export LC_ALL=C
53
54 echo "Need local deterministic ldk-java-classes.jar"
55 ls ldk-java-classes.jar
56
57 rm -rf aar
58 mkdir aar
59 cp -r "$3/"* ./aar/
60 mkdir -p ./aar/jni/{armeabi-v7a,arm64-v8a,x86_64}
61
62 cp liblightningjni_release_aarch64-linux-android.so ./aar/jni/arm64-v8a/liblightningjni.so
63 cp liblightningjni_release_armv7-linux-androideabi.so ./aar/jni/armeabi-v7a/liblightningjni.so
64 cp liblightningjni_release_x86_64-linux-android.so ./aar/jni/x86_64/liblightningjni.so
65 cp ldk-java-classes.jar ./aar/classes.jar
66
67 rm -f LDK-release.aar
68 cd ./aar
69 find . | sort > ../sources-zip-files.txt
70 touch -d "2021-01-01 00:00 UTC" $(cat ../sources-zip-files.txt)
71 cat ../sources-zip-files.txt | zip -X@ ../LDK-release.aar
72 cd ..
73 rm -r aar