diff --git a/packages/flutter_tools/lib/src/ohos/ohos_device.dart b/packages/flutter_tools/lib/src/ohos/ohos_device.dart index 511d32e949a0195196cffa2a2257b6993e2116e9..f57d25ff24fb234c9bb279dc3eb7cfffb4d3eae5 100644 --- a/packages/flutter_tools/lib/src/ohos/ohos_device.dart +++ b/packages/flutter_tools/lib/src/ohos/ohos_device.dart @@ -123,15 +123,14 @@ class OhosDevice extends Device { await runHdcCheckedAsync(['shell', 'rm', remotePath]); } - @override - Future installApp(covariant ApplicationPackage app, + Future _installApp(covariant ApplicationPackage app, {String? userIdentifier}) async { if (app is! OhosHap) { throwToolExit('this project or file is not contain(a) Hap file'); } final OhosHap hap = app; final List installAppCommand = - hdcCommandForDevice(['install', hap.applicationPackage.path]); + hdcCommandForDevice(['install', '-r', hap.applicationPackage.path]); final File file = globals.fs.file(hap.applicationPackage.path); if (!file.existsSync()) { throwToolExit('the hap file not exists!'); @@ -321,13 +320,6 @@ class OhosDevice extends Device { _logger.printTrace("Stopping app '${builtPackage.name}' on $name."); await stopApp(builtPackage, userIdentifier: userIdentifier); - if (await isAppInstalled(builtPackage, userIdentifier: userIdentifier)) { - globals.printStatus('Uninstalling old version...'); - if (!await uninstallApp(builtPackage, userIdentifier: userIdentifier)) { - globals.printWarning('Warning: uninstalling old version failed'); - } - } - if (!await installApp(builtPackage, userIdentifier: userIdentifier)) { return LaunchResult.failed(); } @@ -400,6 +392,30 @@ class OhosDevice extends Device { } } + @override + Future installApp(covariant ApplicationPackage app, + {String? userIdentifier}) async { + final bool wasInstalled = await isAppInstalled(app, userIdentifier: userIdentifier); + _logger.printTrace('Installing Hap.'); + if (await _installApp(app, userIdentifier: userIdentifier)) { + return true; + } + _logger.printTrace('Warning: Failed to install Hap.'); + if (!wasInstalled) { + return false; + } + _logger.printStatus('Uninstalling old version...'); + if (!await uninstallApp(app, userIdentifier: userIdentifier)) { + _logger.printError('Error: Uninstalling old version failed.'); + return false; + } + if (!await _installApp(app, userIdentifier: userIdentifier)) { + _logger.printError('Error: Failed to install Hap again.'); + return false; + } + return true; + } + @override Future stopApp(covariant ApplicationPackage? app, {String? userIdentifier}) async {