The application of the remote Flutter compilation to the iOS project also encountered a compilation error. The application of the remote Flutter compilation to the iOS project also encountered an error. Error Multiple commands produce ‘*. Framework ‘

Multiple commands produce '/Users/user/Library/Developer/Xcode/DerivedData/MyProj-flazyqyatfvrvsgcoofvwrizuvot/Build/Products/Debug-iphoneos/MyPro j.app/Frameworks/FMDB.framework':
1) That command depends on command in Target 'MyProj' (project 'MyProj'): script phase "[CP] Embed Pods Frameworks"2) That command depends on command in Target 'MyProj' (project 'MyProj'): script phase “[CP] Embed Pods Frameworks”


Multiple commands produce '/Users/user/Library/Developer/Xcode/DerivedData/MyProj-flazyqyatfvrvsgcoofvwrizuvot/Build/Products/Debug-iphoneos/MyPro j.app/Frameworks/MMKV.framework':
1) That command depends on command in Target 'MyProj' (project 'MyProj'): script phase "[CP] Embed Pods Frameworks"2) That command depends on command in Target 'MyProj' (project 'MyProj'): script phase “[CP] Embed Pods Frameworks”


Multiple commands produce '/Users/user/Library/Developer/Xcode/DerivedData/MyProj-flazyqyatfvrvsgcoofvwrizuvot/Build/Products/Debug-iphoneos/MyPro j.app/Frameworks/MMKVCore.framework':
1) That command depends on command in Target 'MyProj' (project 'MyProj'): script phase "[CP] Embed Pods Frameworks"2) That command depends on command in Target 'MyProj' (project 'MyProj'): script phase “[CP] Embed Pods Frameworks”


Multiple commands produce '/Users/user/Library/Developer/Xcode/DerivedData/MyProj-flazyqyatfvrvsgcoofvwrizuvot/Build/Products/Debug-iphoneos/MyPro j.app/Frameworks/Sentry.framework':
1) That command depends on command in Target 'MyProj' (project 'MyProj'): script phase "[CP] Embed Pods Frameworks"2) That command depends on command in Target 'MyProj' (project 'MyProj'): script phase "[CP] Embed Pods Frameworks"Copy the code

This compilation error occurs after Xcode10 uses a new build system that checks duplicate build/duplicate output files for reliability and build performance. Duplicate build products may throw related errors when detected. Multiple Commands produce ‘*. Framework ‘is one of them.

Repeat Build artifacts are one of the new features in the new Build System, and can be fully described in the official documentation # Build System Release Notes for Xcode 10.

First check the build system Settings. Open the project with a new version of Xcode and click File -> WorkSpace Settings in the upper left corner of the screen to see the build system configuration items, as shown below.

Xcode10 will default to New Build System, the New Build System, while Legacy Build Sysytem has been marked Deprecated but is still available.

The iOS plugin layer of Flutter relies on MMKV, FMDB and Sentry. The iOS plugin layer of Flutter also relies on these libraries. During the compilation phase of the Flutter Module, the third-party libraries that the plugin layer relies on are compiled into the relevant.xcFramework, and the.XCFramework is embedded into the iOS project via native PodSpec. Third-party libraries that the iOS side relies on through CocoaPods are also compiled at compile time into the.XCFramework embedded in the project. It is stored in a different path before compilation, but it is processed and exported to the same path during compilation, which causes the problem of repeated builds.

# Build System Release Notes for Xcode 10 But the duplicate output file error is mentioned, which requires that all production directories of a Target be processed at the same compile stage, and not duplicate production/output files at multiple compile stages.

Targets which have multiple asset catalogs that aren't in the same build phase may produce an error regarding a "Duplicate the output file".39810274)

Workaround: Ensure that all asset catalogs are processed by the same build phase in the target.
Copy the code

It is an error for any individual file in the build to be produced by more than one build command. An error can also occur if you produce the same file in multiple build commands. The previous error message is a repeat build of a. Framework at Target during the [CP] Embed Pods Frameworks script phase. [CP] Embed Pods Frameworks in Xcode to see the related scripts and I/O list files, including the following files:

  • Pods-MyProj-frameworks.sh
  • Pods-MyProj-frameworks-Debug-input-files.xcfilelist
  • Pods-MyProj-frameworks-Debug-output-files.xcfilelist
  • Pods-MyProj-frameworks-Release-input-files.xcfilelist
  • Pods-MyProj-frameworks-Release-output-files.xcfilelist

The pods-myproj-frameworks. Sh script calls the install_framework function one by one to rebuild the signed framework for each of the third-party libraries that Pods relies on. The import path to the library files when install_framework is called. You can see that duplicate third-party libraries appear, but in different paths. ${BUILT_PRODUCTS_DIR} contains the third-party libraries that CococPods normally rely on, and ${PODS_XCFRAMEWORKS_BUILD_DIR} contains the dependencies on the Flutter build product (XCFramework).

. install_framework"${BUILT_PRODUCTS_DIR}/FMDB/FMDB.framework"
  install_framework "${BUILT_PRODUCTS_DIR}/MMKV/MMKV.framework"
  install_framework "${BUILT_PRODUCTS_DIR}/MMKVCore/MMKVCore.framework". install_framework"${PODS_XCFRAMEWORKS_BUILD_DIR}/Flutter/Flutter.framework"
  install_framework "${PODS_XCFRAMEWORKS_BUILD_DIR}/FMDB/FMDB.framework"
  install_framework "${PODS_XCFRAMEWORKS_BUILD_DIR}/MMKV/MMKV.framework"
  install_framework "${PODS_XCFRAMEWORKS_BUILD_DIR}/MMKVCore/MMKVCore.framework"
  install_framework "${PODS_XCFRAMEWORKS_BUILD_DIR}/mmkv_flutter/mmkv_flutter.framework"
Copy the code

Inside the Install_framework function, the output path is computed and the framework built is exported to that path. The build artifacts are placed in the ${TARGET_BUILD_DIR}/${FRAMEWORKS_FOLDER_PATH} directory, depending on the framework name. If the framework name in the import path is duplicate, the framework will be built repeatedly.

local destination="${TARGET_BUILD_DIR}/${FRAMEWORKS_FOLDER_PATH}"
binary="${destination}/${basename}.framework/${basename}"
Copy the code

To open pods-myproj-frameworks – debug-input-files. xcfilelist and PODs-myProj-frameworks – debug-output-files. xcfilelist, open pods-myProj-frameworks – debug-input-files. xcfilelist These files list the input and output paths for all frameworks, and are the same as the input and output paths used in Pods-MyProj-frameworks. Sh. Open pods-MyProj-frameworks – debug-input-files. xcfilelist to see fMDB. framework/mmkv.framework /… These libraries have different input paths, and in pods-Myproj -frameworks- debug-output-files. xcfilelist these libraries have the following repeated output paths, which are the same as the export paths calculated internally by install_framework functions. Multiple Commands produce ‘*. Framework ‘compilation error if Multiple Commands produce ‘*. Framework’ compilation error if Multiple commands produce ‘*.

. ${TARGET_BUILD_DIR}/${FRAMEWORKS_FOLDER_PATH}/FMDB.framework ... ${TARGET_BUILD_DIR}/${FRAMEWORKS_FOLDER_PATH}/MMKV.framework ... ${TARGET_BUILD_DIR}/${FRAMEWORKS_FOLDER_PATH}/FMDB.framework ${TARGET_BUILD_DIR}/${FRAMEWORKS_FOLDER_PATH}/MMKV.frameworkCopy the code

Therefore, the problem lies in the compilation phase of Script phase “[CP] Embed Pods Frameworks”. The new build system detects repetitive build behavior, and I have found two solutions so far. I suggest to choose solution 2.

  1. Select the old build system, the specific operation path:Xcode -> File -> WorkSpace Settings -> Build System -> Legacy Build SysytePossible, but not recommended, because the build system is already flaggedDeprecated.
  2. Choose a new build system, but solve the problem of duplicate dependencies at the source, so I start fromFlutterModuleSDKRemoved those that might duplicate dependenciesxcframeworkWhen compiling an iOS project, only use the third-party library that the iOS side relies on and reserve one input source. We can seeBuild script flutter_build_script.sh, delete what needs to be deletedxcframeworkAdd to the blacklist. The blacklist will be deleted after a Flutter is compiledxcframeworkSo that you don’t have to build the framework repeatedly when compiling iOS projects.