
30 November 2024 Leave a comment Tech-Help
When developing and debugging Android applications, accessing the log output from your devices is crucial. However, when working with multiple devices or emulators, you might encounter the error: “error: more than one device and emulator”. This guide will walk you through the process of running logcat on multiple devices efficiently.
Solution Using ADB -s Option
The most straightforward way to run logcat on multiple devices is by using the -s
option of the adb command. This option allows you to specify the serial number of the device you want to target. Here’s how you can do it:
- First, list all connected devices using the following command:
adb devices
This will output a list of the devices attached to your system, each identified by a unique serial number.
- Run logcat for each device individually by specifying the device’s serial number:
adb -s logcat
Example:
adb -s 0123456789ABCDEF logcat adb -s 192.168.198.101:5555 logcat
- For more focused output, you can combine this with grep to filter the results. For instance, to get all lines containing “System.out”:
adb -s 192.168.198.101:5555 logcat | grep "System.out"
Automating Logcat with Scripts
If you’re managing multiple devices, automating the logging process can save time. Here is a simple script that logs each device to a separate file:
#! /bin/bash
devices=`adb devices | grep 'device' | cut -f1`
pids=""
for device in $devices
do
log_file="$device-`date +%d-%m-%H:%M:%S`.log"
echo "Logging device $device to \"$log_file\""
adb -s $device logcat -v threadtime > $log_file &
pids="$pids $!"
done
echo "Children PIDs: $pids"
killemall()
{
echo "Killing children (what a shame...)"
for pid in $pids
do
echo "Killing $pid"
kill -TERM $pid
done
}
trap killemall INT
wait
This script will create a log file for each device, capturing logs in a format that includes thread time, which is useful for debugging.
Integrating with Repeato for Streamlined Testing
When working with multiple Android devices, managing logs is just one part of the testing process. To enhance your testing efficiency, consider using Repeato, a no-code test automation tool for iOS and Android. Repeato allows you to create, run, and maintain automated tests with ease. It features built-in ADB support, enabling you to execute ADB commands, including logcat, in sequence with your test scripts.
Repeato’s integration capabilities can significantly streamline your testing workflow, allowing you to focus on developing robust applications without getting bogged down by manual log management.
For more information on setting up and using Repeato, visit our documentation section.