-
Notifications
You must be signed in to change notification settings - Fork 0
/
build.sh
executable file
·97 lines (76 loc) · 3.2 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
#!/bin/sh
sdk=$ANDROID_HOME
outputDirForGeneratedSourceFiles='generated_java_sources'
outputDirForBytecode='java_virtual_machine_bytecode'
outputDexFilepath='classes.dex'
filepathOfAPK="app.apk"
filepathOfUnalignedAPK="${filepathOfAPK}.unaligned"
# Use the latest build tools version...
buildTools=$sdk/build-tools/$(/bin/ls $sdk/build-tools | sort -n | tail -1)
# ...and the latest platform version.
platform=$sdk/platforms/$(/bin/ls $sdk/platforms | sort -n |tail -1)
androidLib=$platform/android.jar
_aapt=$buildTools/aapt
_dx=$buildTools/dx
manifestFilepath=$PWD/AndroidManifest.xml
resourcesFilepath=$PWD/xml
javaSourcesFilepath=$PWD/java
main() {
makeOutputDirs && \
generateJavaFileForAndroidResources && \
compileJavaSourceFilesToJavaVirtualMachineBytecode && \
translateJavaVirtualMachineMBytecodeToAndroidRuntimeBytecode && \
createUnalignedAndroidApplicationPackage && \
addAndroidRuntimeBytecodeToAndroidApplicationPackage && \
signAndroidApplicationPackageWithDebugKey && \
alignUncompressedDataInZipFileToFourByteBoundariesForFasterMemoryMappingAtRuntime && \
cleanup
}
makeOutputDirs() {
mkdir -p "$outputDirForBytecode" "$outputDirForGeneratedSourceFiles"
}
generateJavaFileForAndroidResources() {
# aapt package
#
# Package the android resources. It will read assets and resources that are
# supplied with the -M -A -S or raw-files-dir arguments. The -J -P -F and -R
# options control which files are output.
#
# -f force overwrite of existing files
# -m make package directories under location specified by -J
# -J specify where to output R.java resource constant definitions
# -M specify full path to AndroidManifest.xml to include in zip
# -S directory in which to find resources. Multiple directories will be scanned
# and the first match found (left to right) will take precedence.
# -I add an existing package to base include set
$_aapt package -f -m -J "$outputDirForGeneratedSourceFiles" -M "$manifestFilepath" -S "$resourcesFilepath" -I "$androidLib"
}
compileJavaSourceFilesToJavaVirtualMachineBytecode() {
javac \
-classpath "$androidLib" \
-sourcepath "$javaSourcesFilepath:$outputDirForGeneratedSourceFiles" \
-d "$outputDirForBytecode" \
-target 1.7 \
-source 1.7 \
$(find $javaSourcesFilepath -name '*.java') \
$(find $outputDirForGeneratedSourceFiles -name '*.java')
}
translateJavaVirtualMachineMBytecodeToAndroidRuntimeBytecode() {
$_dx --dex --output="$outputDexFilepath" "$outputDirForBytecode"
}
createUnalignedAndroidApplicationPackage() {
$_aapt package -f -M "$manifestFilepath" -S "$resourcesFilepath" -I "$androidLib" -F "$filepathOfUnalignedAPK"
}
addAndroidRuntimeBytecodeToAndroidApplicationPackage() {
( $_aapt add "$filepathOfUnalignedAPK" "$outputDexFilepath" ) 1>&2
}
signAndroidApplicationPackageWithDebugKey() {
( jarsigner -keystore "$HOME/.android/debug.keystore" -storepass 'android' "$filepathOfUnalignedAPK" androiddebugkey ) 1>&2
}
alignUncompressedDataInZipFileToFourByteBoundariesForFasterMemoryMappingAtRuntime() {
$buildTools/zipalign -f 4 "$filepathOfUnalignedAPK" "$filepathOfAPK"
}
cleanup() {
rm -rf "$outputDirForBytecode" "$outputDirForGeneratedSourceFiles" "$filepathOfUnalignedAPK" "$outputDexFilepath"
}
main