xcode build error: swiftc failed with exit code 1 - ios

Every time I tried to build the code getting the following error:
error log screenshot
To create build always need to quit the xcode or clean the project for many times.
Looking for a permanent solution.

You can try it by deleting derived data from Xcode -> Preferences -> Locations -> Derived data
Then clean the project and run.

I just had this issue and its due to path references. You cannot move folders or files in or out of the Xcode project once it’s built. . xcodeproj file should stay outside of the project folder. If you're moving files around or copying folders, check .xcodeproj outside of the main project folder and verify that the folder and file structure is still intact.

Related

unity - xcode build failed with NSUserDefaults.mm file not found message, possibly because com.unity.services.core folder is not in project folder

building an XCode project with an .xcodeproj file generated by unity 2021.3.3f1 fails with the message "Build input file cannot be found: 'users/---/ --project name--/Libraries/com.unity.services.core/Runtime/Device/UserIdProviders/NSUserDefinitions.mm' "
When I look in Finder, I notice that the com.unity.services.core does not exist under the Libraries folder.
Some background. I recently moved to trash many Xcode files to free up disk space. I also did a new remove and Install of XCode, in case I deleted anything important accidentally. Non unity files work fine in XCode.
This might be the first project I used 2021.3.3f1 for. I previously used 2019.4.14f1 without encountering this problem.
Is there something I should set in the IOS Player settings of Unity BuildSettings to avoid this problem? (or something that would force the com.unity.services.core folder to be generated in the output project)?
I am very inexperienced in Mac and infrastructure so I apologize in advance if I am missing something very basic.
Thank you
You should clean your build folders and build anew, should work.
In Xcode you can do this by going to Product > Clean Build Folder, in Unity you just manually delete the whole Build output folder (I hope you created a seperate folder specifically for the Build output and didn't just export to the project directory in that case don't delete your project directory just set a new Build output folder ;).

Firebase Crashlytics with Swift Package Manager - crash because of wrong path

I have installed Firebase through the Swift Package Manager for my iOS project, including Crashlytics. I have followed these instructions and added the required script to build phases:
https://firebase.google.com/docs/crashlytics/get-started?platform=ios
So the path for execution is:
"${BUILD_DIR%/Build/*}/SourcePackages/checkouts/firebase-ios-sdk/Crashlytics/run"
On start up (iPhone simulator), the app crashes with the following error message:
/Users/[path-to-my-project]/SourcePackages/checkouts/firebase-ios-sdk/Crashlytics/run: No such file or directory Command PhaseScriptExecution failed with a nonzero exit code
I don't understand why it tries to find the crashlytics script in my Xcode project folder and not in the derived data folder at runtime.
I checked the derived data folder and followed the path. Indeed, the Crashlytics run script is at the expected path.
thanks for any hints in the right direction
In the meantime I've found out that the path to the build folder is set globally in the Xcode preferences. For some reason I don't recall, my build folder has always been in my project folder for all projects I ever worked on in Xcode... I know this for sure because I always add the build folder to .gitignore.
To change the build folder to be a subfolder of your project's derived data folder, go to:
Xcode -> Preferences -> Locations -> Advanced and select the first option.
Firebase assumes that this option is selected by default (maybe it is and I'm the weirdo...).

iOS build time error Asset.xcasset No such file or directory

I'm getting an error while trying to run the app on the simulator, using Xcode 12.4
/Users/apple/Library/Developer/Xcode/DerivedData/CCBC-
exyindmimlkaxncxdeubzcgqxqgc/Build/Intermediates.noindex/CCBC.build/Debug-iphonesimulator/CCBC.build/Script-7DBCCAD36C20635EF76D902C.sh: line 4: /Users/apple/Desktop/MyProjects/CCBC_iOS/CCBC.xcodeproj/xcuserdata/.xcassets/Asset.xcasset: No such file or directory
When I select the Asset.xcasset from files in Xcode it shows the file path as /CCBC_iOS/CCBC/Asset.xcasset
Thanks for your help
For me, I had to delete an old script that references this Asset file to be built within Derived Data. Regardless of how much I deleted Derived Data and cleared Build Folder, this script still runs the XCAssets reproducing this bug. I would recommend checking out your Build Phases and Scripts and removing unnecessary files especially for old projects.

Xcode build process stuck at "Copying swiftdocs"

Creating a build for my Xcode project takes too much time. It gets stuck at "Copying swiftdocs". I am making a build to run on device. I cant understand why this is happening. No relevant info available on internet. Just for the info, I am using Cocoa Pods in the project.
Is it anywhere related to pods? I am unable to run the app on device.
Xcode stuck indexing error (compiling model, copying swiftdocs, etc.)
Open your Project Folder.
Find ProjectName.xcodeproj file.
Right-Click Copy and Paste to Safe Place.
Right-Click Show Package Contents.
Find project.xcworkspace file and delete that file.
Reopen Your Project and clean and Rebuild.
If your problem is not solved then replace the file with your backup file.
Hope this will work for you. If still not restart your mac some time it works with restart.

xcodebuild failure clang:error no such file or directory:

Having a problem when building with xcodebuild. My project/app builds fine with the Xcode - gui. It simply isn't finding/building the libcryptopp library which is part of the build process.
The error is:
clang: error: no such file or directory: '/Users/builder/repo/ioskpay/xcode-cryptopp/cryptopp/build/Release-iphoneos/libcryptopp.a'
This particular file should be derived from another project inside the main app - xcodebuild simply isn't correctly pointing at the right file folder which should be:
~/Library/Developer/Xcode/DerivedData
Any ideas?
To fix this, go to your project settings, go to Targets and select your main project target. Then go to Build phases. Under Target dependencies add the static library project.
This way, when you compile the main project, the static library subproject gets compiled before the main project and your static library will be available.
I had the same problem, but for a resource file .m
I opened target -> build phases -> Compile sources
and I found the file the compiler was tell it can't find duplicated: one with strange icon and the other with a normal icon. I simply removed the one with strange icon and it worked. ( I added the file multiple times and I had a merge conflict before that which made something wrong in the project file)
For your case I think you need to remove the lib from target dependencies list and add it again. This may work for you.
In Xcode Version 9.2 (9C40b) this happened when I drug a bunch of files into the project, some of which were duplicate. Rather than simply not adding the duplicates, it added them again and only the name, not the path.
In Target > Build Phases > Compile Sources each of the duplicates showed with no "...in" after them. Each one caused the clang error.
After removing all of the duplicates that Xcode collected, the project compiled and ran.
It makes you use the Project Navigator instead of managing your source files in the Finder. Then the Project Navigator can't replace duplicates like any decent file management system (ahem Finder). 🤨
My xCode info is:
I faced similar errors during xcode building projects (native swift, flutter, react native, native script) in which I got error messages related to clang compilar. Errors like:
clang-4.0: error: no such file or directory: '/Users/xxxxxxxx/Library/Developer/Xcode/DerivedData/xxxxxxxxxxxxxxx/Index/Data Store'
clang-4.0: error: cannot specify -o when generating multiple output files
others
Despite of errors related with DerivedData for native apps can be fixed by deleting the directory and, eventually, restart xCode and even restart the machine... in this case, you will see that after deleting the directory and start building process again, the error comes back.
Then, is the moment of checking the clang installation by running clang --version. The normal output will be something like:
as you can see the InstalledDir is incorrect for xCode. In my case, some days ago I needed to install Anaconda app (R, Python, etc) and, now, I remember that I had to install some dependencies and one of them was clang and its installation was altered.
To fix this problem (in my case that I will not need anaconda any more): (edited)
1.- Delete anaconda and all its dependencies (I recommend to use App Cleaner).
2.- Re-install xCode
After reinstalling xCode, if you type again clang --version, you'll get this:
More info at: https://github.com/flutter/flutter/issues/32457#issuecomment-496161092
Hopefully, this info helps some else.
Best
Ok so by simply adding the correct -target -configuration and -scheme parameters I got this to run correctly. However due to my running this in Jenkins for autobuild purposes it still doesn't work as I'd like - getting stuck in exactly the same place. It's odd because I have the exact same code being built in another job that isn't having this problem. There is no rhyme or reason for it at this point. I will keep shooting rubber bands at it and update when I have an answer...
Sometimes Xcode performs weird.
You have to find that static library project e.g.. "filename.a" under 'Link Binary With Libraries' in Build Phase and then remove it and add it again.
I had the same problem while I was archiving my target. I removed the library and the build succeeded.
For me it was because I had removed a package or pod. I ran pod install and it fixed it
Look for the missing file in the Xcode project i.e the files may be deleted or miss placed.
add the missing files to the xcode, then everything will work fine.
Run this command :
$ conda deactivate

Resources