-
Notifications
You must be signed in to change notification settings - Fork 8
/
build.sh
executable file
·119 lines (102 loc) · 2.57 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
109
110
111
112
113
114
115
116
117
118
119
#!/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
if [ "${dirlist##*.}" = "java" ]; then
echo ${cur_dir}/${dirlist}
echo "\n"
fi
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/appcompat/res" # Resources
ext_pkg='android.support.v7.appcompat' # Package that needs resources
src='src build/gen' # Sources
jar="$ANDROID_JAR:libs/android-support-v4.jar:libs/android-support-v7-appcompat.jar" # JARs
manifest='AndroidManifest.xml' # Manifest
assets='assets' # Assets
pkgs='com.paperairplane.music.share' # Packages that needs to generate BuildConfig
aidl='src/com/sina/sso/RemoteSSO.aidl' # Aidls that needs building
# 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
# Aidl
echo 'Converting Aidl...'
for f in $aidl
do
aidl -obuild/gen $f
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"