Subversion Repositories tpanel

Rev

Details | Last modification | View Log | RSS feed

Rev Author Line No. Line
354 andreas 1
#!/bin/bash
2
#
3
# Set the following paths according to your installation.
4
#
355 andreas 5
export QT_VERSION="6.5.2"
6
export QT_VERSION_MAJOR=6
7
export QTBASE="/opt/Qt/$QT_VERSION"
8
export QTDIR="${QTBASE}/android_x86_64"
354 andreas 9
export ANDROID_HOME="$HOME/Android/Sdk"
10
export ANDROID_NDK_HOST="linux-x86_64"
11
export ANDROID_NDK_PLATFORM="30"
12
export ANDROID_NDK_ROOT="${ANDROID_HOME}/ndk/25.2.9519653"
13
export ANDROID_NDK_HOME="${ANDROID_NDK_ROOT}"
14
export ANDROID_SDK_ROOT="${ANDROID_HOME}"
355 andreas 15
export ANDROID_PLATFORM="android-$ANDROID_NDK_PLATFORM"
354 andreas 16
export JAVA_HOME="/usr/lib/jvm/java-17-openjdk-amd64"
17
 
355 andreas 18
export PATH="${QTDIR}/bin:${QTDIR}/../android_x86/bin:${QTDIR}/../android_arm64_v8a/bin:${QTDIR}/../android_armv7/bin:$PATH"
19
export OPENSSLDIR="$HOME/Android/openssl/ssl_3"
20
 
21
ANDROID_TOOLCHAIN="${ANDROID_NDK_ROOT}/build/cmake/android.toolchain.cmake"
22
ANDROID_API_VERSION="android-$ANDROID_NDK_PLATFORM"
23
 
354 andreas 24
KEYSTORE="$HOME/projects/tpanel/android/android_release.keystore"
25
KEYALIAS="tpanel"
355 andreas 26
PASSFILE="$HOME/.keypass"
354 andreas 27
LOGFILE="`pwd`/build.log"
28
BUILDDIR="tpanel-6-build"
355 andreas 29
BUILDTYPE="Release"
354 andreas 30
 
355 andreas 31
export EXT_LIB_PATH="/home/andreas/Android/distribution"
32
export EXTRA_PATH="/home/andreas/Android/extras"
33
export SSL_PATH="/home/andreas/Android/openssl"
34
export ANDROID_ABIS="arm64-v8a armeabi-v7a x86_64 x86"
354 andreas 35
 
36
# This programs must be taken from the Qt framework and the Android SDK
355 andreas 37
QMAKE="$QTDIR/bin/qmake6"
38
QTCMAKE="$QTDIR/bin/qt-cmake"
39
CMAKE="/opt/Qt/Tools/CMake/bin/cmake"
40
GREP="/usr/bin/grep"
41
SED="/usr/bin/sed"
42
NINJA="${ANDROID_HOME}/cmake/3.22.1/bin/ninja"
354 andreas 43
MAKE="$ANDROID_NDK_ROOT/prebuilt/linux-x86_64/bin/make"
355 andreas 44
ANDROIDDEPLOYQT="$QTDIR/../gcc_64/bin/androiddeployqt"
354 andreas 45
 
46
#------------------------------------------------------------------------------
47
# DO NOT CHANGE ANYTHING BEYOND THIS LINE UNLESS YOU KNOW WHAT YOU'RE DOING!!
48
#------------------------------------------------------------------------------
355 andreas 49
 
50
#export QT_ANDROID_BUILD_ALL_ABIS="ON"
51
 
354 andreas 52
#
53
# The following statement determines the number of CPUs. This is used for the
54
# make command to let run the compiler in parallel.
55
#
56
CPUS=`lscpu | egrep '^CPU\(s\)' | cut -c30-34`
57
 
58
function usage() {
59
    echo "build_android.sh [clean] [debug] [deploy] [sign] [list-avds] [help|--help|-h]"
60
    echo "   clean     Delete old build, if there is one, and start a new clean build."
61
    echo "   debug     Create a binary with debugging enabled."
62
    echo "   deploy    Deploy the binary to an Android emulator."
63
    echo "   sign      Sign the resulting APK file. This requires a file named"
64
    echo "             \"\$HOME/.keypass\" containing the password and has read"
65
    echo "             permissions for the owner only (0400 or 0600). If this file"
66
    echo "             is missing, the script asks for the password."
67
    echo "   list-avds List all available AVDs and exit."
68
    echo
69
    echo "   help | --help | -h   Displays this help screen and exit."
70
    echo
71
    echo "Without parameters the source is compiled, if there were changes, and then"
72
    echo "an Android package is created. This package will be an unsigned release APK."
73
}
74
 
75
function log() {
76
    echo "$@"
77
    echo "$@" >> ${LOGFILE}
78
}
79
 
80
> ${LOGFILE}
81
 
82
# Test command line for parameters and set options
83
OPT_CLEAN=0
84
OPT_DEBUG=0
85
OPT_DEPLOY=0
86
OPT_SIGN=0
87
 
88
for par in "$@"
89
do
90
    if [ "$par" == "clean" ]
91
    then
92
        OPT_CLEAN=1
93
    elif [ "$par" == "debug" ]
94
    then
95
        OPT_DEBUG=1
96
    elif [ "$par" == "deploy" ]
97
    then
98
        OPT_DEPLOY=1
99
    elif [ "$par" == "sign" ]
100
    then
101
        OPT_SIGN=1
102
    elif [ "$par" == "list-avds" ] || [ "$par" == "-list-avds" ]
103
    then
104
        ${ANDROID_SDK_ROOT}/tools/emulator -list-avds
105
        exit 0
106
    elif [ "$par" == "help" ] || [ "$par" == "--help" ] || [ "$par" == "-h" ]
107
    then
108
        usage
109
        exit 0
110
    fi
111
done
112
 
113
if [ $OPT_DEBUG -eq 1 ] && [ $OPT_SIGN -eq 1 ]
114
then
115
    log "You can't sign a debugging version!"
116
    exit 1
117
fi
118
 
119
if [ $OPT_CLEAN -eq 1 ]
120
then
121
    log "Starting a clean build by deleting a maybe existing old build ..."
122
    rm -rf "$BUILDDIR"
123
fi
124
 
355 andreas 125
if [ ! -d "$BUILDDIR" ] || [ ! -f "$BUILDDIR/build.ninja" ]
354 andreas 126
then
127
    if [ ! -d "$BUILDDIR" ]
128
    then
129
        log "Crating new build directory \"$BUILDDIR\" ..."
130
        mkdir "$BUILDDIR" > /dev/null 2>&1
131
 
132
        if [ $? -ne 0 ]
133
        then
134
            log "Error creating a directory!"
135
            exit 1
136
        fi
137
    fi
138
 
139
    log "Changing into build directory \"$BUILDDIR\" ..."
140
    cd "$BUILDDIR"
141
    log "Creating Makefile ..."
142
 
143
    _dbg=""
144
 
145
    if [ $OPT_DEBUG -eq 1 ]
146
    then
355 andreas 147
        _dbg="-DQT_QML_DEBUG:STRING"
354 andreas 148
    fi
149
 
355 andreas 150
#     ${QTCMAKE} -DCMAKE_BUILD_TYPE:STRING="$BUILDTYPE" \
151
#              -DANDROID_PLATFORM:STRING="$ANDROID_NDK_PLATFORM" \
152
#              -DANDROID_SDK_ROOT:PATH="${ANDROID_HOME}" \
153
#              -DANDROID_NDK:PATH="${ANDROID_NDK_ROOT}" \
154
#              -DCMAKE_GENERATOR:STRING="Ninja" \
155
#              -DCMAKE_TOOLCHAIN_FILE:FILEPATH="${ANDROID_TOOLCHAIN}" \
156
#              -DANDROID_USE_LEGACY_TOOLCHAIN_FILE:BOOL="OFF" \
157
#              -DANDROID_STL:STRING="c++_shared" \
158
#              -DQT_NO_GLOBAL_APK_TARGET_PART_OF_ALL:BOOL="ON" \
159
#              -DCMAKE_SYSTEM_VERSION:STATIC=$ANDROID_NDK_PLATFORM \
160
#              -DANDROID_NATIVE_API_LEVEL:STRING="$ANDROID_API_VERSION" \
161
#              -DQT_ANDROID_ABIS:STRING="arm64-v8a;armeabi-v7a;x86_64;x86" \
162
#              .. 2>&1 | tee -a ${LOGFILE}
354 andreas 163
 
355 andreas 164
     ${CMAKE} -DCMAKE_GENERATOR:STRING="Ninja" \
165
              -DCMAKE_BUILD_TYPE:STRING="$BUILDTYPE" \
166
              -DANDROID_PLATFORM:STRING="$ANDROID_API_VERSION" \
167
              -DANDROID_NDK:PATH="${ANDROID_NDK_ROOT}" \
168
              -DCMAKE_TOOLCHAIN_FILE:FILEPATH="${ANDROID_TOOLCHAIN}" \
169
              -DANDROID_USE_LEGACY_TOOLCHAIN_FILE:BOOL="OFF" \
170
              -DANDROID_STL:STRING="c++_shared" \
171
              -DQT_NO_GLOBAL_APK_TARGET_PART_OF_ALL:BOOL="ON" \
172
              -DANDROID_SDK_ROOT:PATH="${ANDROID_HOME}" \
173
              -DCMAKE_SYSTEM_VERSION:STRING="$ANDROID_NDK_PLATFORM" \
174
              ${_dbg} .. 2>&1 | tee -a ${LOGFILE}
175
 
354 andreas 176
    if [ $? -ne 0 ]
177
    then
178
        log "Error creating a Makefile!"
179
        exit 1
180
    fi
355 andreas 181
 
182
#    log "Correcting the platform level to $ANDROID_NDK_PLATFORM ..."
183
#ls -l android_abi_builds/* >> ${LOGFILE}
184
#    for cc in `${GREP} -R -l 'ANDROID_PLATFORM:STRING=' android_abi_builds/*`
185
#    do
186
#        log "Correcting file: $cc"
187
#        ${SED} -i -r "s/android-[0-9][0-9]/android-$ANDROID_NDK_PLATFORM/g" $cc 2>&1 | tee -a ${LOGFILE}
188
#    done
354 andreas 189
else
190
    log "Changing into build directory \"$BUILDDIR\" ..."
191
    cd "$BUILDDIR"
192
fi
193
 
194
log "Compiling the source ..."
355 andreas 195
cp ../CMakeUserPresets.json .
196
${CMAKE} --build --preset "Android" 2>&1 | tee -a ${LOGFILE}
354 andreas 197
 
355 andreas 198
#${CMAKE} --build . 2>&1 | tee -a ${LOGFILE}
199
 
354 andreas 200
if [ $? -ne 0 ]
201
then
202
    log "Error compiling the code!"
203
    exit 1
204
fi
355 andreas 205
exit 0
354 andreas 206
log "Creating an Android binary (apk) file ..."
207
 
208
_install=""
209
_pass=""
210
 
211
if [ $OPT_DEPLOY -eq 1 ]
212
then
213
    _install="--reinstall"
214
fi
215
 
216
if [ $OPT_DEBUG -eq 0 ] && [ $OPT_SIGN -eq 1 ]
217
then
218
    if [ -f "$HOME/.keypass" ]
219
    then
220
        _perm=`stat -c %a "$HOME/.keypass"`
221
 
222
        if [ $_perm -ne 400 ] && [ $_perm -ne 600 ]
223
        then
224
            echo "The file \"$HOME/.keypass\" must have permission 0400 or 0600. Ignoring file!"
225
            read -s -p "Password of Android keystore: " _pass
226
        else
227
            _pass=`cat $HOME/.keypass`
228
        fi
229
    else
230
        read -s -p "Password of Android keystore: " _pass
231
    fi
232
 
233
    ${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}
234
else
235
    _rel=""
236
 
237
    if [ $OPT_DEBUG -eq 0 ]
238
    then
239
        _rel="--release"
240
    fi
241
 
242
    ${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}
243
fi
244
 
245
if [ $? -ne 0 ]
246
then
247
    log "Error building an Android binary file!"
248
    exit 1
249
fi
250
 
251
exit 0