-
Notifications
You must be signed in to change notification settings - Fork 11
/
build.sh
executable file
·108 lines (93 loc) · 2.46 KB
/
build.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
#!/bin/bash
function scandir() {
local cur_dir parent_dir workdir
workdir=$1
cd ${workdir}
if [ ${workdir} = "/" ]
then
cur_dir=""
else
cur_dir=$(pwd)
fi
for dirlist in $(ls ${cur_dir})
do
if test -d ${dirlist};then
cd ${dirlist}
scandir ${cur_dir}/${dirlist}
cd ..
else
echo ${cur_dir}/${dirlist}
echo "\n"
fi
done
}
function usage() {
echo "usage: sh build.sh [debug|release]"
}
# Verification
if [ $# != "1" ]; then
usage
exit 1
fi
# Clean up
echo 'Cleanning up...'
rm -rf build
# Init
echo 'Initializing build environment...'
mkdir build
mkdir build/gen
mkdir build/bin
mkdir build/bin/classes
# Configurations
res="-S res -S libs/SlidingUpPanel/res" # Resources
ext_pkg='com.sothree.slidinguppanel.library' # Package that needs resources
src='src libs/SlidingUpPanel/src libs/SystemBarTint/src build/gen' # Sources
jar="$ANDROID_JAR:libs/android-support-v4.jar:libs/gson-2.2.2.jar:libs/SlidingUpPanel/libs/nineoldandroids-2.4.0.jar" # JARs
manifest='AndroidManifest.xml' # Manifest
assets='assets' # Assets
pkgs='us.shandian.blacklight' # Packages that needs to generate BuildConfig
# Run aapt
echo 'Compiling resources...'
aapt p -m -M $manifest -A $assets -I $ANDROID_JAR $res --extra-packages $ext_pkg --auto-add-overlay -J build/gen -F build/bin/build.apk
# Generate BuildConfig
echo 'Generating BuildConfig...'
if [ ${1} = "debug" ]; then
flag="true"
elif [ ${1} = "release" ]; then
flag="false"
fi
for pkg in $pkgs
do
path="build/gen/${pkg//.//}"
mkdir -p $path
echo -e "package $pkg;\npublic class BuildConfig {\n public static final boolean DEBUG=$flag;\n}" >> "$path/BuildConfig.java"
done
# Get list of sources
echo 'Generating list of sources...'
for dir in $src
do
echo -e `scandir $dir` >> build/bin/sources.list
done
# Run javac
echo 'Compiling Java sources...'
javac -encoding utf-8 -cp $jar @build/bin/sources.list -d build/bin/classes
# Dex
echo 'Dexing...'
jar=${jar//:/ }
jar=${jar//$ANDROID_JAR/}
dx --dex --no-strict --output=build/bin/classes.dex build/bin/classes $jar
# Merge the dex and the apk
echo 'Merging...'
cd build/bin
aapt a build.apk classes.dex
cd ../..
# Sign
echo 'Signing...'
if [ ${1} = "debug" ]; then
jarsigner -keystore keystore/debug.keystore -storepass android build/bin/build.apk my_alias
elif [ ${1} = "release" ]; then
# Jarsigner will ask me for my passwords ^_^
jarsigner -keystore keystore/publish.keystore build/bin/build.apk peter
fi
# Finished
echo "Apk built for $1: ${PWD}/build/bin/build.apk"