Intermittent Swift Framework Compiler Error - ios

I am trying out Swift in the XCode beta. In particular using an #IBDesignable and #IBInspectable. I am building a framework containing an (#IBDesignable) UIView subclass and a Simple iOS App in order to test it out (Both contained in and linked via a workspace). After a few successful builds I get the following error in the framework build output:
:0: error: /Users/richardpj/Projects/Swift2/Swift2FW/build/Swift2FW.build/Debug-iphonesimulator/Swift2FW.build/unextended-module.modulemap:2: umbrella header 'Swift2FW.h' not found
:0: error: could not build Objective-C module 'Swift2FW'
Before you ask I've done a clean and deleted my derived data but nothing seems to resolve it except deleting and recreating the workspace and project files.
Any ideas on the source of the error, how to replicate (for a bug report) OR am I being dumb.
EDIT: I've gotten 50 views since this was posted. Sounds like it's a bug I should report. Any ideas on how to do that?

When making my own swift framework I got the error "could not build Objective-C module".
I fixed it by going to "Link Binary With Libraries" and adding "UIKit".

In case if you are writing embedded framework in Swift check your Project Settings -> Framework Target Name -> Build Phases -> Headers. Currently (Xcode 6.2) any header file listed in Public section here can cause this error:
<unknown>:0: error: could not build Objective-C module 'YourFrameworkName'

I was seeing this error when the .h umbrella file had the same name as one of my swift files. Once I changed the name of the swift file the framework built.
Ex. Project Name: TestProject
|_
TestProject.h <=
|_
Models
|_
TestProject.swift <=
Having the two files with the arrows ( <= ) named the same caused the "could not build Objective-C module" error for me.

In my case I had a previous build setting that overrode Public Headers Folder Path (PUBLIC_HEADERS_FOLDER_PATH) . Clearing that to the (new?) default value of $(CONTENTS_FOLDER_PATH)/Headers fixed the error.

In my case, all I had to do was open the "Edit Scheme" window (Product > Schemes > Edit Scheme) for the embedded Swift Framework target and uncheck "Shared". I guess because non-embedded Swift frameworks aren't yet supported, sharing a framework scheme implies there must be an Objective-C component of the module.
You can also uncheck this in the "Manage Schemes" window (Product > Schemes > Manage Schemes...).

After coming across this problem many times and sometime resorting to recreating the whole project I have found that this very strange build problem is normally caused by you having Breakpoints set.
Open the Breakpoint Navigator Window (CMD-7) and delete all the breakpoints.
This normally fixes this problem for me however bizarre it may sound.
It's very easy to accidentally add a breakpoint when you're clicking in the margin to investigate compilation errors.

I don't know if this will help anybody else but I had imported the ProjectName-Swift.h file into the ProjectName.h (umbrella header) file during some testing, and when I removed that import the error went away and I was able to build again.

In my case this turned out to be because I had failed to list the framework as a dependency in the build phases of my other target(s). As soon as I did that, all was well.
I presume that it is because this ensures that the framework is build before the target(s) that use it.
The reason this issue is intermittent is evidently that, without the dependency, the order of building is indeterminate — so sometimes it happens to be the right order and the build works, and other times it happens to be the wrong order and the build fails.

Related

Build error Xcode 10 - Multiple commands produce

I just upgraded to Xcode 10, and I suddenly face this error when I try to build, any ideas how to fix it? I tried cleaning derived data, but without any luck.
If you use CocoaPods, click Xcode menu file -> Workspace Settings , And click Build system choice Legacy Build System
If you not use CocoaPods, same of top , select Project Settings
If your app is generating the error related to the multiple .app files just like mentioned above in question then removing the .plist files from "Copy bundle Resources" WILL NOT WORK.
If the error is related to .app file then follow the following steps.
Select the Target.
Go to Build Phases tab.
Remove the items listed in Output Files
Compile the code if it compiles successfully then not follow the next steps.
If code does not compile successfully and Xcode may give you an error related to "Library not found". Then add the missing library in General Tab in Linked Frameworks and Libraries that Xcode mentioned in the error.
Keep adding these libraries (that Xcode ask through compile errors) in Linked Frameworks and Libraries until the code compiles successfully.
Hope this helps.
You can try to change the build system to Legacy,
File > Workspace Settings > Build System > Legacy Build System.
I also faced this issue in xcode 10 but it was because of adding the same framework in main project + other extensions (watchkit or siri extension etc).
I added ObjectMapper in podfile for my main project + for my extensions. When I compiled it gave me an error that multiple command produce and also shows me which framework is causing this issue. Now its working fine for me as I've removed it from my extensions I wasn't using it in my extensions.
Don't know about your issue may be you can check your podfile.
If this is CoreData related. The issue is that you are trying to generate the NSManagedObject subclass but you need to set the 'CodeGen' option to Manual/None. This option is defaulted to Class definition and this would regenerate the code thus creating this issue.
i encountered this issue as well while working with CoreData.
in my .xcdatamodeld file, it came down to the fact that, during the creation of my various Entities, i had copy and pasted one multiple times (thinking i was saving time because various properties were similar enough that i thought this was a good idea).
the resulting Build error Xcode 10 - 'Multiple commands produce' occurred because i forgot to check and make sure the new Entities were set to their own unique corresponding class to match the new Entity in the Data Model Inspector pane.
unfortunately, it took me two days to figure out the original Entity's Class Name was still in place.
so lesson: careful when you copy/paste/duplicate Entities in CoreData.
(... i guess :0} )
some time saver. oops! hope this helps someone.
I had this same issue with Core Data entity class. I had forgotten to select Codegen Manual / None because I do not allow mine to be autogenerated. So I had a class in place and also it was trying to generate one.

How to fix Application Loader Error: Invalid Bundle. The bundle ... contains disallowed file 'Frameworks'

I have a Swift project with three Swift custom frameworks. The App builds and runs successfully but when I try to upload to iTunes Connect using Application Loader I get the following error for all three frameworks:
ERROR ITMS-90206: "Invalid Bundle. The bundle at 'XXX.app/Frameworks/YYY.framework' contains disallowed file 'Frameworks'."
As discussed in this SO answer I have set the 'Embedded Content Contains Swift Code' to NO in the frameworks and YES in the App, but this error persists.
The three Frameworks are all my own (I am seriously considering reworking the project to avoid Frameworks altogether but that is a chore I would like to avoid right now).
I am not using cocoapods.
Any ideas on how to resolve this error?
The key to solving this for me was, in addition to ALWAYS_EMBED_SWIFT_STANDARD_LIBRARIES=NO, also setting EMBEDDED_CONTENT_CONTAINS_SWIFT=NO in build settings for all targets except the main app target. Had to clear out derived data, but after that all was well.
In (SE-0133) of the Xcode 8.3 Release note, there's a description about EMBEDDED_CONTENT_CONTAINS_SWIFT setting:
The new build setting ALWAYS_EMBED_SWIFT_STANDARD_LIBRARIES replaces the EMBEDDED_CONTENT_CONTAINS_SWIFT setting, which has been deprecated. This new setting indicates that Xcode should always embed Swift standard libraries in a target for which it has been set, whether or not the target contains Swift code. A typical scenario for using this setting is when a target directly uses or embeds another product that contains Swift code. (26158130)
which means ALWAYS_EMBED_SWIFT_STANDARD_LIBRARIES has replaced EMBEDDED_CONTENT_CONTAINS_SWIFT, thus you need to change the former one(ALWAYS_EMBED_SWIFT_STANDARD_LIBRARIES) to NO in the extension target.
So this is not a good answer, but it is what I did to resolve it:
I created a new project and copied in all my files - in a flat structure without Frameworks, editing just to remove the relevant import statements. It now uploads fine. So it is the Framework structure that is the root of the problem. Not sure if the idea of Swift embedded custom libraries is just broken or I was doing something wrong so still looking for better answers...

iOS : Could not build module <framework-name>

I've got Library from another team. I'm trying to use library in our project and while do so getting an error Could not build module 'Common Library' (name of framework)
Below are solutions that I worked on but didn't helped :
1. Delete Derived data content. Clean and Build.
2. Framework is added in 'Link binary with libraries' of Build phases.
3. While adding framework checkmarked : Target and Copy content to folder.
Even I tried this stackoverflow-link but didn't got any break-through!
The only thing that worked was deleting Objective-C bridging header path in Swift compiler - code generation section of build settings in Project.
However, thereafter I'm not able to get Common interface to create instance (i.e. Common dosen't appears in drop-down list)
Below is framework structure.
Any other fix?
you can try delete DerivedData dir.
where is DerivedData?(xcode 8)
go to File > workspace Settings, you'll see DerivedData path.
DerivedData path in xcode 8
Check whether the framework you are integrating is supporting your project architecture.
To see the framework supported architecture, use Terminal and navigate to Framework folder.
use, "lipo -info myFramework.framework/MyFramework"
And, if you want to use the framework files in your project, check whether the files are available in Framework/Headers Folder.
Getting this error :
Try, "file myFramework.framework/MyFramework" in Terminal
I think you does not need to compile CommonLibrary.framework again. So you can try to remove it from Embedded Binaries list. And make sure the path of CommonLibrary.framework is in your Framework Search Paths.
I also had this problem:
1. My 'GoodLuck' framework had two headers: GoodLuck.h and GLAdder.h
2. Project which import this framework couldn't compile
Solution:
Import GLAdder.h in GoodLuck.h, rebuild the framework. It works.
I also had this problem, due to a typo in my GCC_PREPROCESSOR_DEFINITIONS, which therefore invalidated all of my code.
First helpful warning was multiple "Macro Name must be an identifier" followed by multiple "Could not build module" messages.
As this question do not have answer yet, so adding my answer here it may help in future for some another developer.
I know due to privacy you can not disclose the details.
I have used same library and faced same issue so just did did this two things it is working fine.
In General -> Frameworks,Libraries -> CommonLibrary.framework just select that and choose -> Embed Without Signing.
Build Settings -> Search for "workspace" -> Validate workspace -> set it NO
That's it you are done.

ERROR "swiftc failed with exit code 1" when converting to latest syntax

I was trying to convert syntax of old Swift project to new one as per few suggestion on Stack Overflow I tried converting it through Edit > Convert > To latest Syntax that did not work properly instead I started getting new errors shown as below
Command/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/swiftc
failed with exit code 1
And
Command /usr/bin/ditto failed with exit code 1
I tried Xcode 6.0.1 Command /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/swiftc failed with exit code 1, but it's a different situation.
Have you tried to do clean with Clean build folder?
The combination keys is:
ALT + SHIFT + COMMAND + K
Try delete Derived Data folder and Build it.
Go to Xcode -> Preferences -> Locations for get the derived data path
Clean Xcode. (cmd+shift+k)
Quit Xcode completely.
Open project again.
Wait for Xcode to indexing files.
Now run your project.
Just had the same issue. For me it was because I had renamed some of the project directories. I had a ton of red files in my project navigator. To solve, follow these steps:
click on the directory in project navigator where many files show as red
Under "Identity and Type" in the File Inspector (on the right side), click Containing directory
Select the new directories
Rebuild - command shift K, command B
As far as I know there can be multiple reasons why a compiler fails. Although cmd+alt+shift+k will help most of the time. If this fails, then click on the error message and try to debug it.
For example in the image below, if you read the message, we get to know that, there has been a name duplication. Fixing the name duplication will fix the issue.
Just remove inactive file(deleted file) from Build phases
then
Clean Xcode. (cmd+shift+k)
delete Derived Data folder and Build it.
Go to Xcode -> Preferences -> Locations for get the derived data path or cmd+Alt+shift+k
OR
Just remove inactive file(deleted file) from Build phases
Cleaning the project wasn't working for me, this is because I didn't pay attention to the message right above (Xcode highlights only the final command).
In my case it was
<unknown>:0: error: filename "FileDuplicated.swift" used twice: '/../filepath/FileDuplicated.swift' and '/../filepath/FileDuplicated.swift'
<unknown>:0: note: filenames are used to distinguish private declarations with the same name
Command /../bin/swiftc failed with exit code 1
I had to change the name of one of the two files and it was solved.
Hope this can help someone, cheers
In my case it was due to the few swift files which has been showed grayed out in the Build Phases section. After removing those files it was successful.
In my case I deleted few files from project and when try to commit the code, the files was showing there . To solve this issue.
1. Open terminal
2. Type git clean -n // it will show you list of files which are deleted from project but still are saved somewhere
3. Type git clean -f // All unwanted files will be removed
In my case, it was "Other swift flags". I had declared a flag there but not -D, so this was not getting recognized and resulted in the same error
In my case swift development snapshot was selected instead of xcode 9.2. here are the steps and image.
xcode on screen and click on xcode top menu bar.
Than go to toolchains option and check on xcode 9.2. thats it.
Note: If no toolchain found in your xcode than download from Here and install it. (after installation restart xcode).
Happy Coding!!!
Ok, my turn now. In my case I had an existing project. I copied in a few files from another project. One of the files I brought in was SettingsViewController.swift and there was already a file by the same name I was not aware of. The files were in different directories of the project so no duplicate message was shown. The compile/link messages offered no clue to this. I figured out the issue by adding one file at a time to the project (there were 12 total) and the building each time until I found the offending file. I renamed the new file and project builds now.
In my case it was a compiler flag change that didn't work well. It took a few compiles before it actually started failing though! Xcode caches what it compiles.
I just had this issue. It's due to path references. Have you been moving files around and/or copying folders? Check if .xcodeproj is inside or outside of the main project folder. Also, make sure that the project's file and directory structure are intact.
/yourFolderProjectName/ <-- contains your .xcodeproj file AND folder with Xcode project name
/yourProjectFolder <-- here are .swift, info.plist, assets folder, etc.
/yourProjectXcodeFile.xcodeproj
Another thing to check:
In my case I had deleted a row in the "Other Swift Flags" section in the Build Settings screen under the Release setting.
That row had been a value for a compiler flag key/value pair. So the key was there but not the value.
Once I deleted the key as well, then the build worked again.
This issue is happening because of pods
So Follow the below steps to resolve this issue
Remove all the pods and re-install again.
Remove all the pods using below this command (rm -rf "pwd/Pods/")
Quit the Xcode and open it again and build the app with device (generic iOS device).
Now check this issue will be resolved.
I had this error when Xcode found two .swift files with same name. Rename one of them and build again.
Wait for completing the indexing and run the project again. You must get an error then check it which may be Objective-c bridging file not found error. This error comes if you are using any Objective-C library or code directly in the project and your project unable to find the bridging file in the system. This issue basically caused by, if project is unable to find any file in the system which is using in the project (path issue).
I faced this issue while using the Swift auto-generated header file in my project (named as 'TargetName'-swift.h) to use Swift classes in Objective-C.
There was a typo in the file where I had imported this swift header. Correcting the typo helped me resolve the issue.
Clean the build in Xcode cmd+shift+k.
Update the pods.
look the where errors showing.
Add the missing files in Xcode.
After Run the Code. Working fine.
Try below if none of the above working for you.
My project location was desktop/my_project_folder
I tried all above then i made simple change.
I create one more folder on desktop past my project
.
then...
Cause of problem in my case:
This problem occurred when i change my project name in xcode & project folder name from desktop.
I was working on a private pod and was also pointing to it locally. I had made some file name changes.
Hence I was getting this error.
All I had to do was to run pod install so it would reflect the file name changes. After that it compiled.
In my case I copied a core data entity and only renamed the entity but not the class.
So go to your xcdatamodel and select the enitity > rename also the class name
Had the same issue but with duplicate file references.
Deleting Derived Data and cleaning had no success. But I got it fixed by doing this:
Navigate to your project.pbxproj -> open with your text editor of choice(I use atom).
Command+F and find the duplicate file sources and then delete them.
Build/Run and should be fixed.
For me, it was the keychainAccess problem as described in this answer (my error messages were completely opaque, all I had to go by was 'failed with exit code 1')

linker command failed with exit code 1 (use -v to see invocation) in Swift

I used Swift language in my IOS application project in Xcode6 Beta6 and then I had to work on it with another computer. Then I got this error:
"clang: error: linker command failed with exit code 1 (use -v to see invocation)"
This error is shown only different computers than the computer on which I opened my project at first. It does not give an error in the first computer (which I opened and started to the project)
I tried to clean, and delete the contents of DerivedData folder, but it gives me the same error again. Below this error, it also says that "file not found:" for inside of the DerivedData folder:
file not found: /Users/macbook/Library/Developer/Xcode/DerivedData/SihirliSayilar-gmmsqkhqgygosqeuqdiibnrjasbq/Build/Products/Debug-iphonesimulator/Project.app/Project
I looked the other titles for this issue, but none of them solve this problem.
Thank you for any help!
The fact that it's a linker error should point you into the right direction. Compilation errors usually mean an error in your syntax. Linker error means that although your source files have been compiled correctly, but when the time comes to be linked with other frameworks (system frameworks, or 3rd party ones), clang cannot find them in place.
Usually, this is because a 3rd party library is missing from your system, and your project depends on it, and although it can find the header files, it cannot find the actual library file to connect to. The fact that transferring your project to other computers is giving you problems, while at your computer compiles and links correctly also strengthens the assumption that probably it's a problem with the environment you are trying to compile with and you need to install something.
To find out more about the issue, go into Xcode, go into the report navigator, and you will see logs of all the builds you have made. Check the first one (which is the last build). Scroll to the bottom, and see exactly why it didn't compile. The most common scenario is that some symbol could not be found. Check in which library this symbol belongs, then install this library to your system.
I got same error you have mentioned. I have just clean the project and build it.
It worked!
You can clean the project in Product Tab and select clean. To build select build in product tab in Xcode.
I encountered the same problem and my solution is as follow:
Close the current project in xcode --->
Go to your project file and open the project by clicking the .xcworkspace file. Note: not the .xodeproj file.
Hope this helps!
In My case it worked like this:
-> Click on the project
-> Go to "General" tab
down there
-> Go to "Linked Frameworks & Libraries"
-> Click of the "+" button , you will find something like this -> Pods_yourProjectname.framework add it
-> Then add the Frameworks that you have added from there only!
-> "Command+B" (Build your Project) and the combination "Shift+Command+K" (Clean your Project)
-> Run your Application.
Simple Solution in my case:
Product -> Clean
and then:
Product -> Run
I faced this error when I opened .xcodeproj instead of .xcworkspace while using cocoapods dependency manager.
Make sure you are opening .xcworkspace.
I had the same error, and after digging through the logs I found the error "Duplicate Symbol"...
After a heap of searching I found that I had #imported a ".m" file instead of a ".h"
Maybe this might help someone.
In my case,
I faced the same clang error when I opened myproject.xcodeproj file instead of myproject.xcworkspace by mistake after installing cocoapods to my project.
it can be anything in your code, for me it was a problem with coredata classes?:
#objc(Attribute) // the problem
class Category : NSManagedObject{
}
changed to
#objc(Category)
class Category : NSManagedObject{
}
Set Host Application to your Project Target. Also, check the Allow testing Host Application APIs is turned on.
You might have to link file recently added. In My case files were not added but it got referenced in the project. The referenced file name must be appearing in red color. first, delete the referenced file, then you can right-click on the group add the file manually.

Resources