install method

Future<ProcessResult> install(
  1. String path, {
  2. String? device,
})

Installs the APK file (which has to be on path) to the attached device.

If there is more than 1 device attached, decide which one to use by passing device.

Waits for the package service to start up before proceeding with installation.

Throws if there are no devices attached.

Implementation

Future<io.ProcessResult> install(
  String path, {
  String? device,
}) async {
  await _adbInternals.ensureServerRunning();
  await _adbInternals.ensurePackageServiceRunning(device: device);
  await _adbInternals.ensureActivityServiceRunning(device: device);

  final result = await io.Process.run(
    'adb',
    [
      if (device != null) ...[
        '-s',
        device,
      ],
      'install',
      path,
    ],
    runInShell: true,
  );

  if (result.stdErr.isNotEmpty) {
    _handleAdbExceptions(result.stdErr);

    throw Exception(result.stdErr);
  }

  return result;
}