2023-05-17 21:06:02 +03:00
|
|
|
#!/bin/bash
|
|
|
|
|
2024-10-26 02:17:28 +03:00
|
|
|
usage="Usage: android.sh [type] [platform|version]\n - type: 'build', 'release'\n - platform, for 'build' type: 'v7', 'v8', 'x86'\n - optional version for 'release' (needed on MacOS), example: '0.2.2'"
|
2023-05-17 21:06:02 +03:00
|
|
|
case $1 in
|
2024-09-14 01:47:06 +03:00
|
|
|
build|release)
|
2023-05-17 21:06:02 +03:00
|
|
|
;;
|
|
|
|
*)
|
2023-07-13 18:44:37 +03:00
|
|
|
printf "$usage"
|
2023-05-17 21:06:02 +03:00
|
|
|
exit 1
|
|
|
|
esac
|
|
|
|
|
2024-09-14 01:47:06 +03:00
|
|
|
if [[ $1 == "build" ]]; then
|
|
|
|
case $2 in
|
|
|
|
v7|v8|x86)
|
|
|
|
;;
|
|
|
|
*)
|
|
|
|
printf "$usage"
|
|
|
|
exit 1
|
|
|
|
esac
|
|
|
|
fi
|
2023-07-13 18:44:37 +03:00
|
|
|
|
2024-06-19 15:40:07 +03:00
|
|
|
# Setup build directory
|
2024-10-12 15:33:23 +03:00
|
|
|
BASEDIR=$(cd "$(dirname "$0")" && pwd)
|
|
|
|
cd "${BASEDIR}" || exit 1
|
2024-06-19 15:40:07 +03:00
|
|
|
cd ..
|
|
|
|
|
2024-09-14 01:47:06 +03:00
|
|
|
# Install platforms and tools
|
|
|
|
rustup target add armv7-linux-androideabi
|
|
|
|
rustup target add aarch64-linux-android
|
|
|
|
rustup target add x86_64-linux-android
|
|
|
|
cargo install cargo-ndk
|
2023-07-13 18:44:37 +03:00
|
|
|
|
2024-09-14 13:07:48 +03:00
|
|
|
success=1
|
2023-07-13 18:44:37 +03:00
|
|
|
|
2024-09-14 01:47:06 +03:00
|
|
|
### Build native code
|
|
|
|
function build_lib() {
|
2024-10-12 15:33:23 +03:00
|
|
|
[[ $1 == "v7" ]] && arch=armeabi-v7a
|
|
|
|
[[ $1 == "v8" ]] && arch=arm64-v8a
|
|
|
|
[[ $1 == "x86" ]] && arch=x86_64
|
2024-04-16 15:24:22 +03:00
|
|
|
|
2024-09-14 01:47:06 +03:00
|
|
|
sed -i -e 's/"rlib"/"cdylib","rlib"/g' Cargo.toml
|
2024-07-02 16:40:07 +03:00
|
|
|
|
2024-09-14 01:47:06 +03:00
|
|
|
# Fix for https://stackoverflow.com/questions/57193895/error-use-of-undeclared-identifier-pthread-mutex-robust-cargo-build-liblmdb-s
|
2024-10-12 15:33:23 +03:00
|
|
|
# Uncomment lines below for the 1st build:
|
|
|
|
#export CPPFLAGS="-DMDB_USE_ROBUST=0" && export CFLAGS="-DMDB_USE_ROBUST=0"
|
|
|
|
#cargo ndk -t ${arch} build --profile release-apk
|
|
|
|
#unset CPPFLAGS && unset CFLAGS
|
|
|
|
cargo ndk -t "${arch}" -o android/app/src/main/jniLibs build --profile release-apk
|
2024-09-14 01:47:06 +03:00
|
|
|
if [ $? -eq 0 ]
|
|
|
|
then
|
|
|
|
success=1
|
2024-10-12 19:58:14 +03:00
|
|
|
else
|
|
|
|
success=0
|
2024-09-14 01:47:06 +03:00
|
|
|
fi
|
2024-07-02 16:40:07 +03:00
|
|
|
|
2024-09-14 01:47:06 +03:00
|
|
|
sed -i -e 's/"cdylib","rlib"/"rlib"/g' Cargo.toml
|
2024-10-12 15:33:23 +03:00
|
|
|
rm -f Cargo.toml-e
|
2024-09-14 01:47:06 +03:00
|
|
|
}
|
2024-07-02 16:40:07 +03:00
|
|
|
|
2024-09-14 01:47:06 +03:00
|
|
|
### Build application
|
|
|
|
function build_apk() {
|
2024-10-12 15:33:23 +03:00
|
|
|
cd android || exit 1
|
2024-09-14 01:47:06 +03:00
|
|
|
./gradlew clean
|
2024-09-14 13:07:48 +03:00
|
|
|
# Build signed apk if keystore exists
|
|
|
|
if [ ! -f keystore.properties ]; then
|
|
|
|
./gradlew assembleRelease
|
|
|
|
apk_path=app/build/outputs/apk/release/app-release.apk
|
|
|
|
else
|
|
|
|
./gradlew assembleSignedRelease
|
|
|
|
apk_path=app/build/outputs/apk/signedRelease/app-signedRelease.apk
|
|
|
|
fi
|
2024-06-27 12:30:51 +03:00
|
|
|
|
2024-09-14 13:07:48 +03:00
|
|
|
if [[ $1 == "" ]]; then
|
|
|
|
# Launch application at all connected devices.
|
|
|
|
for SERIAL in $(adb devices | grep -v List | cut -f 1);
|
|
|
|
do
|
2024-10-12 15:33:23 +03:00
|
|
|
adb -s "$SERIAL" install ${apk_path}
|
2024-09-14 13:07:48 +03:00
|
|
|
sleep 1s
|
2024-10-12 15:33:23 +03:00
|
|
|
adb -s "$SERIAL" shell am start -n mw.gri.android/.MainActivity;
|
2024-09-14 13:07:48 +03:00
|
|
|
done
|
|
|
|
else
|
2024-10-26 02:17:28 +03:00
|
|
|
if [[ "$OSTYPE" != "darwin"* ]]; then
|
|
|
|
version=$(grep -m 1 -Po 'version = "\K[^"]*' Cargo.toml)
|
|
|
|
else
|
|
|
|
version=v$2
|
|
|
|
fi
|
2024-09-14 12:12:50 +03:00
|
|
|
# Setup release file name
|
|
|
|
name=grim-${version}-android-$1.apk
|
2024-09-14 13:07:48 +03:00
|
|
|
[[ $1 == "arm" ]] && name=grim-${version}-android.apk
|
2024-10-12 15:33:23 +03:00
|
|
|
rm -f "${name}"
|
|
|
|
mv ${apk_path} "${name}"
|
2024-09-14 12:12:50 +03:00
|
|
|
|
|
|
|
# Calculate checksum
|
2024-09-14 13:07:48 +03:00
|
|
|
checksum=grim-${version}-android-$1-sha256sum.txt
|
|
|
|
[[ $1 == "arm" ]] && checksum=grim-${version}-android-sha256sum.txt
|
2024-10-12 15:33:23 +03:00
|
|
|
rm -f "${checksum}"
|
|
|
|
sha256sum "${name}" > "${checksum}"
|
2024-09-14 01:47:06 +03:00
|
|
|
fi
|
2024-06-27 12:30:51 +03:00
|
|
|
|
2024-09-14 01:47:06 +03:00
|
|
|
cd ..
|
|
|
|
}
|
|
|
|
|
|
|
|
rm -rf android/app/src/main/jniLibs/*
|
2024-06-27 12:30:51 +03:00
|
|
|
|
2024-09-14 01:47:06 +03:00
|
|
|
if [[ $1 == "build" ]]; then
|
2024-10-12 15:33:23 +03:00
|
|
|
build_lib "$2"
|
2024-09-14 01:47:06 +03:00
|
|
|
[ $success -eq 1 ] && build_apk
|
|
|
|
else
|
2024-09-14 12:12:50 +03:00
|
|
|
rm -rf target/release-apk
|
|
|
|
rm -rf target/aarch64-linux-android
|
|
|
|
rm -rf target/x86_64-linux-android
|
|
|
|
rm -rf target/armv7-linux-androideabi
|
|
|
|
|
2024-09-14 01:47:06 +03:00
|
|
|
build_lib "v7"
|
|
|
|
[ $success -eq 1 ] && build_lib "v8"
|
2024-10-26 02:17:28 +03:00
|
|
|
[ $success -eq 1 ] && build_apk "arm" "$2"
|
2024-09-14 01:47:06 +03:00
|
|
|
rm -rf android/app/src/main/jniLibs/*
|
|
|
|
[ $success -eq 1 ] && build_lib "x86"
|
2024-10-26 02:17:28 +03:00
|
|
|
[ $success -eq 1 ] && build_apk "x86_64" "$2"
|
2023-04-10 16:02:53 +03:00
|
|
|
fi
|