内部循环; 构建可能产生不可靠的结果: Xcode Error

在使用 Xcode 10进行编译时,我试图转移到新的构建系统。然而,它给出了以下错误:

Cycle details:
→ Target 'project' : LinkStoryboards


Target 'project' has compile command with input '/Users/project/Commons/Components/ScreenshotSharing/ViewController/AppShare.storyboard'


Target 'project' : ValidateEmbeddedBinary /Users/project/Xcode/DerivedData/project-hgqvaddkhmzxfkaycbicisabeakv/Build/Products/Debug-iphoneos/project.app/PlugIns/stickers.appex


Target 'project' has process command with input '/Users/project/Resources/Info.plist'


Target 'project' has compile command with input '/Users/project/Commons/Components/ScreenshotSharing/ViewController/AppShare.storyboard'

Screenshot added

即使在删除了问题文件之后,对于另一个 xib/Storyboard 也会得到相同的结果。如何在不恢复到遗留构建系统的情况下解决此错误?

84439 次浏览

I was finally able to resolve this by moving Embed App Extensions script in Build Phases of main Target to last position.

Xcode 10's new build system detects dependency cycles in your build and provides diagnostics to help you resolve them. Fixing these dependency cycles improves the reliability of your build, so that the correct products are produced consistently (cycles are a possible cause of needing to delete your derived data). It also improves your incremental build times, as cycles in the build cause something in your build graph to always be out-of-date on each build, making the build re-do work unnecessarily every time you build.

There is documentation on resolving some common types of dependency cycles in Xcode Help: https://help.apple.com/xcode/mac/current/#/dev621201fb0

That said, this cycle diagnostic looks a little odd. It sounds like you were able to resolve it by re-arranging your build phases, but I don't think the diagnostic really explained the problem. If you wouldn't mind, a bug report about improving this diagnostic for this particular case would be very much appreciated. You can file one at https://bugreport.apple.com. Please include all details about your project that you think might be relevant; a sample project that reproduces the issue is ideal, but if you can't attach that, the diagnostic and some idea of the project structure is still helpful.

I was having this issue with Cocoapods. The solution was to clean the build folder re-install all pods, and then rebuild the app. The issue resolved itself that way.

I fixed my problem by moving the 'Copy Bundle Resources' Build Phase before all my 'Copy Files' & 'Link Binary with Libraries' Build Phases

For anybody having an issue with Xcode 10 build system, follow the following steps to fix it:

  1. In Xcode, go to File->Project/Workspace settings.
  2. Change the build system to Legacy Build system.

It will resolve the build issue with the new Xcode.

If you want to work with the new build system, then you can find the troubleshooting help from this apple Xcode help page.

Same issue on Version 10.0 beta 3 (10L201y) and I wanted to have the New Build System.

Problem is had disabled Enable Modules (C and Objective-C)

in Build Settings -> Apple Clang - Language - Modules

After enabling it (set to YES) got rid of the Error.

In the target's Scheme, find the label Build, and ensure that Find Implicit Dependencies is not checked. These steps may work.

I was having this issue with Cocoapods and found a temporary workaround:

  1. Install latest version of cocoapods (1.5.3): sudo gem update cocoapods
  2. Delete you derived data: rm -rf ~/Library/Developer/Xcode/DerivedData/*
  3. pod install

Source here and I'm on Xcode 10 beta 4.

EDIT: now on Xcode 10.0 and still relevant.

I was facing the same issue: below was the error

Cycle in dependencies between targets 'Pods-MyAppName' and 'RxCocoa'; building could produce unreliable results. This usually can be resolved by moving the target's Headers build phase before Compile Sources. Cycle path: Pods-MyAppName → RxCocoa → Pods-MyAppName

I solved it using the below steps:

1). Go to target RxCocoa in Pods-MyAppName project

2) Go to build phases

3) Drag the Headers Phase and move it above the Complile Sources build phase.

This fixed my issue. Hope it helps!

I've met similar issue when tried to archive my project on Xcode 10. Here's the detail text:

→ Target 'mytarget': CodeSign /path/to/mytarget.app


○ Target 'mytarget': SetGroup staff /path/to/mytarget.app


○ Target 'mytarget': SetMode u+w,go-w,a+rX /path/to/mytarget.app


○ Target 'mytarget': SetGroup staff /path/to/mytarget.app

Fixed it by setting $(USER) in mytarget -> Build Settings -> Deployment -> Install Owner

It seems that you need to change the order of the build phases within your Pods targets. For me, moving Headers above the rest worked. You can automate this in your Podfile:

require 'xcodeproj'


post_install do |installer|
installer.pods_project.targets.each do |target|
headers_phase = target.build_phases.find { |p| p.kind_of?(Xcodeproj::Project::Object::PBXHeadersBuildPhase) }
if headers_phase
puts "#{target.name}: Moving Headers build phase to top"
target.build_phases.insert(0, target.build_phases.delete_at(target.build_phases.index(headers_phase)))
end
end
end

I had a similar issue with a mixed interaction between Swift, Objective-C and CoreData: in my project (written in Swift) I made use of Core Data's autogenerated Swift classes as well.

But at one point I needed an Objective C class with public properties (defined in its header counterpart) referring the the core data entities.

#import "ProjectName-Swift.h" // this is to import the swift entities into ObjC


@interface myObjCClass : NSObject


@property (nonatomic) MyCoreDataClass*myEntity;


@end

As soon as I changed the CoreData model, XCode tried to rebuild the classes and I got hung with the indicated cycle build error.

After an initial moment of despair, as I did not have any compile header phases in my project to change the order of, I found out that solution was quite simple:

In the myObjCClass.h I removed the shared Swift header import statement and changed it with a @class directive:

@class MyCoreDataClass; // tell the compiler I will import the class definition somewhere else


// the rest stays the same
@interface myObjCClass : NSObject


@property (nonatomic) MyCoreDataClass*myEntity;


@end

and I moved the #import "ProjectName-Swift.h" statement into the myObjCClass.m class definition file.

#import "myObjCClass.h"
#import "ProjectName-Swift.h"


@implementation myObjCClass


@end

And it builded no worries.

My solution was simply to Clean Build Folder then re-build.

Core_Data

I had the same problem and error but mine happened when I "Created NSManagedObject Subclass" for my entity and I faced this error. So if you think your error is same as mine about Core Data what can probably help you (and helped me ) is to:

  • click on your Entity in you "xcdatamodel" file
  • go to your right bar click on Data Model Inspector
  • change "Module" to "Current Product Module"
  • and finally, change "Codegen" to "Manual/None"
  • clean and build

I think because in other scenarios Xcode creates a file automatically and when we create another one it causes a conflict.

You might be able to fix this here:

File -> Workspace Settings -> Build System: New Build System

Workspace Settings

I have tried things from this page but the only thing that has helped me was that I made a copy of the target and updated the name of the copy (removed the copy suffix), and deleted the old one, and did pod install afterwards.

My issue had to do with a cyclical dependency between my swift bridging header and my objective c files.

In my objective c header files I had a #import "...-swift.h" file and then in a couple of my swift files I was including those files with said import and thus causing a cyclical dependency.

This is the StackOverflow that led me to find the solution:

Objective C, Swift Interoperability issue due to circular dependency

How to prevent circular reference when Swift bridging header imports a file that imports Hopscotch-Swift.h itself

EDIT:

I wound up converting the above files to swift and this solved my issue.

Following two options worked for me: File->Project/Workspace settings.

1, Change the build system to "Legacy Build system" in File->Project Settings

2, Edit Scheme and Select "Parallelize Build" option under Build section.

Xcode 10.2.1/Unit Test Target. My unit test target is independent of host target to improve building time. Solve it by uncheck Find Implicit Dependencies in Scheme - Build options, As i specify all dependencies in Build Settings - Compile Sources.

In fact, you only need to pay attention to Xcode's prompt This usually can be resolved by moving the target's Headers build phase before Compile Sources, and then you can do it.

When I encountered this problem, Xcode prompts me:

:-1: Cycle inside XXXX; building could produce unreliable results. This usually can be resolved by moving the target's Headers build phase before Compile Sources.
Cycle details:
→ Target 'XXXX': LinkStoryboards
○ Target 'XXXX: Ditto Path/XXXX-Swift.h /Path/XXXX-Swift.h
○ Target 'XXXX has compile command for Swift source files
○ That command depends on command in Target 'XXXX: script phase “Run Script”

I only did one thing and solved the problem perfectly:

Select Target and then select Build Phase to move the Run Script to the front of Compile Sources.

Run, compiled successfully.

The principle is simple, just change the compilation order.

image 1

Xcode 10.2 & Swift 5

I faced this problem after updating Xcode to version 11.4. Downgrading to 11.2.1 fixed it.

Xcode: 11.3.1 Target: XCUITest target

  1. Run command to clean build folder : rm -rf ~/Library/Developer/Xcode/DerivedData/*

  2. Change workspace settings: Select Legacy Build System

enter image description here

In the project pane on the LHS, for your build products, don't select them in the list for Target membership in the RHS pane.

The best temporary fix I've found (until you resolve the root problem) is to make a simple change to the source code (even something as trivial as adding a new line) then trying again. I find that making even a whitespace change is enough to allow it to build again. However, this is definitely temporary as it will likely happen again after a few tries.

This is better than cleaning the build folder (which I found to also be temporary) since it's much quicker to make a whitespace change and rebuild, than to clean the build folder and rebuild (especially on larger projects).

Had this problem for a while as well. Added the following block at the end of the podfile (this will also get rid of some warnings):

post_install do |installer|
installer.pods_project.targets.each do |target|
target.deployment_target = ios_version
target.build_configurations.each do |config|
config.build_settings['IOS_DEPLOYMENT_TARGET'] = 'iOS ' + ios_version
end
end
end

I also moved use_frameworks! to the root of the Podfile.

I have the same issue with Cocoapods.

Firstly, remove pods:

rm -rf ios/Pods

then install pods again:

cd ios && pod install && cd ..

Then run your app, it should works now.

In my case,

Removed all pods and reinstall resolved the error

Remove Pods directory in ios folder
pod install

Only for Expo

  1. expo prebuild --clean
  2. cd ios
  3. pod install
  4. yarn ios

if you are developing on React-Native, it was the best way for me.

cd ios && rm -rf Pods && pod install && cd ..

cd ios && rm -rf Pods && pod install && cd ..

This worked for me.