2023-05-17 21:06:02 +03:00
|
|
|
#!/bin/bash
|
|
|
|
|
2024-06-19 15:40:07 +03:00
|
|
|
usage="Usage: build_run_android.sh [type] [platform]\n - type: 'debug', 'release'\n - platform: 'v7', 'v8'"
|
2023-05-17 21:06:02 +03:00
|
|
|
case $1 in
|
|
|
|
debug|release)
|
|
|
|
;;
|
|
|
|
*)
|
2023-07-13 18:44:37 +03:00
|
|
|
printf "$usage"
|
2023-05-17 21:06:02 +03:00
|
|
|
exit 1
|
|
|
|
esac
|
|
|
|
|
2023-07-13 18:44:37 +03:00
|
|
|
case $2 in
|
|
|
|
v7|v8)
|
|
|
|
;;
|
|
|
|
*)
|
|
|
|
printf "$usage"
|
|
|
|
exit 1
|
|
|
|
esac
|
|
|
|
|
2024-06-19 15:40:07 +03:00
|
|
|
# Setup build directory
|
|
|
|
BASEDIR=$(cd $(dirname $0) && pwd)
|
|
|
|
cd ${BASEDIR}
|
|
|
|
cd ..
|
|
|
|
|
2023-07-13 18:44:37 +03:00
|
|
|
# Setup release argument
|
2023-05-17 21:06:02 +03:00
|
|
|
type=$1
|
2024-07-02 16:40:07 +03:00
|
|
|
[[ ${type} == "release" ]] && release_param="--profile release-apk"
|
2023-07-13 18:44:37 +03:00
|
|
|
|
|
|
|
# Setup platform argument
|
2023-07-14 11:48:07 +03:00
|
|
|
[[ $2 == "v7" ]] && arch+=(armeabi-v7a)
|
|
|
|
[[ $2 == "v8" ]] && arch+=(arm64-v8a)
|
2023-07-13 18:44:37 +03:00
|
|
|
|
|
|
|
# Setup platform path
|
2023-07-14 11:48:07 +03:00
|
|
|
[[ $2 == "v7" ]] && platform+=(armv7-linux-androideabi)
|
|
|
|
[[ $2 == "v8" ]] && platform+=(aarch64-linux-android)
|
2023-07-13 18:44:37 +03:00
|
|
|
|
2024-04-16 15:24:22 +03:00
|
|
|
# Install platform
|
|
|
|
[[ $2 == "v7" ]] && rustup target install armv7-linux-androideabi
|
|
|
|
[[ $2 == "v8" ]] && rustup target install aarch64-linux-android
|
|
|
|
|
2024-06-19 15:40:07 +03:00
|
|
|
# Build native code
|
2024-06-27 12:30:51 +03:00
|
|
|
cargo install cargo-ndk
|
2024-07-02 16:40:07 +03:00
|
|
|
|
2024-07-07 09:41:49 +03:00
|
|
|
sed -i -e 's/"rlib"/"cdylib","rlib"/g' Cargo.toml
|
2024-07-02 16:40:07 +03:00
|
|
|
|
|
|
|
# temp fix for https://stackoverflow.com/questions/57193895/error-use-of-undeclared-identifier-pthread-mutex-robust-cargo-build-liblmdb-s
|
|
|
|
success=0
|
|
|
|
export CPPFLAGS="-DMDB_USE_ROBUST=0" && export CFLAGS="-DMDB_USE_ROBUST=0"
|
2024-07-07 09:41:49 +03:00
|
|
|
cargo ndk -t ${arch} build ${release_param}
|
|
|
|
unset CPPFLAGS && unset CFLAGS
|
2024-06-27 12:30:51 +03:00
|
|
|
cargo ndk -t ${arch} -o android/app/src/main/jniLibs build ${release_param}
|
2024-07-02 16:40:07 +03:00
|
|
|
if [ $? -eq 0 ]
|
|
|
|
then
|
|
|
|
success=1
|
|
|
|
fi
|
|
|
|
|
2024-07-07 09:41:49 +03:00
|
|
|
sed -i -e 's/"cdylib","rlib"/"rlib"/g' Cargo.toml
|
2023-05-17 21:06:02 +03:00
|
|
|
|
2024-06-19 15:40:07 +03:00
|
|
|
# Build Android application and launch at all connected devices
|
2024-07-02 16:40:07 +03:00
|
|
|
if [ $success -eq 1 ]
|
2023-04-10 16:02:53 +03:00
|
|
|
then
|
2024-04-21 20:42:01 +03:00
|
|
|
cd android
|
2024-06-27 12:30:51 +03:00
|
|
|
|
|
|
|
# Setup gradle argument
|
|
|
|
[[ $1 == "release" ]] && gradle_param+=(assembleRelease)
|
|
|
|
[[ $1 == "debug" ]] && gradle_param+=(build)
|
|
|
|
|
2023-04-10 16:02:53 +03:00
|
|
|
./gradlew clean
|
2024-06-27 12:30:51 +03:00
|
|
|
./gradlew ${gradle_param}
|
|
|
|
|
|
|
|
# Setup apk path
|
|
|
|
[[ $1 == "release" ]] && apk_path+=(app/build/outputs/apk/release/app-release.apk)
|
|
|
|
[[ $1 == "debug" ]] && apk_path+=(app/build/outputs/apk/debug/app-debug.apk)
|
|
|
|
|
2023-07-14 03:51:06 +03:00
|
|
|
for SERIAL in $(adb devices | grep -v List | cut -f 1);
|
|
|
|
do
|
2024-06-27 12:30:51 +03:00
|
|
|
adb -s $SERIAL install ${apk_path}
|
2023-07-14 03:51:06 +03:00
|
|
|
sleep 1s
|
|
|
|
adb -s $SERIAL shell am start -n mw.gri.android/.MainActivity;
|
|
|
|
done
|
2023-04-10 16:02:53 +03:00
|
|
|
fi
|