Xcodebuild no such module - xcode

I'm trying to build an Xcode project through the terminal. My project uses a submodule called SwiftRichString which I'm importing in one of my files.
On my terminal, I tried:
xcodebuild -project MyProject.xcodeproj
But this says that it cannot find the module called SwiftRichString, as expected.
So then I tried,
xcodebuild -scheme SwiftRichString
This worked and said "Build Succeeded", but then if I try to do
xcodebuild -project MyProject.xcodeproj
it fails just like before.
If I go to Xcode and go to Product>Scheme>SwiftRichString and build it, it succeeds building. Then if I build my project within Xcode, it works, but it doesn't build in terminal.

Related

How to: `xcodebuild -xcworkspace..` with project and swift packages

I have created a xcworkspace to add my iOS.xcproj and local swift package. The workspace builds and runs great from Xcode. What would be the xcodebuild command to do in my CI?
I have been trying using the following:
xcodebuild -workspace [name].xcworkspace -scheme [scheme_name] -configuration [config] -xcconfig [path_xcconfig]
I get this in the output console:
...note: Building targets in dependency order
error: Multiple commands produce <RegisterExecutionPolicyException...
sample:
note: Target 'Firebase_FirebaseInAppMessaging_iOS' (project 'Firebase'): Touch /Users...

Swift Package Manager - Resolve Package Versions terminal command

I want to replace cocoapods with SPM. I have decided to go at it one library at a time. I removed the swinject library from cocoapods and added it via File->Swift Packages->Add Package Dependency
This was successful and the project built and ran as expected.
I then asked other people in my team to check out the branch and see if they can build the project on their side without issues. We then ran into the error "Missing package product 'Swinject'". We resolved this error by performing File->Swift Packages->Resolve Package Versions in Xcode.
I need to get this working on the build server as well. I tried typing in swift package --help in the Terminal app to see what commands are available. The resolve command looked promising so I tried that to no avail. (error: root manifest not found)
So, my question then, is there a terminal command that does the same as File->Swift Packages->Resolve Package Versions?
Note: When I added the 3rd party library via SPM, it created one file for me: Proj.xcworkspace/xcshareddata/swiftpm/Package.resolved. It also made various changes to the Proj.xcodeproj/project.pbxproj file. No package.swift file was created.
Update:
The closest I have gotten to an answer was that I should try xcodebuild -resolvePackageDependencies, unfortunately the command does not do the same as File->Swift Packages->Resolve Package Versions.
I was struggling with the SPM in my project. It seems that you need to pass the -clonedSourcePackagesDirPath [directory]
xcodebuild -resolvePackageDependencies -workspace ck550.xcworkspace -scheme ck550-cli -clonedSourcePackagesDirPath .
xcodebuild -workspace ck550.xcworkspace -scheme ck550-cli -clonedSourcePackagesDirPath .
The first command resolves and downloads all Swift Packages into the ./checkouts and some other ./[dirs] are also created.
The second command initiates the build of your application, and those SPM packages are also built.
Here is output from the build server:
https://travis-ci.org/vookimedlo/ck550-macos/builds/626438212
Travis-CI configuration:
https://github.com/vookimedlo/ck550-macos/blob/master/.travis.yml
From what I have seen, there are 2 Package.resolved files. One on the workspace and one on the project. For some reason the workspace has old versions of the packages and running
xcodebuild -resolvePackageDependencies -workspace myworkspace.xcworkspace -scheme my scheme
does not work. However, resolving on the project (since the project's Package.resolved has the correct packages version info) does work
xcodebuild -resolvePackageDependencies -project myproject.xcodeproj -scheme my scheme

xcodebuild fails, but building from Xcode succeeds

I'm trying to automate my build using xcodebuild.
However, my xcodebuild fails while building static libraries, complaining that it can't find headers that are part of dependency frameworks.
No problem to build from Xcode.
Why is the result of xcodebuild different from the one of Xcode?
You might accidentally build the Xcode project instead of the Xcode Workspace from xcodebuild.
If this is the case, replace:
xcodebuild -project "<*yourProjectFile*>.xcodeproj"
with:
xcodebuild -workspace <*yourWorkspaceFile*>.xcworkspace
After fixing this I get the exact same results from Xcode and xcodebuild.

Xcode 7: Xcode cannot run using the selected device

After upgrade to Xcode 7, Xcode cannot run tests on simulator.
$ xcodebuild test -sdk iphonesimulator -scheme MyProject
Build settings from command line:
SDKROOT = iphonesimulator9.0
xcodebuild: error: Failed to build project MyProject with scheme MyProject.
Reason: Xcode cannot run using the selected device.
The issue is reproduced on Travis CI and Jenkins. It's worked fine when I run xcodebuild test on a local machine.
I've gotten past this error by adding a flag like -destination 'name=iPhone 6'. It seems like xcodebuild used to pick a default destination but isn't doing that anymore. =|
I'm going to see if there is anything I can set in the build scheme to avoid hard coding a device.

xcodebuild build xcode project with dependent project failed. dependent project's target not found

My main project named sample.xcodeproj dependends on sdklib.xcodeproj. The target of sdklib.xocdeproj is sdk.a.
when I build the sample.xcodeproj with xcodebuild command
xcodebuild -project sample.xcodeproj
It failed.
error: no such file or directory:'/Users/.../libsdklib.a
It seems the dependent project doesn't builded. I also didn't see the libsdklib.a in sdklib.xcodeproj's target path. But It runs well in xcode. So where is the sdk.a when I build sample.xcodeproj? and how can I use the xcodebuild command to build sample.xcodeproj with sdklib.xcodeproj?

Resources