ionic-team / ionic-team/capacitor

[Bug]: Dynamically resolve target name in cap run ios

Open
#8,024 1 comment 0 reactions 0 assignees View on GitHub
triage
Dominant language
TypeScript
Stars
16.7k
Forks
1.3k
Avg merge
3d 15h
Merged PRs (30d)
10

Description

### Capacitor Version

💊 Capacitor Doctor 💊

Latest Dependencies:

@capacitor/cli: 7.2.0
@capacitor/core: 7.2.0
@capacitor/android: 7.2.0
@capacitor/ios: 7.2.0

Installed Dependencies:

@capacitor/cli: 7.2.0
@capacitor/core: 7.2.0
@capacitor/android: 7.2.0
@capacitor/ios: 7.2.0

### Other API Details

```Shell
not relevant
```

### Platforms Affected

- [x] iOS
- [ ] Android
- [ ] Web

### Current Behavior

When running a Capacitor iOS application which has multiple schemes with `cap run ios --scheme Dev --configuration Dev` the deployment fails with
```
Deploying Dev.app to 00008101-001525992141001E - failed!
[error] ERR_UNKNOWN: Path
'/ios/DerivedData//Build/Products/Dev-iphoneos/Dev.app'
not found
```
as the runIOS function assumes that the .app name matches the scheme name (i.e., ${runScheme}.app). See: [ios/run.ts#L59](https://github.com/ionic-team/capacitor/blob/main/cli/src/ios/run.ts#L59)

However, by default this is not always correct, as the .app name is determined by the target name, not the scheme name. This can cause deployment to fail because the .app bundle is not found at the expected path, when the scheme and target names differ.

### Expected Behavior

The Capacitor CLI should dynamically query the actual TARGET_NAME associated with the selected scheme using xcodebuild -showBuildSettings, ensuring the correct .app name is used during deployment. This would make runIOS more robust and compatible with a broader range of Xcode project configurations.

### Project Reproduction

[IsAvaible/cap-run-dynamic-target-name-reproduction](https://github.com/IsAvaible/cap-run-dynamic-target-name-reproduction)

### Additional Information

This can be fixed by adding a helper function that invokes:

```
xcodebuild -scheme -showBuildSettings
```
...and extracts the TARGET_NAME from the output. This resolved name should then be used in place of ${runScheme} when determining the final app bundle path.

This enhancement would:

- Improve compatibility with multi-target/-scheme projects
- Prevent .app not found errors
- Align behavior with actual Xcode project structure

Let me know if you'd like a PR for this :).

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.