-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbuild_android.sh
101 lines (74 loc) · 2.52 KB
/
build_android.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
#!/bin/bash
echo "Build Android mobile"
# USAGE: ./build_android.sh snap_file.xml
# or ./build_android.sh http://URL/snap_file.xml
# was called 'snapmobile_init.sh' for init:
# ready to user git source of snap-mobile (checkout mobileapp)
export originalsource="/home/vagrant/source-origin/snapmobile"
export cordovaplugins="/home/vagrant/source-origin/cordova/plugins"
scriptdir=$(readlink -e ".")
# project content or URL to file project
filecontent=true
if [ -f "$1" ]
then
filecontent=true
content=$(cat $1)
else
filecontent=false
url=$1
fi
buildsource=$(mktemp -d)
cp -R $originalsource $buildsource
echo "originalsource: '$originalsource'"
echo "buildsource: '$buildsource'"
cd "$buildsource/snapmobile"
rm -rf .git/
# minimize everything
rm lang* ypr.js paint.js cloud.js gui.js
sed -i '/paint\.js"/d' snap.html
sed -i '/cloud\.js"/d' snap.html
sed -i 's/gui\.js"/binary\.js"/' snap.html
# if file content
if [ $filecontent == true ]
then
# load custom project from file
sed -i '/sha512\.js"/a\
<script type="text/javascript" src="code.js"></script> ' snap.html
echo "var code =" > code.js
echo "'$content'" >> code.js
echo ";" >> code.js
sed -i "/ide\.openIn/a\
ide.droppedText(code); " snap.html
else
# url
sed -i "/ide\.openIn/a\
ide.droppedText(ide.getURL('$url')); " snap.html
fi
find . -name '*.js' | xargs -I {} uglifyjs {} -o {} -c
# return to the directory where the script was called from
cd "$scriptdir"
# ===============================================
# Android Cordova build
builddir=$(mktemp -d)
cordova create $builddir edu.berkeley.snap "Snap\!"
cd $builddir
rm -rf www config.xml
mv "$buildsource/snapmobile" www
cd www
# add mobile-specific library; it's made available at runtime
sed -i '/link rel="shortcut icon"/a\
<script type="text/javascript" src="cordova.js"></script>' snap.html
# add everything needed and build for $device
cordova platform add android
cordova plugin add $cordovaplugins/org.apache.cordova.plugin.softkeyboard
cordova plugin add $cordovaplugins/org.apache.cordova.vibration
cordova plugin add $cordovaplugins/org.apache.cordova.device-motion
cordova plugin add $cordovaplugins/org.apache.cordova.device-orientation
cordova plugin add $cordovaplugins/org.apache.cordova.geolocation
cordova plugin add $cordovaplugins/de.appplant.cordova.plugin.local-notification
# Remove default icons
cd "$builddir/platforms/android"
find -name '*.png' | xargs rm
cordova build android
cd $builddir
find -name '*.apk' | xargs -I {} mv {} $scriptdir