Repository: flutter
Issue: `flutter build ios-framework` fails when plugin declares WatchOS target
Labels: platform-ios,tool,a: existing-apps,P2,team-ios,triaged-ios

<!-- Thank you for using Flutter!

     If you are looking for support, please check out our documentation
     or consider asking a question on Stack Overflow:
      * https://flutter.dev/
      * https://api.flutter.dev/
      * https://stackoverflow.com/questions/tagged/flutter?sort=frequent

     If you have found a bug or if our documentation doesn't have an answer
     to what you're looking for, then fill out the template below. Please read
     our guide to filing a bug first: https://flutter.dev/docs/resources/bug-reports
-->

## Background

Our app includes a Watch App for iOS. To keep all watch related code contained in one place, we have created a plugin that contains both an iOS and a watchOS target in its podspec:

```
Pod::Spec.new do |s|
  s.name             = 'watch_flutter_plugin'
  s.version          = '1.0.0'
  s.summary          = 'Flutter plugin for watchOS app.'
  s.ios.source_files = 'Classes/src/ios/**/*', 'Classes/src/shared/**/*'
  s.ios.dependency 'Flutter'
  s.ios.deployment_target = '14.0'
  s.watchos.deployment_target = '8.0'
  s.watchos.source_files = 'Classes/src/watchos/**/*', 'Classes/src/shared/**/*'
  s.watchos.resources = 'Assets/**/*'
end
```

Note: This setup works fine when building the app with `flutter build ios`, the issue only occurs on `flutter build iOS-framework`.

## Steps to Reproduce

<!-- Please tell us exactly how to reproduce the problem you are running into. -->

1. Add a plugin to your app that declares both an iOS and a watchOS target in its podspec file.
2. Run `flutter build ios-framework` command

## Logs

<details>
<summary>Logs</summary>

<!--
      Include the full logs of the commands you are running between the lines
      with the backticks below. If you are running any "flutter" commands,
      please include the output of running them with "--verbose"; for example,
      the output of running "flutter --verbose create foo".
-->
`flutter build ios-framework  --release --target lib/main/main.dart --verbose`

(Logs redacted due to confidentiality, full logs are available on request)

```
                      /<redacted>/ios/Classes/src/watch
                      os/companionAppBridge/CompanionAppBridge.swift:10:8: error: no such module 'WatchKit'
                      import WatchKit
                             ^
```

<!-- If possible, paste the output of running `flutter doctor -v` here. -->

```
[✓] Flutter (Channel stable, 2.5.4-0.0.pre.1, on macOS 12.4 21F79 darwin-x64, locale de-DE)
    • Flutter version 2.5.4-0.0.pre.1 at /Users/.../flutter
    • Upstream repository https://github.com/flutter/flutter.git
    • Framework revision 7538428275 (vor 4 Wochen), 2022-05-25 09:03:12 -0700
    • Engine revision d3ea636dc5
    • Dart version 2.14.4

[✓] Android toolchain - develop for Android devices (Android SDK version 31.0.0)
    • Android SDK at /Users/.../Library/Android/sdk
    • Platform android-31, build-tools 31.0.0
    • Java binary at: /Applications/Android Studio.app/Contents/jre/Contents/Home/bin/java
    • Java version OpenJDK Runtime Environment (build 11.0.12+0-b1504.28-7817840)
    • All Android licenses accepted.

[✓] Xcode - develop for iOS and macOS
    • Xcode at /Applications/Xcode.app/Contents/Developer
    • Xcode 13.2.1, Build version 13C100
    • CocoaPods version 1.11.2

[✓] Chrome - develop for the web
    • Chrome at /Applications/Google Chrome.app/Contents/MacOS/Google Chrome

[✓] Android Studio (version 2021.2)
    • Android Studio at /Applications/Android Studio.app/Contents
    • Flutter plugin can be installed from:
      🔨 https://plugins.jetbrains.com/plugin/9212-flutter
    • Dart plugin can be installed from:
      🔨 https://plugins.jetbrains.com/plugin/6351-dart
    • Java version OpenJDK Runtime Environment (build 11.0.12+0-b1504.28-7817840)

[✓] VS Code (version 1.63.2)
    • VS Code at /Applications/Visual Studio Code.app/Contents
    • Flutter extension version 3.36.0

[✓] Connected device (1 available)
    • Chrome (web) • chrome • web-javascript • Google Chrome 102.0.5005.115
```

</details>

## Preliminary analysis

The cause for the error seems to be that the `build ios-framework` command issues a [`xcodebuild` command ](https://github.com/flutter/flutter/blob/a30012b27505622633429b4fa001c8631da5e048/packages/flutter_tools/lib/src/commands/build_ios_framework.dart#L485) that builds all targets with SDK `iphoneos` (and `iphonesimulator` in the next command) regardless of the actual platform of the target. This obviously fails for the watchos target as this includes frameworks that are not available in iphoneos SDK.