mirror of
https://github.com/apache/cordova-android.git
synced 2025-01-19 15:12:51 +08:00
adding install function
This commit is contained in:
parent
0084c6f96a
commit
a6473cb826
@ -17,11 +17,11 @@
|
|||||||
|
|
||||||
#!/bin/bash
|
#!/bin/bash
|
||||||
|
|
||||||
set -e
|
|
||||||
|
|
||||||
PROJECT_PATH=$( cd "$( dirname "$0" )/.." && pwd )
|
PROJECT_PATH=$( cd "$( dirname "$0" )/.." && pwd )
|
||||||
|
|
||||||
function check_devices {
|
function check_devices {
|
||||||
|
# FIXME
|
||||||
local devices=`adb devices | awk '/List of devices attached/ { while(getline > 0) { print }}' | grep device`
|
local devices=`adb devices | awk '/List of devices attached/ { while(getline > 0) { print }}' | grep device`
|
||||||
if [ -z "$devices" ] ; then
|
if [ -z "$devices" ] ; then
|
||||||
echo "1"
|
echo "1"
|
||||||
@ -37,7 +37,6 @@ function emulate {
|
|||||||
|
|
||||||
# Do not launch an emulator if there is already one running or if a device is attached
|
# Do not launch an emulator if there is already one running or if a device is attached
|
||||||
if [ $(check_devices) == 0 ] ; then
|
if [ $(check_devices) == 0 ] ; then
|
||||||
# echo "Device attached or emulator already running"
|
|
||||||
return
|
return
|
||||||
fi
|
fi
|
||||||
|
|
||||||
@ -62,8 +61,9 @@ function emulate {
|
|||||||
do
|
do
|
||||||
echo "$i) ${avd_list[$i]}"
|
echo "$i) ${avd_list[$i]}"
|
||||||
done
|
done
|
||||||
echo -n "> "
|
read -t 5 -p "> " avd_id
|
||||||
read avd_id
|
# default value if input timeout
|
||||||
|
if [ $avd_id -eq 1000 ] ; then avd_id=0 ; fi
|
||||||
done
|
done
|
||||||
emulator -cpu-delay 0 -no-boot-anim -cache /tmp/cache -avd ${avd_list[$avd_id]} 1> /dev/null 2>&1 &
|
emulator -cpu-delay 0 -no-boot-anim -cache /tmp/cache -avd ${avd_list[$avd_id]} 1> /dev/null 2>&1 &
|
||||||
fi
|
fi
|
||||||
@ -79,17 +79,41 @@ function log {
|
|||||||
}
|
}
|
||||||
|
|
||||||
function run {
|
function run {
|
||||||
if [ $(check_devices) == 0 ] ; then
|
clean && emulate && wait_for_device && install && launch
|
||||||
clean && emulate && install && launch
|
|
||||||
else
|
|
||||||
build
|
|
||||||
echo "##################################################################"
|
|
||||||
echo "# Plug in your device or launch an emulator with cordova/run #"
|
|
||||||
echo "##################################################################"
|
|
||||||
fi
|
|
||||||
}
|
}
|
||||||
|
|
||||||
function install {
|
function install {
|
||||||
|
|
||||||
|
declare -a devices=($(adb devices | awk '/List of devices attached/ { while(getline > 0) { print }}' | grep device | cut -f 1))
|
||||||
|
local device_id="1000" #FIXME: hopefully user does not have 1000 AVDs
|
||||||
|
|
||||||
|
if [ ${#devices[@]} == 0 ]
|
||||||
|
then
|
||||||
|
# should not reach here. Emulator should launch or device should be attached
|
||||||
|
echo "Emulator not running or device not attached. Could not install debug package"
|
||||||
|
exit 70
|
||||||
|
fi
|
||||||
|
|
||||||
|
if [ ${#devices[@]} == 1 ]
|
||||||
|
then
|
||||||
|
export ANDROID_SERIAL=${devices[0]}
|
||||||
|
# User has more than 1 AVD
|
||||||
|
elif [ ${#devices[@]} -gt 1 ]
|
||||||
|
then
|
||||||
|
while [ -z ${devices[$device_id]} ]
|
||||||
|
do
|
||||||
|
echo "Choose from one of the following devices/emulators [0 to $((${#devices[@]}-1))]:"
|
||||||
|
for(( i = 0 ; i < ${#devices[@]} ; i++ ))
|
||||||
|
do
|
||||||
|
echo "$i) ${devices[$i]}"
|
||||||
|
done
|
||||||
|
read -t 5 -p "> " device_id
|
||||||
|
# default value if input timeout
|
||||||
|
if [ $device_id -eq 1000 ] ; then device_id=0 ; fi
|
||||||
|
done
|
||||||
|
export ANDROID_SERIAL=${devices[$device_id]}
|
||||||
|
fi
|
||||||
|
|
||||||
ant debug install
|
ant debug install
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -98,14 +122,28 @@ function build {
|
|||||||
}
|
}
|
||||||
|
|
||||||
function wait_for_device {
|
function wait_for_device {
|
||||||
local i=0
|
local i="0"
|
||||||
echo "Waiting for emulator..."
|
echo -n "Waiting for device..."
|
||||||
while [ check_devices -eq 0 || timeout -lt 300 ]
|
|
||||||
|
while [ $i -lt 300 ]
|
||||||
do
|
do
|
||||||
|
if [ $(check_devices) -eq 0 ]
|
||||||
|
then
|
||||||
|
break
|
||||||
|
else
|
||||||
sleep 1
|
sleep 1
|
||||||
i=$[i+1]
|
i=$[i+1]
|
||||||
end
|
echo -n "."
|
||||||
|
fi
|
||||||
|
done
|
||||||
|
# Device timeout: emulator has not started in time or device not attached
|
||||||
|
if [ $i -eq 300 ]
|
||||||
|
then
|
||||||
|
echo "device timeout!"
|
||||||
|
exit 69
|
||||||
|
else
|
||||||
|
echo "connected!"
|
||||||
|
fi
|
||||||
}
|
}
|
||||||
|
|
||||||
function launch {
|
function launch {
|
||||||
|
Loading…
Reference in New Issue
Block a user