Subversion Repositories tpanel

Rev

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