Linux build tweaks

This commit is contained in:
Petr Bartos 2022-04-03 14:46:35 +02:00
parent c808c877f3
commit b236ecf180
3 changed files with 66 additions and 29 deletions

View file

@ -4,7 +4,7 @@ ANDROID_NDK_VERSION=21.1.6352462
UNAME := $(shell uname) UNAME := $(shell uname)
ifeq ($(UNAME), Linux) ifeq ($(UNAME), Linux)
ANDROID_SDK_ROOT?=/opt/AndroidSDK ANDROID_SDK_ROOT?=$(HOME)/Android/Sdk
ANDROID_NDK=$(ANDROID_SDK_ROOT)/ndk/$(ANDROID_NDK_VERSION) ANDROID_NDK=$(ANDROID_SDK_ROOT)/ndk/$(ANDROID_NDK_VERSION)
ANDROID_CC=$(ANDROID_NDK)/toolchains/llvm/prebuilt/linux-x86_64/bin/aarch64-linux-$(ANDROID_SDK_VERSION)-clang ANDROID_CC=$(ANDROID_NDK)/toolchains/llvm/prebuilt/linux-x86_64/bin/aarch64-linux-$(ANDROID_SDK_VERSION)-clang
ANDROID_CFLAGS=--target=aarch64-linux-$(ANDROID_SDK_VERSION) ANDROID_CFLAGS=--target=aarch64-linux-$(ANDROID_SDK_VERSION)

View file

@ -1,3 +0,0 @@
#!/bin/sh
./gradlew :app:assembleDebug

View file

@ -1,23 +1,47 @@
#!/bin/bash #!/bin/bash
TARGET=debug if [ -z "$ANDROID_SDK_ROOT" ]; then
ANDROID_SDK_ROOT=~/Android/Sdk
WORKDIR=$(readlink -f $(dirname $0)) fi
if [ -z "$ANDROID_TOOLS_VERSION" ]; then
NAME=$(cat $WORKDIR/app/src/main/res/values/strings.xml | grep "app_name" | cut -d">" -f2 | cut -d"<" -f1 ) ANDROID_TOOLS_VERSION=29.0.2
VERSION=$(cat $WORKDIR/app/src/main/AndroidManifest.xml | grep "versionName" | cut -d\" -f2 | cut -d\" -f1 ) fi
PACKAGE_NAME=$(cat $WORKDIR/app/src/main/AndroidManifest.xml | grep "package" | cut -d\" -f2 | cut -d\" -f1 ) if [ -z "$KEYSTORE" ]; then
KEYSTORE=~/.android/release.keystore
if [ "$1" == "clean" ] || [ "$2" == "clean" ] || [ "$3" == "clean" ]; then
rm -rf $WORKDIR/../build
rm -rf $WORKDIR/build
rm -rf $WORKDIR/app/build
rm -rf $WORKDIR/app/src/main/jniLibs
fi fi
echo "#define Q3QVERSION \"$VERSION"\" > $WORKDIR/app/src/main/cpp/code/vr/vr_version.h SCRIPTDIR=$(readlink -f $(dirname $0))
cd $WORKDIR/.. APP_NAME=$(cat $SCRIPTDIR/app/src/main/res/values/strings.xml | grep "app_name" | cut -d">" -f2 | cut -d"<" -f1 )
APP_VERSION=$(cat $SCRIPTDIR/app/src/main/AndroidManifest.xml | grep "versionName" | cut -d\" -f2 | cut -d\" -f1 )
APP_PACKAGE=$(cat $SCRIPTDIR/app/src/main/AndroidManifest.xml | grep "package" | cut -d\" -f2 | cut -d\" -f1 )
if [ "$1" == "release" ] || [ "$2" == "release" ] || [ "$3" == "release" ] || [ "$4" == "release" ]; then
TARGET=release
GRADLE_BUILD_TYPE=:app:assembleRelease
APK_NAME=app-release-unsigned.apk
else
TARGET=debug
GRADLE_BUILD_TYPE=:app:assembleDebug
APK_NAME=app-debug.apk
fi
APK_LOCATION="$SCRIPTDIR/app/build/outputs/apk/$TARGET"
if [ "$1" == "clean" ] || [ "$2" == "clean" ] || [ "$3" == "clean" ] || [ "$4" == "clean" ]; then
rm -rf $SCRIPTDIR/../build
rm -rf $SCRIPTDIR/build
rm -rf $SCRIPTDIR/app/build
rm -rf $SCRIPTDIR/app/src/main/jniLibs
fi
cd $SCRIPTDIR/app/src/main/pakQ3Q
rm -f $SCRIPTDIR/app/src/main/assets/pakQ3Q.pk3
zip -r $SCRIPTDIR/app/src/main/assets/pakQ3Q.pk3 .
echo "#define Q3QVERSION \"$APP_VERSION"\" > $SCRIPTDIR/app/src/main/cpp/code/vr/vr_version.h
cd $SCRIPTDIR/..
make -j $(getconf _NPROCESSORS_ONLN) $TARGET make -j $(getconf _NPROCESSORS_ONLN) $TARGET
if [ $? -ne 0 ]; then if [ $? -ne 0 ]; then
@ -25,23 +49,38 @@ if [ $? -ne 0 ]; then
exit 1 exit 1
fi fi
cd $WORKDIR cd $SCRIPTDIR
./make.sh ./gradlew "$GRADLE_BUILD_TYPE"
if [ $? -ne 0 ]; then if [ $? -ne 0 ]; then
echo "Failed to build android project" echo "Failed to build android project"
exit 1 exit 1
fi fi
ANDROID_STORAGE_LOCATION=/sdcard/Android/data/$PACKAGE_NAME/files/ UNSIGNED_APK="$APK_LOCATION/$APK_NAME"
APK_LOCATION=$WORKDIR/app/build/outputs/apk/debug/app-debug.apk if [ "$TARGET" == "release" ]; then
echo "Signing Release APK"
APK_NAME="$APP_NAME-release-$APP_VERSION.apk"
SIGNED_APK="$APK_LOCATION/$APK_NAME"
if [ -z "$KEYSTORE_PASS" ]; then
echo ""
echo "Keystore Password:"
read -s KEYSTORE_PASS
fi
apksigner="$ANDROID_SDK_ROOT/build-tools/$ANDROID_TOOLS_VERSION/apksigner"
$apksigner sign --ks "$KEYSTORE" --out "$SIGNED_APK" --v2-signing-enabled true --ks-pass "pass:$KEYSTORE_PASS" "$UNSIGNED_APK"
rm "$UNSIGNED_APK"
else
APK_NAME="$APP_NAME-debug-$APP_VERSION.apk"
mv "$UNSIGNED_APK" "$APK_LOCATION/$APK_NAME"
fi
if [ "$1" == "install" ] || [ "$2" == "install" ] || [ "$3" == "install" ]; then if [ "$1" == "install" ] || [ "$2" == "install" ] || [ "$3" == "install" ] || [ "$4" == "install" ]; then
adb install -r $APK_LOCATION adb install -r "$APK_LOCATION/$APK_NAME"
if [ $? -ne 0 ]; then if [ $? -ne 0 ]; then
adb uninstall $PACKAGE_NAME adb uninstall $APP_PACKAGE
adb install $APK_LOCATION adb install "$APK_LOCATION/$APK_NAME"
if [ $? -ne 0 ]; then if [ $? -ne 0 ]; then
echo "Failed to install apk." echo "Failed to install apk."
exit 1 exit 1
@ -49,6 +88,7 @@ if [ "$1" == "install" ] || [ "$2" == "install" ] || [ "$3" == "install" ]; then
fi fi
fi fi
#ANDROID_STORAGE_LOCATION=/sdcard/Android/data/$APP_PACKAGE/files/
#adb shell mkdir -p $ANDROID_STORAGE_LOCATION #adb shell mkdir -p $ANDROID_STORAGE_LOCATION
#adb push --sync ~/.local/share/Steam/steamapps/common/Quake\ 3\ Arena/baseq3 $ANDROID_STORAGE_LOCATION #adb push --sync ~/.local/share/Steam/steamapps/common/Quake\ 3\ Arena/baseq3 $ANDROID_STORAGE_LOCATION
#if [ $? -ne 0 ]; then #if [ $? -ne 0 ]; then
@ -66,9 +106,9 @@ fi
# exit 1 # exit 1
#fi #fi
if [ "$1" == "start" ] || [ "$2" == "start" ] || [ "$3" == "start" ]; then if [ "$1" == "start" ] || [ "$2" == "start" ] || [ "$3" == "start" ] || [ "$4" == "start" ]; then
adb logcat -c adb logcat -c
adb shell am start -n $PACKAGE_NAME/.MainActivity adb shell am start -n $APP_PACKAGE/.MainActivity
if [ $? -ne 0 ]; then if [ $? -ne 0 ]; then
echo "Failed to start application." echo "Failed to start application."
exit 1 exit 1