Skip to content

Commit b2d7603

Browse files
authored
Simulator: Always close before trying to launch (#2819)
1 parent 8486598 commit b2d7603

File tree

1 file changed

+14
-2
lines changed

1 file changed

+14
-2
lines changed

apple/internal/templates/apple_simulator.template.py

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -695,12 +695,24 @@ def run_app_in_simulator(
695695
root_dir = os.path.dirname(application_output_path)
696696
register_dsyms(root_dir)
697697
with extracted_app(application_output_path, app_name) as app_path:
698-
logger.info("Installing app %s to simulator %s", app_path, simulator_udid)
698+
app_bundle_id = bundle_id(app_path)
699+
logger.info("Will install app %s to simulator %s", app_path, simulator_udid)
700+
# First, quietly kill any existing instances of the app to match Xcode's behavior.
701+
# Otherwise we've observed that the simulator gets confused when trying to re-install the app.
702+
logger.debug(
703+
"Terminating existing instances of %s in %s", app_bundle_id, simulator_udid
704+
)
705+
subprocess.run(
706+
[simctl_path, "terminate", simulator_udid, app_bundle_id],
707+
stdout=subprocess.DEVNULL,
708+
stderr=subprocess.DEVNULL,
709+
)
710+
# We should now be able to install and run it.
711+
logger.debug("Installing...")
699712
subprocess.run(
700713
[simctl_path, "install", simulator_udid, app_path],
701714
check=True,
702715
)
703-
app_bundle_id = bundle_id(app_path)
704716
launch_args = shlex.split(
705717
os.environ.get(
706718
"BAZEL_SIMCTL_LAUNCH_FLAGS",

0 commit comments

Comments
 (0)