run method
Executes the step. Read upstream values from state, write this step's
outputs back into it, and return StepResult.success or
StepResult.failure. Throw only for programming errors ā expected
tool/build failures are reported via the result.
Implementation
@override
Future<StepResult> run(
BuildContext ctx,
PipelineState state,
) async {
final apk = state[apkPath.id]! as String;
final String adb;
try {
adb = adbPath ??
await _resolveToolchain(toolchain, state).findAdb();
} on ToolchainException {
return StepResult.failure(
'adb not found ā install platform-tools (oka get android-sdk)',
);
}
print('š² Installing ${p.basename(apk)}');
final install = await Process.run(
adb,
adbInstallArgs(apk, serial: deviceId),
);
if (install.exitCode != 0 ||
'${install.stdout}${install.stderr}'.contains('Failure')) {
final output = '${install.stdout}${install.stderr}'.trim();
if (output.contains('INCOMPATIBLE')) {
print(
'\nā Signing-key mismatch: the device already has this app '
'installed with a different key. Never uninstall an app with '
'user data ā sign with the same key instead '
'(android/key.properties).',
);
} else if (output.contains('not found') ||
output.contains('no devices')) {
print('\nā No device connected. Reconnect the phone and re-run.');
} else {
print('\nā Install failed:\n$output');
}
return StepResult.failure('adb install failed for ${p.basename(apk)}');
}
print('ā
Installed');
return StepResult.success();
}