Subversion Repositories tpanel

Rev

Rev 375 | Rev 381 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
352 andreas 1
#!/bin/bash
376 andreas 2
set -o pipefail
352 andreas 3
#
4
# Set the following paths according to your installation.
5
#
375 andreas 6
QT_VERSION="6.6.0"
356 andreas 7
QT_VERSION_MAJOR=6
8
QT_PATH="/opt/Qt"
9
QT_ABI="x86_64"
352 andreas 10
 
356 andreas 11
QTBASE="${QT_PATH}/$QT_VERSION"
12
QTDIR="${QTBASE}/android_${QT_ABI}"
13
 
14
ANDROID_HOME="$HOME/Android/Sdk"
15
ANDROID_NDK_PLATFORM="30"
16
ANDROID_NDK_ROOT="${ANDROID_HOME}/ndk/25.2.9519653"
17
ANDROID_SDK_ROOT="${ANDROID_HOME}"
18
ANDROID_PLATFORM="android-$ANDROID_NDK_PLATFORM"
375 andreas 19
 
20
if [ ! -z $OSTYPE ] && [[ "$OSTYPE" == *darwin* ]]
21
then
22
    QTMACROS="${QT_PATH}/Qt?Creator.app/Contents/Resources/package-manager"
23
else
24
    QTMACROS="${QT_PATH}/Tools/QtCreator/share/qtcreator/package-manager"
25
fi
26
 
356 andreas 27
JAVA_HOME="/usr/lib/jvm/java-17-openjdk-amd64"
28
 
29
export PATH="${QT}/Tools/Ninja:${QT}/Tools/CMake/bin:${QTDIR}/bin:$PATH"
30
ANDROID_TOOLCHAIN="${ANDROID_NDK_ROOT}/build/cmake/android.toolchain.cmake"
31
 
352 andreas 32
KEYSTORE="$HOME/projects/tpanel/android/android_release.keystore"
33
KEYALIAS="tpanel"
356 andreas 34
PASSFILE="$HOME/.keypass"
352 andreas 35
LOGFILE="`pwd`/build.log"
356 andreas 36
BUILDDIR="tpanel-6-build"
352 andreas 37
 
356 andreas 38
export EXT_LIB_PATH="$HOME/Android/distribution"
39
export EXTRA_PATH="$HOME/Android/extras"
40
export SSL_PATH="$HOME/Android/openssl"
41
#export ANDROID_ABIS="arm64-v8a armeabi-v7a x86_64 x86"
352 andreas 42
 
375 andreas 43
# This programs must be taken from the Qt framework
354 andreas 44
QMAKE="$QTDIR/bin/qmake"
375 andreas 45
 
46
if [ ! -z $OSTYPE ] && [[ "$OSTYPE" == *darwin* ]]
47
then
48
    CMAKE="${QT_PATH}/Tools/CMake/CMake.app/Contents/bin/cmake"
49
    ANDROIDDEPLOYQT="$QTBASE/macos/bin/androiddeployqt"
50
else
51
    CMAKE="${QT_PATH}/Tools/CMake/bin/cmake"
52
    ANDROIDDEPLOYQT="$QTBASE/gcc_64/bin/androiddeployqt"
53
fi
54
 
356 andreas 55
GREP="/usr/bin/grep"
56
SED="/usr/bin/sed"
352 andreas 57
 
58
#------------------------------------------------------------------------------
59
# DO NOT CHANGE ANYTHING BEYOND THIS LINE UNLESS YOU KNOW WHAT YOU'RE DOING!!
60
#------------------------------------------------------------------------------
356 andreas 61
 
62
# Getting the current directory
63
CURDIR=`pwd`
64
 
352 andreas 65
#
66
# The following statement determines the number of CPUs. This is used for the
356 andreas 67
# cmake command to let run the compiler in parallel.
352 andreas 68
#
356 andreas 69
CPUS=2
70
type nproc > /dev/null 2>&1
352 andreas 71
 
356 andreas 72
if [ $? -eq 0 ]
73
then
74
    CPUS=`nproc`
75
fi
76
 
352 andreas 77
function usage() {
353 andreas 78
    echo "build_android.sh [clean] [debug] [deploy] [sign] [list-avds] [help|--help|-h]"
352 andreas 79
    echo "   clean     Delete old build, if there is one, and start a new clean build."
80
    echo "   debug     Create a binary with debugging enabled."
81
    echo "   deploy    Deploy the binary to an Android emulator."
353 andreas 82
    echo "   sign      Sign the resulting APK file. This requires a file named"
83
    echo "             \"\$HOME/.keypass\" containing the password and has read"
84
    echo "             permissions for the owner only (0400 or 0600). If this file"
85
    echo "             is missing, the script asks for the password."
356 andreas 86
    echo "   verbose | --verbose | -v"
87
    echo "             Prints the commands used to create the target file."
353 andreas 88
    echo "   list-avds List all available AVDs and exit."
352 andreas 89
    echo
353 andreas 90
    echo "   help | --help | -h   Displays this help screen and exit."
91
    echo
352 andreas 92
    echo "Without parameters the source is compiled, if there were changes, and then"
353 andreas 93
    echo "an Android package is created. This package will be an unsigned release APK."
352 andreas 94
}
95
 
96
function log() {
97
    echo "$@"
98
    echo "$@" >> ${LOGFILE}
99
}
100
 
101
> ${LOGFILE}
102
 
103
# Test command line for parameters and set options
104
OPT_CLEAN=0
105
OPT_DEBUG=0
106
OPT_DEPLOY=0
353 andreas 107
OPT_SIGN=0
356 andreas 108
OPT_VERBOSE=0
352 andreas 109
 
110
for par in "$@"
111
do
112
    if [ "$par" == "clean" ]
113
    then
114
        OPT_CLEAN=1
115
    elif [ "$par" == "debug" ]
116
    then
117
        OPT_DEBUG=1
118
    elif [ "$par" == "deploy" ]
119
    then
120
        OPT_DEPLOY=1
353 andreas 121
    elif [ "$par" == "sign" ]
122
    then
123
        OPT_SIGN=1
352 andreas 124
    elif [ "$par" == "list-avds" ] || [ "$par" == "-list-avds" ]
125
    then
126
        ${ANDROID_SDK_ROOT}/tools/emulator -list-avds
353 andreas 127
        exit 0
356 andreas 128
    elif [ "$par" == "--verbose" ] || [ "$par" == "-v" ] || [ "$par" == "verbose" ]
129
    then
130
        OPT_VERBOSE=1
352 andreas 131
    elif [ "$par" == "help" ] || [ "$par" == "--help" ] || [ "$par" == "-h" ]
132
    then
133
        usage
353 andreas 134
        exit 0
352 andreas 135
    fi
136
done
137
 
353 andreas 138
if [ $OPT_DEBUG -eq 1 ] && [ $OPT_SIGN -eq 1 ]
139
then
140
    log "You can't sign a debugging version!"
141
    exit 1
142
fi
143
 
352 andreas 144
if [ $OPT_CLEAN -eq 1 ]
145
then
146
    log "Starting a clean build by deleting a maybe existing old build ..."
354 andreas 147
    rm -rf "$BUILDDIR"
352 andreas 148
fi
149
 
356 andreas 150
if [ ! -d "$BUILDDIR" ] || [ ! -f "$BUILDDIR/build.ninja" ]
352 andreas 151
then
354 andreas 152
    if [ ! -d "$BUILDDIR" ]
352 andreas 153
    then
356 andreas 154
        log "Crating new build directory \"$BUILDDIR\" ..."
155
        mkdir "${BUILDDIR}" > /dev/null 2>&1
156
        mkdir -p "${BUILDDIR}/.qtc/package-manager" > /dev/null 2>&1
352 andreas 157
 
158
        if [ $? -ne 0 ]
159
        then
160
            log "Error creating a directory!"
161
            exit 1
162
        fi
356 andreas 163
 
376 andreas 164
        log "Copying cmake macros from $QTMACROS ..."
356 andreas 165
        cp ${QTMACROS}/* ${BUILDDIR}/.qtc/package-manager > /dev/null 2>&1
166
 
167
        if [ $? -ne 0 ]
168
        then
169
            log "Error copiing cmake macros!"
170
            exit 1
171
        fi
352 andreas 172
    fi
173
 
354 andreas 174
    log "Changing into build directory \"$BUILDDIR\" ..."
175
    cd "$BUILDDIR"
352 andreas 176
    log "Creating Makefile ..."
177
 
178
    _dbg=""
179
 
180
    if [ $OPT_DEBUG -eq 1 ]
181
    then
356 andreas 182
        _dbg="-DCMAKE_BUILD_TYPE:STRING=Debug"
183
    else
184
        _dbg="-DCMAKE_BUILD_TYPE:STRING=Release"
352 andreas 185
    fi
186
 
356 andreas 187
    if [ $OPT_VERBOSE -eq 1 ]
188
    then
189
        echo "${CMAKE} -S ${CURDIR} -B ${CURDIR}/${BUILDDIR} -DCMAKE_GENERATOR:STRING=Ninja ${_dbg} -DCMAKE_PROJECT_INCLUDE_BEFORE:FILEPATH=${CURDIR}/${BUILDDIR}/.qtc/package-manager/auto-setup.cmake -DQT_QMAKE_EXECUTABLE:FILEPATH=${QMAKE} -DCMAKE_PREFIX_PATH:PATH=${QTDIR} -DCMAKE_C_COMPILER:FILEPATH=${ANDROID_NDK_ROOT}/toolchains/llvm/prebuilt/linux-x86_64/bin/clang -DCMAKE_CXX_COMPILER:FILEPATH=${ANDROID_NDK_ROOT}/toolchains/llvm/prebuilt/linux-x86_64/bin/clang++ -DANDROID_PLATFORM:STRING=${ANDROID_PLATFORM} -DANDROID_NDK:PATH=${ANDROID_NDK_ROOT} -DCMAKE_TOOLCHAIN_FILE:FILEPATH=${ANDROID_TOOLCHAIN} -DANDROID_USE_LEGACY_TOOLCHAIN_FILE:BOOL=OFF -DANDROID_ABI:STRING=${QT_ABI} -DANDROID_STL:STRING=c++_shared -DCMAKE_FIND_ROOT_PATH:PATH=${QTDIR} -DQT_NO_GLOBAL_APK_TARGET_PART_OF_ALL:BOOL=ON -DQT_HOST_PATH:PATH=${QTBASE}/gcc_64 -DANDROID_SDK_ROOT:PATH=${ANDROID_HOME} -DQT_ANDROID_BUILD_ALL_ABIS:BOOL=ON"
190
    fi
352 andreas 191
 
356 andreas 192
    ${CMAKE} -S ${CURDIR} -B ${CURDIR}/${BUILDDIR} \
193
        -DCMAKE_GENERATOR:STRING=Ninja ${_dbg} \
194
        -DCMAKE_PROJECT_INCLUDE_BEFORE:FILEPATH=${CURDIR}/${BUILDDIR}/.qtc/package-manager/auto-setup.cmake \
195
        -DQT_QMAKE_EXECUTABLE:FILEPATH=${QMAKE} \
196
        -DCMAKE_PREFIX_PATH:PATH=${QTDIR} \
197
        -DCMAKE_C_COMPILER:FILEPATH=${ANDROID_NDK_ROOT}/toolchains/llvm/prebuilt/linux-x86_64/bin/clang \
198
        -DCMAKE_CXX_COMPILER:FILEPATH=${ANDROID_NDK_ROOT}/toolchains/llvm/prebuilt/linux-x86_64/bin/clang++ \
199
        -DANDROID_PLATFORM:STRING=${ANDROID_PLATFORM} \
200
        -DANDROID_NDK:PATH=${ANDROID_NDK_ROOT} \
201
        -DCMAKE_TOOLCHAIN_FILE:FILEPATH=${ANDROID_TOOLCHAIN} \
202
        -DANDROID_USE_LEGACY_TOOLCHAIN_FILE:BOOL=OFF \
203
        -DANDROID_ABI:STRING=${QT_ABI} \
204
        -DANDROID_STL:STRING=c++_shared \
205
        -DCMAKE_FIND_ROOT_PATH:PATH=${QTDIR} \
206
        -DQT_NO_GLOBAL_APK_TARGET_PART_OF_ALL:BOOL=ON \
207
        -DQT_HOST_PATH:PATH=${QTBASE}/gcc_64 \
208
        -DANDROID_SDK_ROOT:PATH=${ANDROID_HOME} \
209
        -DQT_ANDROID_BUILD_ALL_ABIS:BOOL=ON \
364 andreas 210
        -DQT_ANDROID_ABIS:STRING="arm64-v8a;armeabi-v7a;x86;x86_64" \
356 andreas 211
        2>&1 | tee -a ${LOGFILE}
212
 
352 andreas 213
    if [ $? -ne 0 ]
214
    then
215
        log "Error creating a Makefile!"
216
        exit 1
217
    fi
218
else
354 andreas 219
    log "Changing into build directory \"$BUILDDIR\" ..."
220
    cd "$BUILDDIR"
352 andreas 221
fi
222
 
362 andreas 223
log "Compiling the source and using ${CPUS} cpus..."
352 andreas 224
 
356 andreas 225
if [ $OPT_VERBOSE -eq 1 ]
226
then
227
    echo "${CMAKE} --build "${CURDIR}/${BUILDDIR}" --target all -j${CPUS}"
228
fi
229
 
230
${CMAKE} --build "${CURDIR}/${BUILDDIR}" --target all -j${CPUS} 2>&1 | tee -a ${LOGFILE}
231
 
352 andreas 232
if [ $? -ne 0 ]
233
then
234
    log "Error compiling the code!"
235
    exit 1
236
fi
237
 
238
log "Creating an Android binary (apk) file ..."
239
 
240
_install=""
241
_pass=""
242
 
243
if [ $OPT_DEPLOY -eq 1 ]
244
then
245
    _install="--reinstall"
246
fi
247
 
353 andreas 248
if [ $OPT_DEBUG -eq 0 ] && [ $OPT_SIGN -eq 1 ]
352 andreas 249
then
250
    if [ -f "$HOME/.keypass" ]
251
    then
353 andreas 252
        _perm=`stat -c %a "$HOME/.keypass"`
253
 
254
        if [ $_perm -ne 400 ] && [ $_perm -ne 600 ]
255
        then
256
            echo "The file \"$HOME/.keypass\" must have permission 0400 or 0600. Ignoring file!"
257
            read -s -p "Password of Android keystore: " _pass
258
        else
259
            _pass=`cat $HOME/.keypass`
260
        fi
352 andreas 261
    else
262
        read -s -p "Password of Android keystore: " _pass
263
    fi
264
 
356 andreas 265
    if [ $OPT_VERBOSE -eq 1 ]
266
    then
267
        echo "${ANDROIDDEPLOYQT} --input ${CURDIR}/${BUILDDIR}/android-tpanel-deployment-settings.json --output ${CURDIR}/${BUILDDIR}/android-build --android-platform ${ANDROID_PLATFORM} --jdk ${JAVA_HOME} --gradle --release --verbose --sign ${KEYSTORE} ${KEYALIAS} --storepass "${_pass}" ${_install}"
268
    fi
269
 
270
    ${ANDROIDDEPLOYQT} --input ${CURDIR}/${BUILDDIR}/android-tpanel-deployment-settings.json \
271
        --output ${CURDIR}/${BUILDDIR}/android-build \
272
        --android-platform ${ANDROID_PLATFORM} \
273
        --jdk ${JAVA_HOME} \
274
        --gradle --release \
275
        --sign ${KEYSTORE} ${KEYALIAS} \
276
        --storepass "${_pass}" ${_install} 2>&1 | tee -a ${LOGFILE}
352 andreas 277
else
356 andreas 278
    if [ $OPT_VERBOSE -eq 1 ]
353 andreas 279
    then
361 andreas 280
        echo "${ANDROIDDEPLOYQT} --input ${CURDIR}/${BUILDDIR}/android-tpanel-deployment-settings.json --output ${CURDIR}/${BUILDDIR}/android-build --android-platform ${ANDROID_PLATFORM} --jdk ${JAVA_HOME} --gradle --verbose ${_install}"
353 andreas 281
    fi
282
 
356 andreas 283
    ${ANDROIDDEPLOYQT} --input ${CURDIR}/${BUILDDIR}/android-tpanel-deployment-settings.json \
284
        --output ${CURDIR}/${BUILDDIR}/android-build \
285
        --android-platform ${ANDROID_PLATFORM} \
286
        --jdk ${JAVA_HOME} \
361 andreas 287
        --gradle --verbose  ${_install} 2>&1 | tee -a ${LOGFILE}
352 andreas 288
fi
289
 
290
if [ $? -ne 0 ]
291
then
292
    log "Error building an Android binary file!"
293
    exit 1
294
fi
295
 
296
exit 0