Rev 354 | Blame | Last modification | View Log | RSS feed
#!/bin/bash
#
# Set the following paths according to your installation.
#
export QT_VERSION="6.5.2"
export QT_VERSION_MAJOR=6
export QTBASE="/opt/Qt/$QT_VERSION"
export QTDIR="${QTBASE}/android_x86_64"
export ANDROID_HOME="$HOME/Android/Sdk"
export ANDROID_NDK_HOST="linux-x86_64"
export ANDROID_NDK_PLATFORM="30"
export ANDROID_NDK_ROOT="${ANDROID_HOME}/ndk/25.2.9519653"
export ANDROID_NDK_HOME="${ANDROID_NDK_ROOT}"
export ANDROID_SDK_ROOT="${ANDROID_HOME}"
export ANDROID_PLATFORM="android-$ANDROID_NDK_PLATFORM"
export JAVA_HOME="/usr/lib/jvm/java-17-openjdk-amd64"
export PATH="${QTDIR}/bin:${QTDIR}/../android_x86/bin:${QTDIR}/../android_arm64_v8a/bin:${QTDIR}/../android_armv7/bin:$PATH"
export OPENSSLDIR="$HOME/Android/openssl/ssl_3"
ANDROID_TOOLCHAIN="${ANDROID_NDK_ROOT}/build/cmake/android.toolchain.cmake"
ANDROID_API_VERSION="android-$ANDROID_NDK_PLATFORM"
KEYSTORE="$HOME/projects/tpanel/android/android_release.keystore"
KEYALIAS="tpanel"
PASSFILE="$HOME/.keypass"
LOGFILE="`pwd`/build.log"
BUILDDIR="tpanel-6-build"
BUILDTYPE="Release"
export EXT_LIB_PATH="/home/andreas/Android/distribution"
export EXTRA_PATH="/home/andreas/Android/extras"
export SSL_PATH="/home/andreas/Android/openssl"
export ANDROID_ABIS="arm64-v8a armeabi-v7a x86_64 x86"
# This programs must be taken from the Qt framework and the Android SDK
QMAKE="$QTDIR/bin/qmake6"
QTCMAKE="$QTDIR/bin/qt-cmake"
CMAKE="/opt/Qt/Tools/CMake/bin/cmake"
GREP="/usr/bin/grep"
SED="/usr/bin/sed"
NINJA="${ANDROID_HOME}/cmake/3.22.1/bin/ninja"
MAKE="$ANDROID_NDK_ROOT/prebuilt/linux-x86_64/bin/make"
ANDROIDDEPLOYQT="$QTDIR/../gcc_64/bin/androiddeployqt"
#------------------------------------------------------------------------------
# DO NOT CHANGE ANYTHING BEYOND THIS LINE UNLESS YOU KNOW WHAT YOU'RE DOING!!
#------------------------------------------------------------------------------
#export QT_ANDROID_BUILD_ALL_ABIS="ON"
#
# The following statement determines the number of CPUs. This is used for the
# make command to let run the compiler in parallel.
#
CPUS=`lscpu | egrep '^CPU\(s\)' | cut -c30-34`
function usage() {
echo "build_android.sh [clean] [debug] [deploy] [sign] [list-avds] [help|--help|-h]"
echo " clean Delete old build, if there is one, and start a new clean build."
echo " debug Create a binary with debugging enabled."
echo " deploy Deploy the binary to an Android emulator."
echo " sign Sign the resulting APK file. This requires a file named"
echo " \"\$HOME/.keypass\" containing the password and has read"
echo " permissions for the owner only (0400 or 0600). If this file"
echo " is missing, the script asks for the password."
echo " list-avds List all available AVDs and exit."
echo
echo " help | --help | -h Displays this help screen and exit."
echo
echo "Without parameters the source is compiled, if there were changes, and then"
echo "an Android package is created. This package will be an unsigned release APK."
}
function log() {
echo "$@"
echo "$@" >> ${LOGFILE}
}
> ${LOGFILE}
# Test command line for parameters and set options
OPT_CLEAN=0
OPT_DEBUG=0
OPT_DEPLOY=0
OPT_SIGN=0
for par in "$@"
do
if [ "$par" == "clean" ]
then
OPT_CLEAN=1
elif [ "$par" == "debug" ]
then
OPT_DEBUG=1
elif [ "$par" == "deploy" ]
then
OPT_DEPLOY=1
elif [ "$par" == "sign" ]
then
OPT_SIGN=1
elif [ "$par" == "list-avds" ] || [ "$par" == "-list-avds" ]
then
${ANDROID_SDK_ROOT}/tools/emulator -list-avds
exit 0
elif [ "$par" == "help" ] || [ "$par" == "--help" ] || [ "$par" == "-h" ]
then
usage
exit 0
fi
done
if [ $OPT_DEBUG -eq 1 ] && [ $OPT_SIGN -eq 1 ]
then
log "You can't sign a debugging version!"
exit 1
fi
if [ $OPT_CLEAN -eq 1 ]
then
log "Starting a clean build by deleting a maybe existing old build ..."
rm -rf "$BUILDDIR"
fi
if [ ! -d "$BUILDDIR" ] || [ ! -f "$BUILDDIR/build.ninja" ]
then
if [ ! -d "$BUILDDIR" ]
then
log "Crating new build directory \"$BUILDDIR\" ..."
mkdir "$BUILDDIR" > /dev/null 2>&1
if [ $? -ne 0 ]
then
log "Error creating a directory!"
exit 1
fi
fi
log "Changing into build directory \"$BUILDDIR\" ..."
cd "$BUILDDIR"
log "Creating Makefile ..."
_dbg=""
if [ $OPT_DEBUG -eq 1 ]
then
_dbg="-DQT_QML_DEBUG:STRING"
fi
# ${QTCMAKE} -DCMAKE_BUILD_TYPE:STRING="$BUILDTYPE" \
# -DANDROID_PLATFORM:STRING="$ANDROID_NDK_PLATFORM" \
# -DANDROID_SDK_ROOT:PATH="${ANDROID_HOME}" \
# -DANDROID_NDK:PATH="${ANDROID_NDK_ROOT}" \
# -DCMAKE_GENERATOR:STRING="Ninja" \
# -DCMAKE_TOOLCHAIN_FILE:FILEPATH="${ANDROID_TOOLCHAIN}" \
# -DANDROID_USE_LEGACY_TOOLCHAIN_FILE:BOOL="OFF" \
# -DANDROID_STL:STRING="c++_shared" \
# -DQT_NO_GLOBAL_APK_TARGET_PART_OF_ALL:BOOL="ON" \
# -DCMAKE_SYSTEM_VERSION:STATIC=$ANDROID_NDK_PLATFORM \
# -DANDROID_NATIVE_API_LEVEL:STRING="$ANDROID_API_VERSION" \
# -DQT_ANDROID_ABIS:STRING="arm64-v8a;armeabi-v7a;x86_64;x86" \
# .. 2>&1 | tee -a ${LOGFILE}
${CMAKE} -DCMAKE_GENERATOR:STRING="Ninja" \
-DCMAKE_BUILD_TYPE:STRING="$BUILDTYPE" \
-DANDROID_PLATFORM:STRING="$ANDROID_API_VERSION" \
-DANDROID_NDK:PATH="${ANDROID_NDK_ROOT}" \
-DCMAKE_TOOLCHAIN_FILE:FILEPATH="${ANDROID_TOOLCHAIN}" \
-DANDROID_USE_LEGACY_TOOLCHAIN_FILE:BOOL="OFF" \
-DANDROID_STL:STRING="c++_shared" \
-DQT_NO_GLOBAL_APK_TARGET_PART_OF_ALL:BOOL="ON" \
-DANDROID_SDK_ROOT:PATH="${ANDROID_HOME}" \
-DCMAKE_SYSTEM_VERSION:STRING="$ANDROID_NDK_PLATFORM" \
${_dbg} .. 2>&1 | tee -a ${LOGFILE}
if [ $? -ne 0 ]
then
log "Error creating a Makefile!"
exit 1
fi
# log "Correcting the platform level to $ANDROID_NDK_PLATFORM ..."
#ls -l android_abi_builds/* >> ${LOGFILE}
# for cc in `${GREP} -R -l 'ANDROID_PLATFORM:STRING=' android_abi_builds/*`
# do
# log "Correcting file: $cc"
# ${SED} -i -r "s/android-[0-9][0-9]/android-$ANDROID_NDK_PLATFORM/g" $cc 2>&1 | tee -a ${LOGFILE}
# done
else
log "Changing into build directory \"$BUILDDIR\" ..."
cd "$BUILDDIR"
fi
log "Compiling the source ..."
cp ../CMakeUserPresets.json .
${CMAKE} --build --preset "Android" 2>&1 | tee -a ${LOGFILE}
#${CMAKE} --build . 2>&1 | tee -a ${LOGFILE}
if [ $? -ne 0 ]
then
log "Error compiling the code!"
exit 1
fi
exit 0
log "Creating an Android binary (apk) file ..."
_install=""
_pass=""
if [ $OPT_DEPLOY -eq 1 ]
then
_install="--reinstall"
fi
if [ $OPT_DEBUG -eq 0 ] && [ $OPT_SIGN -eq 1 ]
then
if [ -f "$HOME/.keypass" ]
then
_perm=`stat -c %a "$HOME/.keypass"`
if [ $_perm -ne 400 ] && [ $_perm -ne 600 ]
then
echo "The file \"$HOME/.keypass\" must have permission 0400 or 0600. Ignoring file!"
read -s -p "Password of Android keystore: " _pass
else
_pass=`cat $HOME/.keypass`
fi
else
read -s -p "Password of Android keystore: " _pass
fi
${ANDROIDDEPLOYQT} --input android-tpanel-deployment-settings.json --output android-build --android-platform ${ANDROID_API_VERSION} --jdk ${JAVA_HOME} --release --sign ${KEYSTORE} ${KEYALIAS} --storepass "${_pass}" ${_install} --gradle --verbose 2>&1 | tee -a ${LOGFILE}
else
_rel=""
if [ $OPT_DEBUG -eq 0 ]
then
_rel="--release"
fi
${ANDROIDDEPLOYQT} --input android-tpanel-deployment-settings.json --output android-build --android-platform ${ANDROID_API_VERSION} --jdk ${JAVA_HOME} ${_install} ${_rel} --gradle --verbose 2>&1 | tee -a ${LOGFILE}
fi
if [ $? -ne 0 ]
then
log "Error building an Android binary file!"
exit 1
fi
exit 0