blob: dba53df6a2c5f1d9ca920629e785febe1e7ba910 (
plain)
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
|
#!/bin/bash
if [[ "$snapsource" == "" ]]
then
export snapsource="https://github.com/Gubolin/snap.git"
fi
if [[ $1 = "" ]]
then
echo "Usage: mobile.sh PLATFORM [BUILDSOURCE]"
exit 0
fi
scriptdir=$(readlink -e ".")
# Requirements:
# git, nodejs, android SDK / other platform(s)
# cordova (https://cordova.apache.org/)
# optional: crosswalk-cordova (https://github.com/crosswalk-project/crosswalk-cordova-android)
if [[ $2 != "" ]]
then
buildsource=$(readlink -e "$2")
fi
builddir=$(mktemp -d)
cordova create $builddir edu.berkeley.snap "Snap\!"
cd $builddir
rm -rf www config.xml
if [[ $2 == "" ]]
then
git clone "$snapsource" www
cd www/
else
mv "$buildsource" www
cd www
fi
# 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
echo "Adding cordova plugins"
# add everything needed and build for $device
cordova platform add "$1" > /dev/null
cordova plugin add org.apache.cordova.geolocation \
org.apache.cordova.device-motion \
org.apache.cordova.device-orientation \
org.apache.cordova.network-information \
org.apache.cordova.vibration 2> /dev/null
#org.apache.cordova.plugin.softkeyboard \
#de.appplant.cordova.plugin.local-notification
if [[ $1 == "android" ]]
then
# Remove default icons
cd "$builddir/platforms/android"
find -name '*.png' | xargs rm
if [[ $crosswalk != "" ]]
then
# adapted from https://crosswalk-project.org/documentation/cordova/migrate_an_application.html#migrate
echo "Preparing crosswalk"
rm -Rf "$builddir/platforms/android/CordovaLib/*"
cp -a $crosswalk/framework/* "$builddir/platforms/android/CordovaLib/"
cp -a "$crosswalk/VERSION" "$builddir/platforms/android/"
export ANDROID_HOME=$(dirname $(dirname $(which android)))
cd "$builddir/platforms/android/CordovaLib/"
android update project --subprojects --target android-21 --path . > /dev/null
ant debug > /dev/null
cd "$builddir"
# prepend permissions to end of manifest
sed -i "s,</manifest>,\
<uses-permission android:name=\"android.permission.ACCESS_WIFI_STATE\" />\
<uses-permission android:name=\"android.permission.ACCESS_NETWORK_STATE\" />\
<uses-permission android:name=\"android.permission.INTERACT_ACROSS_USERS\" />\
</manifest>,g" \
"$builddir/platforms/android/AndroidManifest.xml"
fi
fi
echo "Building application"
cordova build "$1" > /dev/null
cd $builddir
# TODO other platforms
find -name '*.apk' | xargs -I {} mv {} $scriptdir
echo "Finished."
|