0

when using ant to install android apps, it will hang if there is no android device connected to the machine. It will just wait for the user to connect one, which interrupts the autonomous nature of the script.

How can I set some kind of conditional statement to check if there are any devices attached to the computer before running the install script?

CQM
  • 42,592
  • 75
  • 224
  • 366

2 Answers2

1

I would do something like this from ant script

  • Call "adb devices"
  • Parse output (to see how many devices are connected)
  • Check number of connected devices in ant conditional statement.
Victor Ronin
  • 22,758
  • 18
  • 92
  • 184
  • can you write this out in some code? these are the things I want ant to do but I'm not sure how you would do it with Ant – CQM Oct 09 '12 at 21:53
1

I was about the suggest the same thing.

DEV=$(adb devices 2>&1 | tail -n +2 | sed '/^$/d')
if [ -z "$DEV" ]
then
   echo "No devices" >&2
   exit 1
fi
Durairaj Packirisamy
  • 4,635
  • 1
  • 21
  • 27
  • okay, so I am already calling my ant script from a python script. I don't know if I can justify adding a bash script on top of that. is there another way to control the adb command within ant? like perhaps some flags I can add – CQM Oct 09 '12 at 22:02
  • Do the same thing in the python script (ofcourse with python syntax), I just provided an example – Durairaj Packirisamy Oct 09 '12 at 22:11