354 |
andreas |
1 |
#!/bin/bash
|
|
|
2 |
#
|
|
|
3 |
# Set the following paths according to your installation.
|
|
|
4 |
#
|
|
|
5 |
export QTDIR="/opt/Qt/6.5.2"
|
|
|
6 |
export ANDROID_HOME="$HOME/Android/Sdk"
|
|
|
7 |
export ANDROID_NDK_HOST="linux-x86_64"
|
|
|
8 |
export ANDROID_NDK_PLATFORM="30"
|
|
|
9 |
export ANDROID_NDK_ROOT="${ANDROID_HOME}/ndk/25.2.9519653"
|
|
|
10 |
export ANDROID_NDK_HOME="${ANDROID_NDK_ROOT}"
|
|
|
11 |
export ANDROID_SDK_ROOT="${ANDROID_HOME}"
|
|
|
12 |
export ANDROID_API_VERSION="android-30"
|
|
|
13 |
export JAVA_HOME="/usr/lib/jvm/java-17-openjdk-amd64"
|
|
|
14 |
export PATH="${QTDIR}/android_x86_64/bin:${QTDIR}/android_x86/bin:${QTDIR}/android_arm64_v8a/bin:${QTDIR}/android_armv7/bin:$PATH"
|
|
|
15 |
|
|
|
16 |
KEYSTORE="$HOME/projects/tpanel/android/android_release.keystore"
|
|
|
17 |
KEYALIAS="tpanel"
|
|
|
18 |
LOGFILE="`pwd`/build.log"
|
|
|
19 |
BUILDDIR="tpanel-6-build"
|
|
|
20 |
|
|
|
21 |
_EXT_LIB_PATH="/home/andreas/Android/distribution"
|
|
|
22 |
_EXTRA_PATH="/home/andreas/Android/extras"
|
|
|
23 |
_SSL_PATH="/home/andreas/Android/openssl"
|
|
|
24 |
_ANDROID_ABIS="arm64-v8a armeabi-v7a x86_64 x86"
|
|
|
25 |
|
|
|
26 |
# This programs must be taken from the Qt framework and the Android SDK
|
|
|
27 |
QMAKE="$QTDIR/android_x86/bin/qmake6"
|
|
|
28 |
MAKE="$ANDROID_NDK_ROOT/prebuilt/linux-x86_64/bin/make"
|
|
|
29 |
ANDROIDDEPLOYQT="$QTDIR/gcc_64/bin/androiddeployqt"
|
|
|
30 |
|
|
|
31 |
#------------------------------------------------------------------------------
|
|
|
32 |
# DO NOT CHANGE ANYTHING BEYOND THIS LINE UNLESS YOU KNOW WHAT YOU'RE DOING!!
|
|
|
33 |
#------------------------------------------------------------------------------
|
|
|
34 |
#
|
|
|
35 |
# The following statement determines the number of CPUs. This is used for the
|
|
|
36 |
# make command to let run the compiler in parallel.
|
|
|
37 |
#
|
|
|
38 |
CPUS=`lscpu | egrep '^CPU\(s\)' | cut -c30-34`
|
|
|
39 |
|
|
|
40 |
function usage() {
|
|
|
41 |
echo "build_android.sh [clean] [debug] [deploy] [sign] [list-avds] [help|--help|-h]"
|
|
|
42 |
echo " clean Delete old build, if there is one, and start a new clean build."
|
|
|
43 |
echo " debug Create a binary with debugging enabled."
|
|
|
44 |
echo " deploy Deploy the binary to an Android emulator."
|
|
|
45 |
echo " sign Sign the resulting APK file. This requires a file named"
|
|
|
46 |
echo " \"\$HOME/.keypass\" containing the password and has read"
|
|
|
47 |
echo " permissions for the owner only (0400 or 0600). If this file"
|
|
|
48 |
echo " is missing, the script asks for the password."
|
|
|
49 |
echo " list-avds List all available AVDs and exit."
|
|
|
50 |
echo
|
|
|
51 |
echo " help | --help | -h Displays this help screen and exit."
|
|
|
52 |
echo
|
|
|
53 |
echo "Without parameters the source is compiled, if there were changes, and then"
|
|
|
54 |
echo "an Android package is created. This package will be an unsigned release APK."
|
|
|
55 |
}
|
|
|
56 |
|
|
|
57 |
function log() {
|
|
|
58 |
echo "$@"
|
|
|
59 |
echo "$@" >> ${LOGFILE}
|
|
|
60 |
}
|
|
|
61 |
|
|
|
62 |
> ${LOGFILE}
|
|
|
63 |
|
|
|
64 |
# Test command line for parameters and set options
|
|
|
65 |
OPT_CLEAN=0
|
|
|
66 |
OPT_DEBUG=0
|
|
|
67 |
OPT_DEPLOY=0
|
|
|
68 |
OPT_SIGN=0
|
|
|
69 |
|
|
|
70 |
for par in "$@"
|
|
|
71 |
do
|
|
|
72 |
if [ "$par" == "clean" ]
|
|
|
73 |
then
|
|
|
74 |
OPT_CLEAN=1
|
|
|
75 |
elif [ "$par" == "debug" ]
|
|
|
76 |
then
|
|
|
77 |
OPT_DEBUG=1
|
|
|
78 |
elif [ "$par" == "deploy" ]
|
|
|
79 |
then
|
|
|
80 |
OPT_DEPLOY=1
|
|
|
81 |
elif [ "$par" == "sign" ]
|
|
|
82 |
then
|
|
|
83 |
OPT_SIGN=1
|
|
|
84 |
elif [ "$par" == "list-avds" ] || [ "$par" == "-list-avds" ]
|
|
|
85 |
then
|
|
|
86 |
${ANDROID_SDK_ROOT}/tools/emulator -list-avds
|
|
|
87 |
exit 0
|
|
|
88 |
elif [ "$par" == "help" ] || [ "$par" == "--help" ] || [ "$par" == "-h" ]
|
|
|
89 |
then
|
|
|
90 |
usage
|
|
|
91 |
exit 0
|
|
|
92 |
fi
|
|
|
93 |
done
|
|
|
94 |
|
|
|
95 |
if [ $OPT_DEBUG -eq 1 ] && [ $OPT_SIGN -eq 1 ]
|
|
|
96 |
then
|
|
|
97 |
log "You can't sign a debugging version!"
|
|
|
98 |
exit 1
|
|
|
99 |
fi
|
|
|
100 |
|
|
|
101 |
if [ $OPT_CLEAN -eq 1 ]
|
|
|
102 |
then
|
|
|
103 |
log "Starting a clean build by deleting a maybe existing old build ..."
|
|
|
104 |
rm -rf "$BUILDDIR"
|
|
|
105 |
fi
|
|
|
106 |
|
|
|
107 |
if [ ! -d "$BUILDDIR" ] || [ ! -f "$BUILDDIR/Makefile" ]
|
|
|
108 |
then
|
|
|
109 |
if [ ! -d "$BUILDDIR" ]
|
|
|
110 |
then
|
|
|
111 |
log "Crating new build directory \"$BUILDDIR\" ..."
|
|
|
112 |
mkdir "$BUILDDIR" > /dev/null 2>&1
|
|
|
113 |
|
|
|
114 |
if [ $? -ne 0 ]
|
|
|
115 |
then
|
|
|
116 |
log "Error creating a directory!"
|
|
|
117 |
exit 1
|
|
|
118 |
fi
|
|
|
119 |
fi
|
|
|
120 |
|
|
|
121 |
log "Changing into build directory \"$BUILDDIR\" ..."
|
|
|
122 |
cd "$BUILDDIR"
|
|
|
123 |
log "Creating Makefile ..."
|
|
|
124 |
|
|
|
125 |
_dbg=""
|
|
|
126 |
|
|
|
127 |
if [ $OPT_DEBUG -eq 1 ]
|
|
|
128 |
then
|
|
|
129 |
_dbg="CONFIG+=qml_debug debug debug_info"
|
|
|
130 |
fi
|
|
|
131 |
|
|
|
132 |
${QMAKE} -spec android-clang CONFIG+=qtquickcompiler "${_dbg}" QT_ANDROID_BUILD_ALL_ABIS=ON QT_PATH_ANDROID_ABI_armeabi-v7a="$QTDIR/android_armv7" QT_PATH_ANDROID_ABI_arm64-v8a="$QTDIR/android_arm64_v8a" QT_PATH_ANDROID_ABI_x86="$QTDIR/android_x86" QT_PATH_ANDROID_ABI_x86_64="$QTDIR/android_x86_64" SDK_PATH="${ANDROID_SDK_ROOT}" EXT_LIB_PATH="${_EXT_LIB_PATH}" EXTRA_PATH="${_EXTRA_PATH}" SSL_PATH="${_SSL_PATH}" ANDROID_ABIS="${_ANDROID_ABIS}" ../tpanel.pro 2>&1 | tee -a ${LOGFILE}
|
|
|
133 |
|
|
|
134 |
if [ $? -ne 0 ]
|
|
|
135 |
then
|
|
|
136 |
log "Error creating a Makefile!"
|
|
|
137 |
exit 1
|
|
|
138 |
fi
|
|
|
139 |
else
|
|
|
140 |
log "Changing into build directory \"$BUILDDIR\" ..."
|
|
|
141 |
cd "$BUILDDIR"
|
|
|
142 |
fi
|
|
|
143 |
|
|
|
144 |
log "Compiling the source ..."
|
|
|
145 |
${MAKE} -j ${CPUS} apk_install_target 2>&1 | tee -a ${LOGFILE}
|
|
|
146 |
|
|
|
147 |
if [ $? -ne 0 ]
|
|
|
148 |
then
|
|
|
149 |
log "Error compiling the code!"
|
|
|
150 |
exit 1
|
|
|
151 |
fi
|
|
|
152 |
|
|
|
153 |
log "Creating an Android binary (apk) file ..."
|
|
|
154 |
|
|
|
155 |
_install=""
|
|
|
156 |
_pass=""
|
|
|
157 |
|
|
|
158 |
if [ $OPT_DEPLOY -eq 1 ]
|
|
|
159 |
then
|
|
|
160 |
_install="--reinstall"
|
|
|
161 |
fi
|
|
|
162 |
|
|
|
163 |
if [ $OPT_DEBUG -eq 0 ] && [ $OPT_SIGN -eq 1 ]
|
|
|
164 |
then
|
|
|
165 |
if [ -f "$HOME/.keypass" ]
|
|
|
166 |
then
|
|
|
167 |
_perm=`stat -c %a "$HOME/.keypass"`
|
|
|
168 |
|
|
|
169 |
if [ $_perm -ne 400 ] && [ $_perm -ne 600 ]
|
|
|
170 |
then
|
|
|
171 |
echo "The file \"$HOME/.keypass\" must have permission 0400 or 0600. Ignoring file!"
|
|
|
172 |
read -s -p "Password of Android keystore: " _pass
|
|
|
173 |
else
|
|
|
174 |
_pass=`cat $HOME/.keypass`
|
|
|
175 |
fi
|
|
|
176 |
else
|
|
|
177 |
read -s -p "Password of Android keystore: " _pass
|
|
|
178 |
fi
|
|
|
179 |
|
|
|
180 |
${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}
|
|
|
181 |
else
|
|
|
182 |
_rel=""
|
|
|
183 |
|
|
|
184 |
if [ $OPT_DEBUG -eq 0 ]
|
|
|
185 |
then
|
|
|
186 |
_rel="--release"
|
|
|
187 |
fi
|
|
|
188 |
|
|
|
189 |
${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}
|
|
|
190 |
fi
|
|
|
191 |
|
|
|
192 |
if [ $? -ne 0 ]
|
|
|
193 |
then
|
|
|
194 |
log "Error building an Android binary file!"
|
|
|
195 |
exit 1
|
|
|
196 |
fi
|
|
|
197 |
|
|
|
198 |
exit 0
|