CakeWallet/scripts/android/build_decred.sh
JoeGruffins 65402ba1eb
dcr: Always fetch the current dir path. (#2242)
* dcr: Always fetch the current dir path.

On ios devices the path will change between updates breaking decred.
Never save the path and always check to ensure it is up to date.
Previous wallets were also not creating a directory in the correct
place. Move those when found.

* Update cw_decred/lib/wallet_service.dart

* dcr: Update libwallet dep.

---------

Co-authored-by: Omar Hatem <omarh.ismail1@gmail.com>
2025-06-17 01:37:49 +03:00

84 lines
2.5 KiB
Bash
Executable file

#!/bin/bash
set -e
cd "$(dirname "$0")"
# . ./config.sh
CW_DECRED_DIR=$(realpath ../..)/cw_decred
LIBWALLET_PATH="${PWD}/decred/libwallet"
LIBWALLET_URL="https://github.com/decred/libwallet.git"
LIBWALLET_VERSION="05f8d7374999400fe4d525eb365c39b77d307b14"
if [[ -e $LIBWALLET_PATH ]]; then
rm -fr $LIBWALLET_PATH || true
fi
mkdir -p $LIBWALLET_PATH || true
git clone $LIBWALLET_URL $LIBWALLET_PATH
cd $LIBWALLET_PATH
git checkout $LIBWALLET_VERSION
if [[ "x$ANDROID_HOME" == "x" ]];
then
echo "ANDROID_HOME is missing, please declare it before building (on macos it is usually $HOME/Library/Android/sdk)"
echo "echo > ~/.zprofile"
echo "echo 'export ANDROID_HOME=\"\$HOME/Library/Android/sdk\" > ~/.zprofile"
exit 1
fi
if [[ "x$ANDROID_NDK_VERSION" == "x" ]];
then
echo "ANDROID_NDK_VERSION is missing, please declare it before building"
echo "You have these versions installed on your system currently:"
ls ${ANDROID_HOME}/ndk/ | cat | awk '{ print "- " $1 }'
echo "echo > ~/.zprofile"
echo "echo 'export ANDROID_NDK_VERSION=..... > ~/.zprofile"
exit 1
fi
export NDK_BIN_PATH="${ANDROID_HOME}/ndk/${ANDROID_NDK_VERSION}/toolchains/llvm/prebuilt/$(uname | tr '[:upper:]' '[:lower:]')-x86_64/bin"
export ANDROID_API_VERSION=21
# export CPATH="$(clang -v 2>&1 | grep "Selected GCC installation" | rev | cut -d' ' -f1 | rev)/include"
for arch in "aarch" "aarch64" "x86_64"
do
TRIPLET=""
TARGET=""
ARCH_ABI=""
case $arch in
"aarch")
TRIPLET="armv7a-linux-androideabi"
TARGET="arm"
ARCH_ABI="armeabi-v7a";;
"aarch64")
TRIPLET="aarch64-linux-android"
TARGET="arm64"
ARCH_ABI="arm64-v8a";;
"x86_64")
TRIPLET="x86_64-linux-android"
TARGET="amd64"
ARCH_ABI="x86_64";;
*)
echo "Unknown arch: $arch"
exit 1;;
esac
# PATH="${TOOLCHAIN_BASE_DIR}_${arch}/bin:${ORIGINAL_PATH}"
if [[ -e ./build ]]; then
rm -fr ./build
fi
CLANG_PATH="${NDK_BIN_PATH}/${TRIPLET}${ANDROID_API_VERSION}-clang"
CGO_ENABLED=1 GOOS=android GOARCH=${TARGET} CC=${CLANG_PATH} CXX=${CLANG_PATH}++ \
go build -v -buildmode=c-shared -o ./build/${TRIPLET}-libdcrwallet.so ./cgo
DEST_LIB_DIR=${CW_DECRED_DIR}/android/libs/${ARCH_ABI}
mkdir -p $DEST_LIB_DIR
cp ${LIBWALLET_PATH}/build/${TRIPLET}-libdcrwallet.so $DEST_LIB_DIR/libdcrwallet.so
done
HEADER_DIR=$CW_DECRED_DIR/lib/api
cp ${LIBWALLET_PATH}/build/${TRIPLET}-libdcrwallet.h $HEADER_DIR/libdcrwallet.h
cd $CW_DECRED_DIR
dart run ffigen