OLD | NEW |
1 #!/bin/bash | 1 #!/bin/bash |
2 # | 2 # |
3 # android_setup.sh: Sets environment variables used by other Android scripts. | 3 # android_setup.sh: Sets environment variables used by other Android scripts. |
4 | 4 |
5 # Parse the arguments for a DEVICE_ID. | 5 # Parse the arguments for a DEVICE_ID. |
6 DEVICE_ID="" | 6 DEVICE_ID="" |
| 7 DEVICE_SERIAL="" |
7 while (( "$#" )); do | 8 while (( "$#" )); do |
8 if [[ $(echo "$1" | grep "^-d$") != "" ]]; | 9 if [[ $(echo "$1" | grep "^-d$") != "" ]]; |
9 then | 10 then |
10 DEVICE_ID=$2 | 11 DEVICE_ID=$2 |
11 shift | 12 shift |
| 13 elif [[ "$1" == "-s" ]]; |
| 14 then |
| 15 if [[ $# -lt 2 ]]; |
| 16 then |
| 17 echo "ERROR: missing serial number" |
| 18 exit 1; |
| 19 fi |
| 20 DEVICE_SERIAL="-s $2" |
| 21 shift |
12 else | 22 else |
13 APP_ARGS="$APP_ARGS $1" | 23 APP_ARGS=("${APP_ARGS[@]}" "${1}") |
14 fi | 24 fi |
15 | 25 |
16 shift | 26 shift |
17 done | 27 done |
18 | 28 |
19 APP_ARGS=$(echo ${APP_ARGS} | sed 's/^ *//g') | |
20 | |
21 function exportVar { | 29 function exportVar { |
22 NAME=$1 | 30 NAME=$1 |
23 VALUE=$2 | 31 VALUE=$2 |
24 echo export $NAME=\"$VALUE\" | 32 echo export $NAME=\"$VALUE\" |
25 export $NAME="$VALUE" | 33 export $NAME="$VALUE" |
26 } | 34 } |
27 | 35 |
28 SCRIPT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )" | 36 SCRIPT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )" |
29 | 37 |
30 # A valid Android SDK installation is required to build the sample app. | 38 # A valid Android SDK installation is required to build the sample app. |
(...skipping 172 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
203 ANDROID_ARCH="x86" | 211 ANDROID_ARCH="x86" |
204 ;; | 212 ;; |
205 *) | 213 *) |
206 echo -n "ERROR: unknown device specified ($TARGET_DEVICE), valid values: " | 214 echo -n "ERROR: unknown device specified ($TARGET_DEVICE), valid values: " |
207 echo "nexus_[s,4,7,10] xoom galaxy_nexus razr_i arm arm_thumb arm_v7 arm_v
7_thumb x86" | 215 echo "nexus_[s,4,7,10] xoom galaxy_nexus razr_i arm arm_thumb arm_v7 arm_v
7_thumb x86" |
208 return 1; | 216 return 1; |
209 ;; | 217 ;; |
210 esac | 218 esac |
211 | 219 |
212 echo "The build is targeting the device: $TARGET_DEVICE" | 220 echo "The build is targeting the device: $TARGET_DEVICE" |
| 221 export DEVICE_ID="$TARGET_DEVICE" |
213 | 222 |
214 # Set up the toolchain. | 223 # Set up the toolchain. |
215 setup_toolchain | 224 setup_toolchain |
216 if [[ "$?" != "0" ]]; then | 225 if [[ "$?" != "0" ]]; then |
217 return 1 | 226 return 1 |
218 fi | 227 fi |
219 DEFINES="${DEFINES} android_toolchain=${TOOLCHAIN_TYPE}" | 228 DEFINES="${DEFINES} android_toolchain=${TOOLCHAIN_TYPE}" |
220 | 229 |
221 # Use the "android" flavor of the Makefile generator for both Linux and OS X. | 230 # Use the "android" flavor of the Makefile generator for both Linux and OS X. |
222 exportVar GYP_GENERATORS "make-android" | 231 exportVar GYP_GENERATORS "make-android" |
(...skipping 14 matching lines...) Expand all Loading... |
237 if [ -d $HOST_DST ]; | 246 if [ -d $HOST_DST ]; |
238 then | 247 then |
239 HOST_DST="${HOST_DST}/$(basename ${ANDROID_SRC})" | 248 HOST_DST="${HOST_DST}/$(basename ${ANDROID_SRC})" |
240 fi | 249 fi |
241 | 250 |
242 echo "HOST: $HOST_DST" | 251 echo "HOST: $HOST_DST" |
243 | 252 |
244 if [ -f $HOST_DST ]; | 253 if [ -f $HOST_DST ]; |
245 then | 254 then |
246 #get the MD5 for dst and src | 255 #get the MD5 for dst and src |
247 ANDROID_MD5=`$ADB shell md5 $ANDROID_SRC` | 256 ANDROID_MD5=`$ADB $DEVICE_SERIAL shell md5 $ANDROID_SRC` |
248 HOST_MD5=`md5sum $HOST_DST` | 257 HOST_MD5=`md5sum $HOST_DST` |
249 | 258 |
250 if [ "${ANDROID_MD5:0:32}" != "${HOST_MD5:0:32}" ]; | 259 if [ "${ANDROID_MD5:0:32}" != "${HOST_MD5:0:32}" ]; |
251 then | 260 then |
252 $ADB pull $ANDROID_SRC $HOST_DST | 261 $ADB $DEVICE_SERIAL pull $ANDROID_SRC $HOST_DST |
253 # else | 262 # else |
254 # echo "md5 match of android [$ANDROID_SRC] and host [$HOST_DST]" | 263 # echo "md5 match of android [$ANDROID_SRC] and host [$HOST_DST]" |
255 fi | 264 fi |
256 else | 265 else |
257 $ADB pull $ANDROID_SRC $HOST_DST | 266 $ADB $DEVICE_SERIAL pull $ANDROID_SRC $HOST_DST |
258 fi | 267 fi |
259 } | 268 } |
260 | 269 |
| 270 # adb_push_if_needed(host_src, android_dst) |
| 271 adb_push_if_needed() { |
| 272 |
| 273 # get adb location |
| 274 source $SCRIPT_DIR/utils/setup_adb.sh |
| 275 |
| 276 # read input params |
| 277 HOST_SRC="$1" |
| 278 ANDROID_DST="$2" |
| 279 |
| 280 ANDROID_LS=`$ADB $DEVICE_SERIAL shell ls -ld $ANDROID_DST` |
| 281 if [ "${ANDROID_LS:0:1}" == "d" ]; |
| 282 then |
| 283 ANDROID_DST="${ANDROID_DST}/$(basename ${HOST_SRC})" |
| 284 fi |
| 285 |
| 286 echo "ANDROID: $ANDROID_DST" |
| 287 |
| 288 ANDROID_LS=`$ADB $DEVICE_SERIAL shell ls -ld $ANDROID_DST` |
| 289 if [ "${ANDROID_LS:0:1}" == "-" ]; |
| 290 then |
| 291 #get the MD5 for dst and src |
| 292 ANDROID_MD5=`$ADB $DEVICE_SERIAL shell md5 $ANDROID_DST` |
| 293 HOST_MD5=`md5sum $HOST_SRC` |
| 294 |
| 295 if [ "${ANDROID_MD5:0:32}" != "${HOST_MD5:0:32}" ]; |
| 296 then |
| 297 $ADB $DEVICE_SERIAL push $HOST_SRC $ANDROID_DST |
| 298 # else |
| 299 # echo "md5 match of android [${ANDROID_DST}] and host [${HOST_SRC}]" |
| 300 fi |
| 301 else |
| 302 $ADB $DEVICE_SERIAL push $HOST_SRC $ANDROID_DST |
| 303 fi |
| 304 } |
| 305 |
261 # Set up the device. | 306 # Set up the device. |
262 setup_device "${DEVICE_ID}" | 307 setup_device "${DEVICE_ID}" |
263 if [[ "$?" != "0" ]]; then | 308 if [[ "$?" != "0" ]]; then |
264 exit 1 | 309 exit 1 |
265 fi | 310 fi |
OLD | NEW |