forked from obbimi/Squore
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathclean.and.assemble.sh
executable file
·235 lines (208 loc) · 9.8 KB
/
clean.and.assemble.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
#!/usr/bin/env bash
#export JAVA_HOME=/usr/lib/jvm/java-8-openjdk
#export JAVA_HOME=/usr/lib/jvm/java-10-openjdk
export JAVA_HOME=/usr/lib/jvm/java-11-openjdk
#export JAVA_HOME=/usr/lib/jvm/java-22-jdk
#export JAVA_HOME=/osshare/software/oracle/java-8-oracle
if [[ ! -e $JAVA_HOME ]]; then
export JAVA_HOME=/cygdrive/c/localapps/jdk1.8.0_231
fi
if [[ ! -e $JAVA_HOME ]]; then
# ubuntu shell
#export JAVA_HOME=/mnt/c/localapps/jdk1.8.0_231
#export JAVA_HOME=C:/localapps/jdk1.8.0_231
export JAVA_HOME=/usr/lib/jvm/java-8-openjdk-amd64
fi
if [[ ! -e $JAVA_HOME ]]; then
echo "java home not correctly configured: $JAVA_HOME"
exit 1
fi
mffile=$(grep Manifest build.gradle | grep -E -v '(ALL)' | grep -v '//' | cut -d "'" -f 2)
if [[ -z "${mffile}" ]]; then
echo "Could not determine manifest file by looking in build.gradle"
exit 1
fi
pkg=$(grep package= ${mffile} | perl -ne 's~.*"([a-z\.]+)".*~$1~; print')
# check if a new version code for the brand for which we will be creating an apk is specified
if [[ -n "$1" ]]; then
versionCodeFromCommandLine=$1
echo "Changing build.gradle to use versioncode $versionCodeFromCommandLine"
#grep versionCode build.gradle | sed -i "s/10000 + [0-9][0-9][0-9]/10000 + ${versionCodeFromCommandLine}/"
#sed -i "s/10000 + [0-9][0-9]*/10000 + ${versionCodeFromCommandLine}/" build.gradle
sed -i "s/versionCodeXXX = [0-9][0-9]*/versionCodeXXX = ${versionCodeFromCommandLine}/" build.gradle
fi
brand=$(grep -E 'Brand\s+brand\s*=\s*Brand\.' src/com/doubleyellow/scoreboard/Brand.java | perl -ne 's~.*Brand\.(\w+);.*~$1~; print')
echo "Manifest file : ${mffile}"
echo "Package : ${pkg}"
echo "Brand : ${brand}"
#hasNewVersionCode=$(git diff build.gradle | grep -E '^\+' | grep versionCode | sed 's~.*0000\s*+\s*~~' | sort | tail -1) # holds only the last 3 digits
hasNewVersionCode=$(git diff build.gradle | grep 'versionCodeXXX =' | sed 's~def versionCodeXXX = ~~' | grep -v '-' | sed 's~+\s*~~' | head -1 | tr -d ' ') # holds only the last 3 digits
echo "hasNewVersionCode: $hasNewVersionCode"
BU_DIR=/osshare/code/gitlab/double-yellow.be/app
if [[ ! -e ${BU_DIR} ]]; then
BU_DIR=/mnt/c/code/gitlab/double-yellow.be/app
fi
productFlavor="phoneTabletPost23"
relapk=$(find . -name "*${productFlavor}-Xrelease.apk")
if [[ ! -e ${relapk} ]]; then
relapk=$(find ${BU_DIR} -name "Score-${brand}.${productFlavor}*${hasNewVersionCode}.apk")
fi
if [[ -e ${relapk} ]]; then
apkFileTime=$(find ${relapk} -maxdepth 0 -printf "%Ty%Tm%Td%TH%TM.%.2TS")
echo "Comparing changetime of files against ${relapk} (${apkFileTime})"
changedFiles="$(find . -type f -newer ${relapk} | grep -E -v '(intermediates)' | grep -E '\.(java|xml|md|gradle)' | grep -E -v '(\.idea/|/\.gradle/|/generated/|/reports/)')"
else
changedFiles="No release apk to compare with"
fi
# make a small modification in preferences date value so 'Quick Intro' will not play for 1 or 2 days (to allow better PlayStore automated testing)
#if grep -q ${mffile} .gitignore; then
if [[ -z "${hasNewVersionCode}" ]]; then
echo "Not modifying PreferenceValues.java for build ${mffile}"
else
todayYYYYMMDD=$(date --date='1 day' +%Y-%m-%d)
if [[ -n "$(grep 'NO_SHOWCASE_FOR_VERSION_BEFORE =' ./src/com/doubleyellow/scoreboard/prefs/PreferenceValues.java | grep -v ${todayYYYYMMDD})" ]]; then
echo "Adapting NO_SHOWCASE_FOR_VERSION_BEFORE to $todayYYYYMMDD in PreferenceValues.java"
sed -i "s~\(NO_SHOWCASE_FOR_VERSION_BEFORE\s*=\s*.\)[0-9-]*~\1${todayYYYYMMDD}~" ./src/com/doubleyellow/scoreboard/prefs/PreferenceValues.java
#echo "TEMPORARY NOT CHANGING DATE TO TEST CASTING AND CHRONOS"
fi
fi
if [[ -z "${hasNewVersionCode}" ]]; then
if [[ -n "$(grep versionCode build.gradle)" ]]; then
echo "Specify new version code for ${brand}"
read -p "Open build.gradle [Y/n] ?" ANWSER
if [[ "${ANWSER:-y}" = "y" ]]; then
vi +/versionCode build.gradle
exit 1
fi
else
read -t 3 -p "Warning : continue without changing version code for ${brand} ?"
fi
fi
## will be repopulated by ./gradlew
#/bin/rm -rf -v .gradle
## will be repopulated during build
#/bin/rm -rf -v build
#/bin/rm -rfv $HOME/.android/build-cache
if [[ 1 -eq 2 ]]; then
echo "TEMP EXIT"
exit 1
fi
iStep=${2:-1}
echo "Changed files : $changedFiles"
if [[ -n "${changedFiles}" ]]; then
echo "*** There were changes. ${changedFiles}"
echo "*** Rebuilding..."
if [[ ${iStep} -gt 2 ]]; then
iStep=1
fi
else
echo "*** There were no changes. Not rebuilding..."
if [[ ${iStep} -eq 1 ]]; then
iStep=2
fi
fi
ADB_COMMAND=$(which adb || which adb.exe)
if [[ ${iStep} -le 1 ]]; then
echo "Cleaning ... ${pkg}"
./gradlew clean
echo "Building ... ${pkg}"
if ./gradlew assemble; then
productFlavors="phoneTabletPre22 phoneTabletPost23 wearOs"
for productFlavor in ${productFlavors}; do
relapk=$(find . -name "*-${productFlavor}-release.apk")
dbgapk=$(find . -name "*-${productFlavor}-debug.apk")
# determine correct version number from manifest
if [[ -e build/intermediates/merged_manifests/${productFlavor}Release ]]; then
mergedManifest=$(find build/intermediates/merged_manifests/${productFlavor}Release -name AndroidManifest.xml)
echo "Merged manifest: ${mergedManifest}"
versionCode=$(head ${mergedManifest} | grep versionCode | sed -e 's~[^0-9]~~g')
echo "Merged manifest versionCode: ${versionCode}"
if [[ -e ${BU_DIR} ]]; then
if [[ -e ${relapk} ]]; then
cp -v -p --backup ${relapk} ${BU_DIR}/Score-${brand}.${productFlavor}-${versionCode}.apk
else
echo "No release file. Maybe because no signingconfig in build.gradle ?!"
cp -v -p --backup ${dbgapk} ${BU_DIR}/Score-${brand}.${productFlavor}-${versionCode}.DEBUG_NO_RELEASE.apk
fi
else
echo "NOT making backup in non existing directory ${BU_DIR}"
fi
else
echo "WARN: could not find build/intermediates/merged_manifests/${productFlavor}Release"
fi
#read -p "Does copy look ok"
if [[ 1 -eq 2 ]]; then
if [[ -n "${relapk}" ]]; then
ls -l ${relapk}
echo "${ADB_COMMAND} -s \${device} install -r Squore/${relapk}"
fi
if [[ -n "${dbgapk}" ]]; then
ls -l ${dbgapk}
echo "${ADB_COMMAND} -s \${device} install -r Squore/${dbgapk}"
fi
fi
done
else
echo '#################### Building failed #####################' > /dev/stderr
exit 1
fi
fi
if [[ ${iStep} -le 2 ]]; then
devices="$(${ADB_COMMAND} devices | grep -E -v '(List of|^$)' | sed 's~ *device~~')"
echo "Devices: ${devices}"
for dvc in ${devices}; do
if [[ -z "${dvc}" ]]; then
continue
fi
build_version_sdk=$( ${ADB_COMMAND} -s ${dvc} shell getprop ro.build.version.sdk | sed -e 's~[^0-9]~~')
build_product_model=$( ${ADB_COMMAND} -s ${dvc} shell getprop ro.product.model)
build_characteristics=$(${ADB_COMMAND} -s ${dvc} shell getprop ro.build.characteristics) # "emulator,nosdcard,watch",default
echo "Device ${dvc} : Version= ${build_version_sdk}, Model= ${build_product_model}, Characteristicts= ${build_characteristics}"
productFlavor="phoneTabletPost23"
if [[ ${build_version_sdk} -lt 23 ]]; then
productFlavor="phoneTabletPre22"
fi
#if [[ "${build_product_model}" =~ "wear" ]]; then
# productFlavor="wearOs"
#fi
if [[ "${build_characteristics}" =~ "watch" ]]; then
productFlavor="wearOs"
fi
#mergedManifest=$(find build/intermediates/merged_manifests/${productFlavor}Release -name AndroidManifest.xml)
#versionCode=$(head ${mergedManifest} | grep versionCode | sed -e 's~[^0-9]~~g')
#apkFile=${BU_DIR}/Score-${brand}.${productFlavor}-${versionCode}.apk
apkFile=${BU_DIR}/Score-${brand}.${productFlavor}*${hasNewVersionCode}.apk
echo "Installing new ${productFlavor} version ${hasNewVersionCode} on device ${dvc}... (${apkFile})"
#echo "[TMP] Uninstalling previous version of ${pkg} ..."
#adb -s ${dvc} uninstall ${pkg}
apkFile=$(echo ${apkFile} | sed 's~/mnt/c~c:~') # in ubuntu shell the apk should be passed without the /mnt/c path
${ADB_COMMAND} -s ${dvc} install -r ${apkFile} 2> tmp.adb.install # 1> /dev/null
if grep failed tmp.adb.install; then
echo "Uninstalling previous version of ${pkg} to install new version ..."
# uninstall previous app
${ADB_COMMAND} -s ${dvc} uninstall ${pkg}
echo "Installing new version ${hasNewVersionCode} (after uninstall) ..."
${ADB_COMMAND} -s ${dvc} install -r ${apkFile} 2> tmp.adb.install
fi
# launch the app
echo "Launching the app ${pkg} ..."
${ADB_COMMAND} -s ${dvc} shell monkey -p ${pkg} -c android.intent.category.LAUNCHER 1 > /dev/null 2> /dev/null
set +x
# adb -s ${dvc} logcat
echo "${ADB_COMMAND} -s ${dvc} logcat | grep -E '(SB|doubleyellow)' | grep -E -v '(AutoResize)'"
done
if [[ -z "${devices}" ]]; then
echo "############### No devices found to install the app..."
fi
rm tmp.adb.install 2> /dev/null
echo "tmp files cleaned"
fi
# install a shortcut
# pkg=com.doubleyellow.scoreboard
#
# adb -d shell am broadcast \
# -a com.android.launcher.action.INSTALL_SHORTCUT \
# --es Intent.EXTRA_SHORTCUT_NAME "Squore" \
# --esn Intent.EXTRA_SHORTCUT_ICON_RESOURCE \
# ${pkg}/.activity
#