A utility library to automate mobile emulators.

Overview

emulators

A utility library to automate mobile emulators.

Can be used to automate screenshots on multiple devices.

Example project

https://github.com/tim-smart/flutter-emulators-screenshots-demo

This project demonstrates how to use this package to generate screenshots for a Flutter project.

FAQ

Random errors / hangs with Android emulators

You might hit an adb bug. A symptom is that the output of the command adb -s emulator-5554 emu avd name is empty when the emulator is running (where emulator-5554 is the name of your emulator).

If the file ~/.emulator_console_auth_token exists and is empty, stop the emulator and remove the file.

See https://github.com/tim-smart/dart_emulators/issues/4 for more info.

Comments
  • emu.forEach hangs waiting for Android emulators

    emu.forEach hangs waiting for Android emulators

    In my Linux installation (with Android Studio, flutter doctor ok, no issues with flutter run or emulators in general) emu.forEach hangs waiting for Android emulators. After 3 minutes, the timeout kicks in:

    $ dart tools/screenshots.dart 
    Shutdown all emulators
    Creating Nexus_5X emulator
    Launching screenshots
    Unhandled exception:
    TimeoutException after 0:03:00.000000: Future not completed
    

    I tried to switch image for Nexus_5X, with no luck:

    • system-images;android-30;google_apis;x86_64
    • system-images;android-30;google_apis;x86
    • system-images;android-30;google_apis_playstore;x86

    If i issue flutter run with the emulator running, I can use/debug the app normally. flutter devices also shows the emulator ok:

    $ flutter devices
    2 connected devices:
    
    sdk gphone x86 64 arm64 (mobile) • emulator-5554 • android-x64    • Android 11 (API 30) (emulator)
    Chrome (web)                     • chrome        • web-javascript • Chromium 90.0.4430.212 built on Debian 10.9, running on Debian 10.11
    

    I tested the code of the demo project (https://github.com/tim-smart/flutter-emulators-screenshots-demo) as well, again with no luck.

    Maybe related to #3

    Any idea?

    opened by Enrico204 8
  • timeout after 3 minutes when running emu.shutdownAll

    timeout after 3 minutes when running emu.shutdownAll

    I'm testing out the dart_emulators package using flutter-emulators-screenshots-demo. The unmodified demo fails after 3 minutes with the following log:

    $ dart tools/screenshots.dart 
    Unhandled exception:
    Error waiting for device: TimeoutException after 0:03:00.000000: Future not completed
    #0      toFuture.<anonymous closure> (package:fpdt/task_either.dart:23:14)
    #1      Left._fold (package:fpdt/either.dart:408:13)
    #2      fold.<anonymous closure> (package:fpdt/either.dart:35:24)
    <asynchronous suspension>
    #3      Stream.asyncMap.<anonymous closure>.add (dart:async/stream.dart)
    <asynchronous suspension>
    

    Flutter doctor shows no issues:

    $ flutter doctor
    Doctor summary (to see all details, run flutter doctor -v):
    [✓] Flutter (Channel stable, 2.8.1, on macOS 12.1 21C52 darwin-x64, locale
        en-US)
    [✓] Android toolchain - develop for Android devices (Android SDK version
        31.0.0-rc2)
    [✓] Xcode - develop for iOS and macOS (Xcode 13.2.1)
    [✓] Chrome - develop for the web
    [✓] Android Studio (version 2020.3)
    [✓] IntelliJ IDEA Ultimate Edition (version 2021.2)
    [✓] IntelliJ IDEA Community Edition (version 2017.2.2)
    [✓] Connected device (2 available)
    
    • No issues found!
    

    I am able to start Android and iOS simulators manually with no problems.

    opened by speaking-in-code 4
  • Emulators.build() crashed integration test

    Emulators.build() crashed integration test

    I have tried to modify the demo app to use the integration_test framework instead of the deprecated flutter_driver. The problem is that calling Emulators.build() directly crashed the test, so there is no way of making screenshots. Any ideas how to solve it?

    package:test_core/src/runner/plugin/platform_helpers.dart 115:19 deserializeSuite. dart:async/zone.dart 1383:47 _rootRun dart:async/zone.dart 1293:19 _CustomZone.run dart:async/zone.dart 1201:7 _CustomZone.runGuarded dart:async/stream_impl.dart 392:13 _BufferingStreamSubscription._sendDone.sendDone dart:async/stream_impl.dart 402:7 _BufferingStreamSubscription._sendDone dart:async/stream_impl.dart 291:7 _BufferingStreamSubscription._close dart:async/stream_controller.dart 782:19 _SyncStreamControllerDispatch._sendDone dart:async/stream_controller.dart 637:7 _StreamController._closeUnchecked dart:async/stream_controller.dart 630:5 _StreamController.close package:stream_channel/src/guarantee_channel.dart 55:31 new GuaranteeChannel.. dart:async/zone.dart 1383:47 _rootRun dart:async/zone.dart 1293:19 _CustomZone.run dart:async/zone.dart 1201:7 _CustomZone.runGuarded dart:async/stream_impl.dart 392:13 _BufferingStreamSubscription._sendDone.sendDone dart:async/stream_impl.dart 402:7 _BufferingStreamSubscription._sendDone dart:async/stream_impl.dart 291:7 _BufferingStreamSubscription._close dart:async/stream_controller.dart 782:19 _SyncStreamControllerDispatch._sendDone dart:async/stream_controller.dart 637:7 _StreamController._closeUnchecked dart:async/stream_controller.dart 630:5 _StreamController.close dart:async/stream_controller.dart 874:29 _StreamSinkWrapper.close package:stream_channel/src/guarantee_channel.dart 188:38 _GuaranteeSink.close package:stream_channel/src/multi_channel.dart 241:29 _MultiChannel._closeInnerChannel dart:async/zone.dart 1383:47 _rootRun dart:async/zone.dart 1293:19 _CustomZone.run dart:async/zone.dart 1201:7 _CustomZone.runGuarded dart:async/stream_impl.dart 392:13 _BufferingStreamSubscription._sendDone.sendDone dart:async/stream_impl.dart 402:7 _BufferingStreamSubscription._sendDone dart:async/stream_impl.dart 291:7 _BufferingStreamSubscription._close dart:async/stream_controller.dart 782:19 _SyncStreamControllerDispatch._sendDone dart:async/stream_controller.dart 637:7 _StreamController._closeUnchecked dart:async/stream_controller.dart 630:5 _StreamController.close package:stream_channel/src/guarantee_channel.dart 55:31 new GuaranteeChannel.. dart:async/zone.dart 1383:47 _rootRun dart:async/zone.dart 1293:19 _CustomZone.run dart:async/zone.dart 1201:7 _CustomZone.runGuarded dart:async/stream_impl.dart 392:13 _BufferingStreamSubscription._sendDone.sendDone dart:async/stream_impl.dart 402:7 _BufferingStreamSubscription._sendDone dart:async/stream_impl.dart 534:14 _DelayedDone.perform dart:async/stream_impl.dart 620:11 _PendingEvents.handleNext dart:async/stream_impl.dart 591:7 _PendingEvents.schedule. dart:async/zone.dart 1383:47 _rootRun dart:async/zone.dart 1293:19 _CustomZone.run dart:async/zone.dart 1201:7 _CustomZone.runGuarded dart:async/zone.dart 1241:23 _CustomZone.bindCallbackGuarded. dart:async/zone.dart 1391:13 _rootRun dart:async/zone.dart 1293:19 _CustomZone.run dart:async/zone.dart 1201:7 _CustomZone.runGuarded dart:async/zone.dart 1241:23 _CustomZone.bindCallbackGuarded. dart:async/schedule_microtask.dart 40:21 _microtaskLoop dart:async/schedule_microtask.dart 49:5 _startMicrotaskLoop dart:isolate-patch/isolate_patch.dart 122:13 _runPendingImmediateCallback dart:isolate-patch/isolate_patch.dart 193:5 _RawReceivePortImpl._handleMessage

    Failed to load ".../flutter-emulators-screenshots-demo-main/integration_test/main_test.dart": Connection closed before test suite loaded.

    opened by Klabauterman 3
  • device_state.g.dart:13:17: Error: Method not found

    device_state.g.dart:13:17: Error: Method not found

    ../../../.pub-cache/hosted/pub.dartlang.org/emulators-0.4.9/lib/src/device/device_state.g.dart:13:17: Error: Method not found: '$enumDecode'. platform: $enumDecode(_$DevicePlatformEnumMap, json['platform']),

    Is some kind of code generation required? I tryed to run the tools.dart and got the error above :( can you help.

    opened by a43mrk 2
  • option to execute dart_emulators w/o unistalling present app!

    option to execute dart_emulators w/o unistalling present app!

    I couldnt find any option to start dart_emulators without he uninstalling the app; I'm in this need because some popup like notification authorization or login that pass through 2fa process really cut the integration test process and left some part for human interaction :( I really need that the screenshots to be done at the app with already logged state(resume the last state). is there some option to switch on/off the uninstall process before finishing on integration test?

    opened by a43mrk 1
  • emu.toolchain.avdmanager will fail, because the path is absent in $PATH

    emu.toolchain.avdmanager will fail, because the path is absent in $PATH

    Installing Android Studio and all required packages will still not be enough to make emu.toolchain.avdmanager work.

    Output:

    Unhandled exception:
    ProcessException: No such file or directory
      Command: avdmanager create avd -n Nexus_5X -k system-images;android-31;google_apis_playstore;x86_64 -d Nexus 5X -f
    

    It seems on MacOS after installing Android Studio $ANDROID_SDK_ROOT is not set (it's empty), but $ANDROID_HOME is set:

    $ echo $ANDROID_SDK_ROOT
    
    $ echo $ANDROID_HOME
    ~/Library/Android/sdk
    $ $ANDROID_HOME/cmdline-tools/latest/bin/avdmanager                
    
    Usage:
          avdmanager [global options] [action] [action options]
          Global options:
    ...
    

    It would be nice if the wrapper could fallback to $ANDROID_HOME to make it work right out of the box.

    opened by martin-braun 1
  • Heavy OOP Rewrite

    Heavy OOP Rewrite

    This package is really cool but it wasn't working right for me so I dove into the source code and went down a rabbit hole. I ended up refactoring the package pretty heavily.

    I'm not sure whether or not you'll like my changes, a lot of them are about differences of style. I got rid of a lot of the functional stuff and replaced it with OOP stuff. I like functional as much as the next guy, but it's not very readable in Dart. I think some of these are conventions in Javascript? Either way they're discouraged in Dart.

    Here are some of the changes I made:

    1. When things fail, fail loudly either by printing an error and skipping the current device, or by crashing the entire program.
    2. Replace all functions that return functions with client classes. These kinds of functions are discouraged in Dart and severely hurt readability.
    3. Remove some of the options (this ties back into 1, the options were swallowing fatal errors).
    4. Replace most uses of someFuture.then(...) with await someFuture;. Usage of then outside of ultra-simple one liners is discouraged in dart.
    5. Replaced import 'foo.dart' as Foo; with import 'foo.dart';. Generally, import...as in Dart is discouraged outside of some particular packages (like math.dart). Typically, packages expose logic via a class with methods so you don't pollute the namespace by importing them directly.
    6. To launch the emulated app, all that devs have to do is call a single function now with some basic input: runEmulatedApp.
    opened by caseycrogers 1
  • shutdownAll doesn't work (emulators are left running)

    shutdownAll doesn't work (emulators are left running)

    While doing some tests with this Flutter package, I discovered that await emu.shutdownAll(config); is not working (at least, for me), meaning that any emulator running is left in running state (no matter who started those emulators).

    My system is Debian 10, emulators works as intended using Android Studio, and they show up when issuing flutter devices:

    $ flutter devices
    2 connected devices:
    
    sdk gphone x86 64 arm64 (mobile) • emulator-5554 • android-x64    • Android 11 (API 30) (emulator)
    Chrome (web)                     • chrome        • web-javascript • Chromium 90.0.4430.212 built on Debian 10.9, running on Debian 10.11
    
    opened by Enrico204 1
  • Add rotate orientation support

    Add rotate orientation support

    If possible, can you add support for setting the emulator/device orientation?

    The old screenshots package did this via scripts that on Mac, which just ran the following osascript scpt. Note that it would require running the command [open -a Simulator.app] to ensure the simulator on Mac is visible to the finder before hand.

    Not sure how to tackle Android, but suspect there is something you can call/do to activate the same orientation.

    on run argv
      my do_submenu("Simulator", "Device", "Orientation", item 1 of argv)
      return item 1 of argv
    end run
    
    on do_submenu(app_name, menu_name, menu_item, submenu_item)
        try
            -- bring the target application to the front
            tell application app_name
                activate
            end tell
            tell application "System Events"
                tell process app_name
                    tell menu bar 1
                        tell menu bar item menu_name
                            tell menu menu_name
                                tell menu item menu_item
                                    tell menu menu_item
                                        click menu item submenu_item
                                    end tell
                                end tell
                            end tell
                        end tell
                    end tell
                end tell
            end tell
            return true
        on error error_message
            return false
        end try
    end do_submenu
    
    opened by gslender 0
  • Better Android SDK instructions

    Better Android SDK instructions

    I really struggled for a while to figure out how to install all the needed Android SDK tools for command-line. Would help if you provided some guidance around what is needed, and how to ensure that the right system $path is setup to allow all the commands you need for the Android emulators... ie ./emulator ./avdmanager etc

    opened by gslender 1
  • Support fvm

    Support fvm

    Currently I'm using fvm to run flutter; is ther a plan to support fvm flutter like command? if flutter isn't the command file not found is being throwing :(

    opened by a43mrk 6
Owner
Tim
Tim
A flutter utility to easily create flavors in your flutter application

Flutter Flavorizr A flutter utility to easily create flavors in your flutter application Getting Started Let's start by setting up our environment in

Angelo Cassano 268 Jan 1, 2023
A Dart testing utility for asserting that some code emits a compilation error.

A Dart testing utility for asserting that some code emits a compilation error.

Remi Rousselet 32 Dec 11, 2022
A simple Flutter / Dart Utility class for converting complex objects to uri and query string

A simple Flutter / Dart Utility class for converting complex or nested objects to uri and query strings you can follow the the article on how this cla

Opata Joshua 5 Sep 7, 2022
CLI utility to manage MC Server installations

CLI utility to manage MC server installations. Features Install required JDKs Download server files Generate start scripts (with optimized JVM flags)

Michael Rittmeister 14 Nov 18, 2022
Utility to process H264 profile-level-id values

h264_profile_level_id Dart utility to process H264 profile-level-id values based on Google's libwebrtc C++ code. API import 'package:h264_profile_leve

Ibragim Abbasov 2 Apr 22, 2022
Uproot(uprt) is a multi-platform (Windows, MacOs, and Linux) command line utility written in Dart to convert a router's DHCP IP Reservations between routers

UPROOT Uproot(uprt) is a multi-platform (Windows, MacOs, and Linux) command line utility written in Dart to convert a router's DHCP IP Reservations be

GeekVisit 73 Jan 1, 2023
🔍 👀 CLI utility to check last-visit of your CodeForces friends & much more, 🚀 powered by CodeForces API

JoJo ?? ?? CLI utility to check last-visit of your CodeForces friends & much more, ?? powered by CodeForces API Features Online Friends All Friends Pr

Tirth 5 Jul 20, 2020
Contains utility functions and classes in the style of dart:collection to make working with collections easier

The collection package for Dart contains a number of separate libraries with utility functions and classes that makes working with collections easier.

Dart 273 Dec 27, 2022
Quiver is a set of utility libraries for Dart that makes using many Dart libraries easier and more convenient, or adds additional functionality.

Quiver is a set of utility libraries for Dart that makes using many Dart libraries easier and more convenient, or adds additional functionality.

Google 905 Jan 2, 2023
Fluro is a Flutter routing library that adds flexible routing options like wildcards, named parameters and clear route definitions.

Fluro is a Flutter routing library that adds flexible routing options like wildcards, named parameters and clear route definitions.

Luke Pighetti 3.5k Jan 4, 2023
A Dart library to parse Portable Executable (PE) format

pefile A Dart library to parse Portable Executable (PE) format Usage A simple usage example: var pe = pefile.parse('C:\\Windows\\System32\\notepad.exe

null 4 Sep 12, 2022
This library contains methods that make it easy to consume Mpesa Api.

This library contains methods that make it easy to consume Mpesa Api. It's multi-platform, and supports CLI, server, mobile, desktop, and the browser.

Eddie Genius 3 Dec 15, 2021
Scribble is a lightweight library for freehand drawing in Flutter supporting pressure, variable line width and more!

Scribble Scribble is a lightweight library for freehand drawing in Flutter supporting pressure, variable line width and more! A

Tim Created It. 73 Dec 16, 2022
An alternative random library for Dart.

Randt Randt library for Dart... Description Use Randt to get a random integer from a list, generate random integer in a specific range and generate ra

Bangladesh Coding Soldierz 3 Nov 21, 2021
A library for YAML manipulation with comment and whitespace preservation.

Yaml Editor A library for YAML manipulation while preserving comments. Usage A simple usage example: import 'package:yaml_edit/yaml_edit.dart'; void

Dart 17 Dec 26, 2022
The Dart Time Machine is a date and time library for Flutter, Web, and Server with support for timezones, calendars, cultures, formatting and parsing.

The Dart Time Machine is a date and time library for Flutter, Web, and Server with support for timezones, calendars, cultures, formatting and parsing.

null 2 Oct 8, 2021
A comprehensive, cross-platform path manipulation library for Dart.

A comprehensive, cross-platform path manipulation library for Dart. The path package provides common operations for manipulating paths: joining, split

Dart 159 Dec 29, 2022
Boilerplate-free form validation library

Valform Boilerplate-free form validation library. Preface Why? Why not Formz? Why Valform? Getting started Simple Usage Inspiration Why? There is no c

Alexander Farkas 3 Nov 14, 2021
Boilerplate-free form validation library

Trigger Boilerplate-free form validation library. Preface Why? Why not Formz? Why Trigger? Getting started Simple Usage Inspiration Why? There is no c

Alexander Farkas 3 Nov 14, 2021