Last active
May 24, 2023 13:13
-
-
Save franzwarning/d71d7fc50ed1a37c513dc3da8a73ab04 to your computer and use it in GitHub Desktop.
Fastlane capture_android_screenshots/screengrab android on multiple devices at the same time
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
# Script adb+ | |
# Usage | |
# You can run any command adb provide on all your current devices | |
# ./adb+ <command> is the equivalent of ./adb -s <serial number> <command> | |
# | |
# Examples | |
# ./adb+ version | |
# ./adb+ install apidemo.apk | |
# ./adb+ uninstall com.example.android.apis | |
adb devices | while read line | |
do | |
if [ ! "$line" = "" ] && [ `echo $line | awk '{print $2}'` = "device" ] | |
then | |
device=`echo $line | awk '{print $1}'` | |
echo "$device $@ ..." | |
adb -s $device $@ || echo "already uninstalled" | |
fi | |
done |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
lane :build_for_screenshots do | |
gradle( | |
task: 'assemble', | |
build_type: 'Screenshots' | |
) | |
gradle( | |
task: 'assemble', | |
build_type: 'ScreenshotsAndroidTest' | |
) | |
end | |
lane :screenshots do | |
def do_screenshot_on_device(device_name, device_type) | |
# close all simulators | |
sh('adb devices | grep emulator | cut -f1 | while read line; do adb -s $line emu kill; done') | |
sh('sleep 3') | |
# open simulator | |
sh('emulator -avd %s > /dev/null 2>&1 &' % device_name) | |
while true | |
adb_output = adb(command: 'devices') | |
puts('output of command' + adb_output) | |
if adb_output.match(/emulator-([0-9]*)\tdevice/) | |
break | |
sh('sleep 3') | |
end | |
sh('sleep 3') | |
end | |
# uninstall old tests | |
begin | |
sh('../adb+.sh uninstall "example.bundle.id.test"') | |
rescue => ex | |
UI.error(ex) | |
end | |
sh('../adb+.sh install ../app/build/outputs/apk/screenshots/app-screenshots.apk') | |
sh('../adb+.sh install ../app/build/outputs/apk/androidTest/screenshots/app-screenshots-androidTest.apk') | |
capture_android_screenshots( | |
device_type: device_type | |
) | |
end | |
do_screenshot_on_device('Nexus_10_API_28', 'tenInch') | |
do_screenshot_on_device('Nexus_6_API_29', 'phone') | |
end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
app_apk_path('./app/build/outputs/apk/screenshots/app-screenshots.apk') | |
tests_apk_path('./app/build/outputs/apk/androidTest/screenshots/app-screenshots-androidTest.apk') | |
output_directory('./fastlane/screenshots') | |
use_adb_root(true) | |
clear_previous_screenshots(true) | |
locales(['en-US']) | |
# clear all previously generated screenshots in your local output directory before creating new ones | |
skip_open_summary(true) | |
# For more information about all available options run | |
# fastlane screengrab --help |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
I wanted to be able to automate taking screenshots on MULTIPLE DEVICES using fastlane. I couldn't quite find anything that did the trick. What my
screenshots
lane does it 1 by 1 launch emulators, wait for them to load, install tests, then run the fastlane screengrab action. You need to runbuild_for_screenshots
before running screenshots. Be sure to replace the template bundle id with your own. Also note that normally you'd want to run with debug build variant but I'm using a build variant called "screenshots". I hope this is helpful to somebody! Feel free to post a question and I'll try to respond quickly.