Repository: flutter
Issue: [Add2App] option B from iOS guide can't be used if app and module have a shared pod dependency
Labels: platform-ios,d: api docs,a: existing-apps,has reproducible steps,P3,found in release: 3.10,found in release: 3.12,team-ios,triaged-ios

Option B from add to app iOS guide can't be used if app and module have a shared pod dependency.  

I mentioned this issue in my feature request https://github.com/flutter/flutter/issues/114692 and it has a lot of details, but initially I didn't want to create a separate issue because I thought we had a simple workaround. 

### Steps to reproduce

1. Integrate Flutter module into existing iOS app using [Option B](https://docs.flutter.dev/add-to-app/ios/project-setup#option-b---embed-frameworks-in-xcode) (or Option C) from the add2app iOS guide.  
(We can use [prebuilt_module](https://github.com/flutter/samples/tree/e461787dc190a3925fa733b7ec8b0eea8f76e77d/add_to_app/prebuilt_module) from the Flutter samples as an example)
2. Make sure iOS app has a Cocoapods support.  
(`prebuilt_module`: run `pod init` from the `ios_using_prebuilt_module` directory)
3. Add Cocoapods dependencies to the app.  
(to the `ios_using_prebuilt_module`).
```ruby
  # Pods for IOSUsingPrebuiltModule
  pod 'Sentry', :git => 'https://github.com/getsentry/sentry-cocoa.git', :tag => '8.8.0'
  pod 'DatadogSDK' => '1.19.0'
  pod 'DatadogSDKCrashReporting' => '1.19.0'
```
4. Add Flutter dependencies (plugins) to the module, these plugins should have dependencies we add in the step 2 as a direct/transitive dependencies.  
(add to the `pubspec.yaml` from the `flutter_module` directory)
```yaml
datadog_flutter_plugin: 1.5.1
sentry_flutter: 7.8.0
```
5. Build iOS frameworks from the Flutter module.  
(run `flutter build ios-framework --output=../ios_using_prebuilt_module/Flutter` from the `flutter_module`)
6. Embed frameworks to the app following Option B from the 'add to an existing iOS app' guide.
7. Open project in XCode and start app for the simulator  
(to open XCode from the `flutter_module`:  
`open ../ios_using_prebuilt_module/IOSUsingPrebuiltModule.xcworkspace`) 

### Expected results

iOS app is built and launched successfully.

### Actual results

XCode build errors:
```console
Multiple commands produce '/Users/mazhnik/Library/Developer/Xcode/DerivedData/IOSUsingPrebuiltModule-fslipirruxqfkpgbhswqnyfjfxeb/Build/Products/Debug-iphonesimulator/IOSUsingPrebuiltModule.app/Frameworks/Datadog.framework'
```
```console
Multiple commands produce '/Users/mazhnik/Library/Developer/Xcode/DerivedData/IOSUsingPrebuiltModule-fslipirruxqfkpgbhswqnyfjfxeb/Build/Products/Debug-iphonesimulator/IOSUsingPrebuiltModule.app/Frameworks/Sentry.framework'
```
Warnings:
```console
duplicate output file '/Users/mazhnik/Library/Developer/Xcode/DerivedData/IOSUsingPrebuiltModule-fslipirruxqfkpgbhswqnyfjfxeb/Build/Products/Debug-iphonesimulator/IOSUsingPrebuiltModule.app/Frameworks/Datadog.framework' on task: PhaseScriptExecution [CP] Embed Pods Frameworks /Users/mazhnik/Library/Developer/Xcode/DerivedData/IOSUsingPrebuiltModule-fslipirruxqfkpgbhswqnyfjfxeb/Build/Intermediates.noindex/IOSUsingPrebuiltModule.build/Debug-iphonesimulator/IOSUsingPrebuiltModule.build/Script-98112F522513510246BDAF44.sh
```
```console
duplicate output file '/Users/mazhnik/Library/Developer/Xcode/DerivedData/IOSUsingPrebuiltModule-fslipirruxqfkpgbhswqnyfjfxeb/Build/Products/Debug-iphonesimulator/IOSUsingPrebuiltModule.app/Frameworks/Sentry.framework' on task: PhaseScriptExecution [CP] Embed Pods Frameworks /Users/mazhnik/Library/Developer/Xcode/DerivedData/IOSUsingPrebuiltModule-fslipirruxqfkpgbhswqnyfjfxeb/Build/Intermediates.noindex/IOSUsingPrebuiltModule.build/Debug-iphonesimulator/IOSUsingPrebuiltModule.build/Script-98112F522513510246BDAF44.sh
```

### Code sample

Created a branch from the `flutter/samples` repository where I followed `Steps to reproduce`:  
https://github.com/p-mazhnik/flutter-samples/tree/add2app-issue

Sample is `add_to_app/prebuilt_module`. 

### Logs

<details><summary>XCode Logs</summary>

```console

Showing All Messages
Prepare packages
Prepare build
Multiple commands produce '/Users/mazhnik/Library/Developer/Xcode/DerivedData/IOSUsingPrebuiltModule-fslipirruxqfkpgbhswqnyfjfxeb/Build/Products/Debug-iphonesimulator/IOSUsingPrebuiltModule.app/Frameworks/Datadog.framework'

Multiple commands produce '/Users/mazhnik/Library/Developer/Xcode/DerivedData/IOSUsingPrebuiltModule-fslipirruxqfkpgbhswqnyfjfxeb/Build/Products/Debug-iphonesimulator/IOSUsingPrebuiltModule.app/Frameworks/Sentry.framework'

Multiple commands produce '/Users/mazhnik/Library/Developer/Xcode/DerivedData/IOSUsingPrebuiltModule-fslipirruxqfkpgbhswqnyfjfxeb/Build/Products/Debug-iphonesimulator/IOSUsingPrebuiltModule.app/Frameworks/SentryPrivate.framework'

Building targets in dependency order

Computing target dependency graph and provisioning inputs

Build target IOSUsingPrebuiltModule
duplicate output file '/Users/mazhnik/Library/Developer/Xcode/DerivedData/IOSUsingPrebuiltModule-fslipirruxqfkpgbhswqnyfjfxeb/Build/Products/Debug-iphonesimulator/IOSUsingPrebuiltModule.app/Frameworks/Datadog.framework' on task: PhaseScriptExecution [CP] Embed Pods Frameworks /Users/mazhnik/Library/Developer/Xcode/DerivedData/IOSUsingPrebuiltModule-fslipirruxqfkpgbhswqnyfjfxeb/Build/Intermediates.noindex/IOSUsingPrebuiltModule.build/Debug-iphonesimulator/IOSUsingPrebuiltModule.build/Script-98112F522513510246BDAF44.sh

duplicate output file '/Users/mazhnik/Library/Developer/Xcode/DerivedData/IOSUsingPrebuiltModule-fslipirruxqfkpgbhswqnyfjfxeb/Build/Products/Debug-iphonesimulator/IOSUsingPrebuiltModule.app/Frameworks/Sentry.framework' on task: PhaseScriptExecution [CP] Embed Pods Frameworks /Users/mazhnik/Library/Developer/Xcode/DerivedData/IOSUsingPrebuiltModule-fslipirruxqfkpgbhswqnyfjfxeb/Build/Intermediates.noindex/IOSUsingPrebuiltModule.build/Debug-iphonesimulator/IOSUsingPrebuiltModule.build/Script-98112F522513510246BDAF44.sh

duplicate output file '/Users/mazhnik/Library/Developer/Xcode/DerivedData/IOSUsingPrebuiltModule-fslipirruxqfkpgbhswqnyfjfxeb/Build/Products/Debug-iphonesimulator/IOSUsingPrebuiltModule.app/Frameworks/SentryPrivate.framework' on task: PhaseScriptExecution [CP] Embed Pods Frameworks /Users/mazhnik/Library/Developer/Xcode/DerivedData/IOSUsingPrebuiltModule-fslipirruxqfkpgbhswqnyfjfxeb/Build/Intermediates.noindex/IOSUsingPrebuiltModule.build/Debug-iphonesimulator/IOSUsingPrebuiltModule.build/Script-98112F522513510246BDAF44.sh



Activity Log Complete    09.07.2023, 10:05    0.2 seconds

```

</details>


### Flutter Doctor output

<details><summary>Doctor output</summary>

```console
[✓] Flutter (Channel stable, 3.10.5, on macOS 13.3.1 22E772610a darwin-arm64,
    locale ru-RU)
    • Flutter version 3.10.5 on channel stable at /Users/mazhnik/flutter
    • Upstream repository https://github.com/flutter/flutter.git
    • Framework revision 796c8ef792 (4 weeks ago), 2023-06-13 15:51:02 -0700
    • Engine revision 45f6e00911
    • Dart version 3.0.5
    • DevTools version 2.23.1

[✓] Android toolchain - develop for Android devices (Android SDK version 33.0.1)
    • Android SDK at /Users/mazhnik/Library/Android/sdk
    • Platform android-33, build-tools 33.0.1
    • ANDROID_HOME = /Users/mazhnik/Library/Android/sdk
    • Java binary at: /Users/mazhnik/Library/Application
      Support/JetBrains/Toolbox/apps/AndroidStudio/ch-0/222.4459.24.2221.9971841
      /Android Studio.app/Contents/jbr/Contents/Home/bin/java
    • Java version OpenJDK Runtime Environment (build
      17.0.6+0-17.0.6b802.4-9586694)
    • All Android licenses accepted.

[✓] Xcode - develop for iOS and macOS (Xcode 14.3.1)
    • Xcode at /Applications/Xcode.app/Contents/Developer
    • Build 14E300c
    • CocoaPods version 1.12.1

[✓] Chrome - develop for the web
    • Chrome at /Applications/Google Chrome.app/Contents/MacOS/Google Chrome

[✓] Android Studio (version 2022.2)
    • Android Studio at /Users/mazhnik/Library/Application
      Support/JetBrains/Toolbox/apps/AndroidStudio/ch-0/222.4459.24.2221.9971841
      /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
      17.0.6+0-17.0.6b802.4-9586694)

[✓] IntelliJ IDEA Ultimate Edition (version 2023.1.3)
    • IntelliJ at /Users/mazhnik/Applications/JetBrains Toolbox/IntelliJ IDEA
      Ultimate.app
    • Flutter plugin version 74.0.4
    • Dart plugin version 231.9161.14

[✓] IntelliJ IDEA Ultimate Edition (version 2023.1.3)
    • IntelliJ at /Users/mazhnik/Library/Application
      Support/JetBrains/Toolbox/apps/IDEA-U/ch-0/231.9161.38/IntelliJ IDEA.app
    • 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

[✓] VS Code (version 1.73.0)
    • VS Code at /Applications/Visual Studio Code.app/Contents
    • Flutter extension version 3.52.0

[✓] Connected device (3 available)
    • iPhone 14 Pro (mobile) • BB40A04B-5DC2-4B69-864F-8B42B652A2B5 • ios
      • com.apple.CoreSimulator.SimRuntime.iOS-16-4 (simulator)
    • macOS (desktop)        • macos                                •
      darwin-arm64   • macOS 13.3.1 22E772610a darwin-arm64
    • Chrome (web)           • chrome                               •
      web-javascript • Google Chrome 114.0.5735.198

[✓] Network resources
    • All expected network resources are available.

• No issues found!
```

</details>

### Proposal
1. Update flutter add-to-app documentation to indicate that Options B & Option C have limitation in case flutter plugin and native iOS app have a shared dependency.
2. Introduce new flag `--[no-]-plugins` for the `build ios-framework` command that excludes plugins from build (`_producePlugins` function is not called): 
https://github.com/flutter/flutter/issues/114692
3. Introduce Option D that suggests developers to:
    - build frameworks using `flutter build ios-framework --no-plugins`
    - link & embed `App.xcframework` using option B
    - link & embed `Flutter.xcframework` using option B or C
    - link plugins to project by adding them to `Podfile` directly (e.g. by using `install_flutter_plugin_pods`, similar to Option A). Another advantage -- we don't need to determine whether plugin produce static or dynamic framework (like in option B when embed plugins frameworks manually), Cocoapods will do this for us.
      - If using `install_flutter_plugin_pods` we will run into a limitation: 
      it requires Flutter and module dependencies to be installed locally. Workaround is to copy plugins somewhere and add them to project manually or using script similar to `flutter_install_plugin_pods`. I am not sure if we should provide such scripts to the developers.
      - we may also need a slightly different version of `flutter_post_install` script