【求助】IOS 升级Xcode14后,构建失败:Multiple commands produce?

详细的错误内容如下,原本podfile中引入了一个本地库

pod 'LBFoundation', :path => './Specs/foundation'

然后会生成两个target, LBFoundation.commonLBFoundation.common-Service(本人IOS小白,也不知道为什么会有两个target)


Showing All Messages

Prepare build
note: Building targets in dependency order
error: Multiple commands produce '/Project/DerivedData/Product1/Build/Intermediates.noindex/ArchiveIntermediates/Product1/IntermediateBuildFilesPath/UninstalledProducts/iphoneos/LBFoundation.framework'
    note: Target 'LBFoundation.common' (project 'Pods') has create directory command with output '/Project/DerivedData/Product1/Build/Intermediates.noindex/ArchiveIntermediates/Product1/IntermediateBuildFilesPath/UninstalledProducts/iphoneos/LBFoundation.framework'
    note: Target 'LBFoundation.common-Service' (project 'Pods') has create directory command with output '/Project/DerivedData/Product1/Build/Intermediates.noindex/ArchiveIntermediates/Product1/IntermediateBuildFilesPath/UninstalledProducts/iphoneos/LBFoundation.framework'


Building targets in dependency order

Multiple commands produce '/Project/DerivedData/Product1/Build/Intermediates.noindex/ArchiveIntermediates/Product1/IntermediateBuildFilesPath/UninstalledProducts/iphoneos/LBFoundation.framework'

Computing target dependency graph and provisioning inputs

Create build description
Build description signature: 88c15e2173a8937894d3334eb649cc15
Build description path: /Project/DerivedData/Product1/Build/Intermediates.noindex/ArchiveIntermediates/Product1/IntermediateBuildFilesPath/XCBuildData/88c15e2173a8937894d3334eb649cc15.xcbuilddata

看网上的问题应该是原本该项目的编译系统用的是Legacy Build Sysytem,但是14后统一只能用New Build System。而新的编译方式会产生上述问题,不知道怎么解决。
哪位大佬能指点一下,感激不尽。

Xcode版本: 14.3
CocoaPods版本: 1.12.0

podfile内容就不贴出来了。直接回答区贴答案吧。

阅读 6.3k
2 个回答

感谢Stephanie老哥,我贴一下答案吧。

最后发现是由于podfile中多个target都有
pod 'LBFoundation', :path => './Specs/foundation'

例如我有个主工程 project1, 同时有两个target 'NotificationService''project1WidgetExtension'。主工程依赖这两个target。

cocoapods在install LBFoundation时会生成两个target, 'LBFoundation.common''LBFoundation.common-Service'.
这可能是由于依赖的两个工程里只引用了LBFoundation中的某个部分,比如LBFoundation/Service有关。
所以install的时候会生成两个不一样的target, 然后archive时两个target又都会生成LBFoundation.framework导致冲突(这个不清楚内部逻辑,感觉是这样)

解决方案是再单独pod一下LBFoundation/Service,最终podfile如下(隐藏了无关信息):

source 'https://github.com/CocoaPods/Specs.git'

platform :ios, "12.0"
inhibit_all_warnings!

def private_develop_share_pods
  # 省略
  pod 'LBFoundation', :path => './Specs/foundation'
  pod 'LBFoundation/Service', :path => './Specs/foundation'
  # 省略
end

target 'project1' do
    project 'project1.xcodeproj'
    use_frameworks!
    private_develop_share_pods
    # 省略
end

target 'NotificationService' do
    project 'project1.xcodeproj'
    use_frameworks!
    private_develop_share_pods
    # 省略
end

target 'project1WidgetExtension' do
    project 'project1.xcodeproj'
    use_frameworks!
    private_develop_share_pods
    # 省略
end

# 省略

这个模块具体看你库里用的什么模块,我看github上也有老哥是这样解决的。
然后再pod install,就可以看到pods下只剩下一个LBFoundation的target了。此时archive就不会报Multiple commands produce的错误了

link_stat "/project1Path/../../iphoneos/AFNetworking.framework" failed: No such file or directory (2)

后面archive的时候还有个错误,是Xcode14.3官方的错误。也顺带贴一下
错误信息:

PhaseScriptExecution [CP]\ Embed\ Pods\ Frameworks /project1Path/DerivedData/project1/Build/Intermediates.noindex/ArchiveIntermediates/project1/IntermediateBuildFilesPath/project1.build/Release-iphoneos/project1.build/Script-E4774E2B0A75F86160F06910.sh (in target 'project1' from project 'project1')
    cd /project1Path
    /bin/sh -c /project1Path/DerivedData/project1/Build/Intermediates.noindex/ArchiveIntermediates/project1/IntermediateBuildFilesPath/project1.build/Release-iphoneos/project1.build/Script-E4774E2B0A75F86160F06910.sh

mkdir -p /project1Path/DerivedData/project1/Build/Intermediates.noindex/ArchiveIntermediates/project1/BuildProductsPath/Release-iphoneos/project1.app/Frameworks
Symlinked...
rsync --delete -av --filter P .*.?????? --links --filter "- CVS/" --filter "- .svn/" --filter "- .git/" --filter "- .hg/" --filter "- Headers" --filter "- PrivateHeaders" --filter "- Modules" "../../../IntermediateBuildFilesPath/UninstalledProducts/iphoneos/AFNetworking.framework" "/project1Path/DerivedData/project1/Build/Intermediates.noindex/ArchiveIntermediates/project1/InstallationBuildProductsLocation/Applications/project1.app/Frameworks"
building file list ... rsync: link_stat "/project1Path/../../../IntermediateBuildFilesPath/UninstalledProducts/iphoneos/AFNetworking.framework" failed: No such file or directory (2)
done

sent 29 bytes  received 20 bytes  98.00 bytes/sec
total size is 0  speedup is 0.00
rsync error: some files could not be transferred (code 23) at /AppleInternal/Library/BuildRoots/97f6331a-ba75-11ed-a4bc-863efbbaf80d/Library/Caches/com.apple.xbs/Sources/rsync/rsync/main.c(996) [sender=2.6.9]
Command PhaseScriptExecution failed with a nonzero exit code

目前最新版本Xcode14.3存在这个问题,可以选择降级到14.2或者修改 Pods/Target Support Files/Pods-projectName/Pods-projectName-frameworks文件内的44行
source="$(readlink "${source}")"修改为source="$(readlink -f "${source}")"

因为每次install都会被覆盖重写,补充一下动态修改脚本

ef find_and_replace(dir, findstr, replacestr)
  Dir[dir].each do |name|
    text = File.read(name)
    replace = text.gsub(findstr, replacestr)
    if text != replace
      puts "Fix: " + name
      File.open(name, "w") { |file| file.puts replace }
      STDOUT.flush
    end
  end
  Dir[dir + '*/'].each(&method(:find_and_replace))
end

post_install do |installer_representation|
  # 省略
  # Xcode14问题补丁,升级后可以移除:https://github.com/CocoaPods/CocoaPods/pull/11828
  find_and_replace("./Pods/Target Support Files/Pods-projectName/Pods-projectName-frameworks.sh", 'source="$(readlink "${source}")"', 'source="$(readlink -f "${source}")"')
end

github上对应issues: https://github.com/CocoaPods/CocoaPods/issues/11808
并且该修复已经被合并,下次版本应该会发布修复: https://github.com/CocoaPods/CocoaPods/pull/11828

再次感谢Stephanie老哥

Try this:

Command + Shift + k to clean the project and rebuild the project
if also not work, you could delete the /Project/DerivedData/ directory and rebuild again

撰写回答
你尚未登录,登录后可以
  • 和开发者交流问题的细节
  • 关注并接收问题和回答的更新提醒
  • 参与内容的编辑和改进,让解决方法与时俱进
推荐问题