Fix install for iOS simulator, and add ability to uninstall (#4223)
diff --git a/packages/flutter_tools/lib/src/ios/simulators.dart b/packages/flutter_tools/lib/src/ios/simulators.dart
index f566a14..58ae15b 100644
--- a/packages/flutter_tools/lib/src/ios/simulators.dart
+++ b/packages/flutter_tools/lib/src/ios/simulators.dart
@@ -274,10 +274,24 @@
bool _isAnyConnected() => getConnectedDevices().isNotEmpty;
+ bool isInstalled(String appId) {
+ return exitsHappy(<String>[
+ _xcrunPath,
+ 'simctl',
+ 'get_app_container',
+ 'booted',
+ appId,
+ ]);
+ }
+
void install(String deviceId, String appPath) {
runCheckedSync(<String>[_xcrunPath, 'simctl', 'install', deviceId, appPath]);
}
+ void uninstall(String deviceId, String appId) {
+ runCheckedSync(<String>[_xcrunPath, 'simctl', 'uninstall', deviceId, appId]);
+ }
+
void launch(String deviceId, String appIdentifier, [List<String> launchArgs]) {
List<String> args = <String>[_xcrunPath, 'simctl', 'launch', deviceId, appIdentifier];
if (launchArgs != null)
@@ -362,6 +376,11 @@
}
@override
+ bool isAppInstalled(ApplicationPackage app) {
+ return SimControl.instance.isInstalled(app.id);
+ }
+
+ @override
bool installApp(ApplicationPackage app) {
try {
IOSApp iosApp = app;
@@ -373,6 +392,16 @@
}
@override
+ bool uninstallApp(ApplicationPackage app) {
+ try {
+ SimControl.instance.uninstall(id, app.id);
+ return true;
+ } catch (e) {
+ return false;
+ }
+ }
+
+ @override
bool isSupported() {
if (!Platform.isMacOS) {
_supportMessage = "Not supported on a non Mac host";
@@ -424,17 +453,6 @@
}
@override
- bool isAppInstalled(ApplicationPackage app) {
- try {
- // TODO(tvolkert): This logic is wrong; simulatorHomeDirectory always exists
- String simulatorHomeDirectory = _getSimulatorAppHomeDirectory(app);
- return FileSystemEntity.isDirectorySync(simulatorHomeDirectory);
- } catch (e) {
- return false;
- }
- }
-
- @override
Future<LaunchResult> startApp(
ApplicationPackage app,
BuildMode mode, {
@@ -505,13 +523,7 @@
}
bool _applicationIsInstalledAndRunning(ApplicationPackage app) {
- bool isInstalled = exitsHappy(<String>[
- 'xcrun',
- 'simctl',
- 'get_app_container',
- 'booted',
- app.id,
- ]);
+ bool isInstalled = isAppInstalled(app);
bool isRunning = exitsHappy(<String>[
'/usr/bin/killall',