Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

ADB Error codes

Tags:

We have an android device and as part of testing I need to excute a console test application on the target device. If the test application detects an error it returns -1.

I can use adb shell to run the test applications remotely on the target but I can't find a way of getting back the return code. I need this so I that I can build this into an automated test suite.

I could try grepping the console output for some failure text but that is a bit grubby. Does anyone know of a more elegant solution?

like image 437
Ian Stroud Avatar asked Feb 21 '12 14:02

Ian Stroud


People also ask

What is ADB error?

ADB device not found is an error that usually occurs when there is a problem with your ADM device driver. ADB, which stands for Android Debug Bridge, is a command-line tool that lets you communicate with a device. In this instance, it would allow you to control a device over USB from your computer.

What are ADB commands?

Android Debug Bridge (adb) is a versatile command-line tool that lets you communicate with a device. The adb command facilitates a variety of device actions, such as installing and debugging apps, and it provides access to a Unix shell that you can use to run a variety of commands on a device.


2 Answers

This is a workaround to get the exit code: adb shell '{your command here} > /dev/null 2>&1; echo $?'

This is a wrapper around adb in Ruby:

def adb(opt)   input = "#{adb_command} #{opt[:command]} #{opt[:params]}"   puts "Executing #{input}...\n"   output = nil   exit_code = 0    def wait_for(secs)     if secs       begin         Timeout::timeout(secs) { yield }       rescue         print 'execution expired'       end     else       yield     end   end    wait_for(opt[:timeout]) do     case opt[:command]     when :install, :push, :uninstall       output, exit_code = `#{input}`, $?.to_i     when :shell       input = "#{adb_command} shell \"#{opt[:params]}; echo \\$?\""       output = `#{input}`.split("\n")       exit_code = output.pop.to_i       output = output.join("\n")     else       raise 'Error: param command to adb not defined!'     end   end    return if opt[:ignore_fail] and output =~ /#{opt[:ignore_fail]}/   raise output unless exit_code == 0 end 
like image 103
Paulo Henrique Nonaka Avatar answered Sep 21 '22 17:09

Paulo Henrique Nonaka


You could use Facebook's fb-adb, a "A better shell for Android devices" which "propagates program exit status instead of always exiting with status 0".

like image 43
sschuberth Avatar answered Sep 21 '22 17:09

sschuberth