Checking for Errors Running xcodebuild (Command Line) for iOS - ios

I'm currently working on a script to build my iOS projects.
I am able to run the archive command using...
xcodebuild -workspace <workspace_name> -scheme <scheme_name> 'archive'
But what is the best way to check for errors? If there is a way to do it without parsing the logs, it would be great. However, if parsing the logs is the best way, what's the best string to look for?
I tested for return codes. xcodebuild returns 0 on success, but also when there are build errors.
Thanks in advance!

Using -project parameter, you can build your project. Goto your Project.xcodeproj folder on terminal. Then type,
xcodebuild -project projectname.xcodeproj
Check this xcodebuild reference .

Related

Build Xcode project from command line that use OneSignalNotificationServiceExtension

I am trying to build an Ios app with Objective-C xcode project
The project is using OneSignalNotificationServiceExtension that is why I am specifying the architecture.
the command:
xcodebuild ARCHS=armv6,armv7 ONLY_ACTIVE_ARCH=NO build
but the compilation fails and It throws an error:
Exiting because upload-symbols was run in validation mode
The reason I am doing this is because I need to use the sonarqube wrapper and it takes the build command as argument:
sonar-wrapper --out-dir=bw-output <<build command>>
but I am only able to build the xcode project using xcode
If there is a better way to integrate sonarqube to this kind of projects let me know please.
Maybe try using Fastlane instead of using the xcodebuild CLI directly, I find Fastlane is much more user friendly. I use it for my CI/CD deployments.
It looks like there is some Sonarqube integration as well:
https://docs.fastlane.tools/actions/sonar/
Website: https://fastlane.tools
I successfully built the project specifying the debug mode, workspace and scheme like this:
xcodebuild -configuration Debug -workspace <<workspace>> -scheme <<scheme>> clean build

How can I build the Xcode-generated Swift Package Workspace with xcodebuild?

When you open a Package.swift file, Xcode will generate a workspace with the path: .swiftpm/xcode/package.xcworkspace.
I'd like to use xcodebuild to build this but it does not seem to work. The error messages are not helpful, just tells me that clang failed.
The actual command I'm running is:
xcodebuild -workspace .swiftpm/xcode/package.xcworkspace -scheme MyLibrary-Package -sdk iphonesimulator OTHER_SWIFT_FLAGS="-D SWIFT_PACKAGE"
Funny enough, trying to build a scheme that describes an individual target works:
xcodebuild -workspace .swiftpm/xcode/package.xcworkspace -scheme SpecificTarget -sdk iphonesimulator OTHER_SWIFT_FLAGS="-D SWIFT_PACKAGE"
Am I missing some build flags needed to build the combination scheme? Has anyone else struggled with this and have any advice?
Note:
The ultimate goal here is to be able to verify that my Swift Package builds in CI. If there is an easier way to achieve this goal then I'm happy to go another route. (The easier might just be multiple commands to build the individual targets but this is less robust)

Printing to the Xcode (XCTest) UITest Report

I'm currently writing UITests for an iPhone app and currently use NSLog to print when there is an unexpected situation in helper methods, this causes a false assertion at the test level so it's clear where the error occurs in the test. Then I just read the log to see what the issue was. Is there a way to print this to the test report so I can check all failures once all the tests run? Right now the only log results are the ones that the test generates automatically (such as "Tap 'myButton' Button" or "Find: Elements matching typeButton")
I'm happy to make any necessary clarifications.
First of all, you can check your
TestSummaries.plist file
which is generated in
/Users/username/Library/Developer/Xcode/DerivedData/project-name/Logs/Test/TestSummaries.plist
If you open the file in xcode, you will see all your test summaries but in little bit bored way. You have to expand all the nodes. But you can make an html report by using
xcpretty
just use this command in your terminal
xcodebuild test -project projectname -scheme schmefilename -destination 'platform=iOS Simulator,name=iPad 2' | xcpretty --report html --output outputfolderdestination/report.html
To install xcpretty, use the below command
gem install xcpretty
You can use XCUITestHTMLReport. It creates an Xcode like HTML report
You use it like this
$ xcodebuild test -workspace XCUITestHTMLReport.xcworkspace -scheme XCUITestHTMLReportSampleApp -destination 'platform=iOS Simulator,name=iPhone 7,OS=11.0' -resultBundlePath TestResults
$ ./xchtmlreport -r TestResults
Report successfully created at TestResults/index.html

Xcodebuild is not creating an app

I'm trying to create a simulator app to submit to Facebook for review. I've followed their instructions to the letter, but keep running into problems. I am using CocoaPods and have a workspace instead of a plain old project. Here's the command I'm running:
xcodebuild -arch i386 -sdk iphonesimulator8.1 -workspace [APP].xcworkspace -scheme [APP]
I get a ** BUILD SUCCEEDED ** message, but either one of two things will happen:
No build folder is created, and I can't find where the .App file is.
A .App is created in a build folder, but is 0 bytes in size and crashes when running with ios-sim.
I read that changing the Run scheme to 'Release' might fix it, but that didn't do anything. Any ideas?
So, I had the same problem and solved it by doing the following:
I made my app as release build instead of debug in xcode: Product->Scheme->Edit Scheme and then Build Configuration set to Release.
After doing this I then went back to the command line and added a destination for the build:
xcodebuild -arch i386 -sdk iphonesimulator8.1 -workspace [APP].xcworkspace -scheme [APP] -derivedDataPath /path/to/build
If you are still having problems make sure you clean and build all of your targets (pods included) and try the above steps again.
Hope this works; it did for me.

Prefix.pch framework file not found error xcodebuild

I'm trying to build an app using the xcodebuild command.
I'm using this commmand xcodebuild -project appNameWithExtension -target name -sdk iphoneos -configuration Release"
I have a framework added to my app and when I try to build with xcode there are no problems but when I try to use my xcodebuild command I get this error
/path/appname-Prefix.pch:16:13: fatal error: 'frameworkname/frameworkname.h' file not found
It's pointing to this line of code in my Prefix.pch file
#import <frameworkname/frameworkname.h>
Does anyone know a way to make the xcodebuild commmand find the framework, because it seems like I'm missing something in the command to tell it where to find the framework. I can build with xcode, but I can't build from commandline, so I'm probably missing something?
Any help would be much appreciated :)

Resources