forked from playgameservices/cpp-android-basic-samples
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbuild_sample.sh
More file actions
116 lines (97 loc) · 3.06 KB
/
build_sample.sh
File metadata and controls
116 lines (97 loc) · 3.06 KB
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
#!/bin/bash
set -eua
declare result=0
declare -r required_vars=( \
ANDROID_HOME \
NDK_ROOT \
NDK_MODULE_PATH )
echo Checking Environment... >&2
# Check that all of the required environment variables are set, and
# point to valid paths.
#
for varname in ${required_vars[@]}; do
if [[ ! -v ${varname} ]]; then
echo "PROBLEM: ${varname} not set" >&2
result=1
else
eval path=\$${varname}
if [[ ! -e "${path}" ]]; then
echo "PROBLEM: ${varname} (${path}) does not exist" >&2
result=1
fi
fi
done
[[ ${result} -ne 0 ]] && exit ${result}
# Now check the subdirectories and files we'll actually be using
# to make sure they all exist.
#
declare -r lib_rel_path="/extras/google/google_play_services/libproject/\
google-play-services_lib"
# Paths to check
declare -r required_paths=( \
"${ANDROID_HOME}/tools/android" \
"${NDK_ROOT}/ndk-build" \
"${ANDROID_HOME}/${lib_rel_path}/project.properties"
"${NDK_MODULE_PATH}/gpg-cpp-sdk/android/lib"
"./AndroidManifest.xml"
"./jni/Android.mk" )
# (Hopefully) helpful note to be displayed if a path check fails. Keep in
# sync with the "required_paths" array above.
declare -r remedies=( \
"Be sure ANDROID_HOME points to the location of a valid Android SDK." \
"Be sure NDK_ROOT points to the location of a valid Android NDK." \
"Is the Play Games Services SDK package installed?" \
"Have you downloaded and installed the Play Games Services SDK for C++?" \
"Run this script from your project root." \
"Is this an NDK project?" )
declare -i i=0
for path in ${required_paths[@]}; do
if [[ ! -e "${path}" ]]; then
echo "ERROR: ${path} does not exist" >&2
echo " ${remedies[i]}" >&2
result=1
fi
i=i+1
done
# Make sure ant is installed.
if [[ -z `which ant` ]]; then
echo "ERROR: Can't find ant on the PATH. Please (re)install ant." >&2
result=1
fi
if [[ ${result} -ne 0 ]]; then
echo "Environment incorrect; aborting" >&2
exit ${result}
fi
echo Environment OK >&2
declare -x mode=${1:-debug}
declare -r android_tool="${ANDROID_HOME}/tools/android"
declare -r ndk_build="${NDK_ROOT}/ndk-build"
declare -r lib_project="${ANDROID_HOME}/${lib_rel_path}"
>&2 echo Preparing projects...
declare -r private_lib=".gpg-lib"
# Write out the local.properties file; replace the current one.
echo "# GENERATED by build_sample.sh -- do not modify." > local.properties
echo "sdk.dir=${ANDROID_HOME}" >> local.properties
echo "gpg.lib=${private_lib}" >> local.properties
${android_tool} update project --path .
#
# Get a private copy of the library project
#
function cleanup() {
rm -rf ${private_lib}
}
# clean before copying to ensure no garbage is left behind...
cleanup
# ...and make sure *this* script leaves no garbage behind, either.
trap cleanup EXIT
# Copy the lib project and run "android update lib-project" on it.
# This requires a target, which apparently needs to be android-10.
cp -r ${lib_project} ${private_lib}
${android_tool} update lib-project --path ${private_lib} --target android-10
#
# At last, build!
#
echo Building... >&2
${ndk_build}
ant ${mode}
echo Done >&2