Build Xcode project from command line that use OneSignalNotificationServiceExtension - ios

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

Related

Xcode UI Tests : xcodebuild fails to generate Coverage.profdata on xcode12, fails with error 'error: No profiles could be merged.'

Here is how we are setup while facing the issue.
We have a project which has both UI and Unit tests.
Uses fastlane.
Has CI/CD implementation using Jenkins which runs on an aws ec2 instance.
Quite recently we moved to Xcode12 (I know!!! However, better late than never)
Problem statement:
After moving to xcode12, the jenkins pipeline is unable to generate the Coverage.profdata file which in turn will be used by Slather to derive code coverage metrics. Yes, did not happen when running xcode11.
We are using the xcodebuild command after pointing it to the appropriate command line tool version (in this case it is 12.4).
First we build the app using (after getting the simulator ID)
xcodebuild build-for-testing -workspace Example.xcworkspace -scheme ExampleUITests -derivedDataPath ./derivedData -destination 'platform=iOS Simulator,id=<simulator_id>'
Then we run the test using
xcodebuild test-without-building -workspace Example.xcworkspace -scheme ExampleUITests -enableCodeCoverage YES -destination 'platform=iOS Simulator,id=<simulator_id>' -derivedDataPath ./derivedData
All the UI tests run successfully but end up with the following statements when the test suite completes.
warning: <Path_to_derived_data>/Build/ProfileData/<Some_UUID>/<Filename>.profraw: Invalid instrumentation profile data (file header is corrupt)
error: No profiles could be merged.
P.S: This is not happening on my local machine. Only on the mac in the Jenkins ec2 instance.
We faced a similar issue. We were also using fastlane.
And the fix which worked for us was to ensure we delete any artifacts from the previous build. The situation you've described is quite similar to situation we faced. The first run for unit tests generates a few coverage artifacts, after which executing UI tests also generates coverage artifacts and then xcov/slather is unable to parse these artifacts.
Therefore, can you check if deleting the Logs/Test folder in derived data helps? If it doesn't try clearing derived data entirely and then check if that helps resolve the issue on CI.
See related threads on xcov

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)

Xcode 8 Build with Jenkins CI

I'm having issues with automated jenkins build on a mac pro using Xcode 8.1 with xcodebuild.
I would like my setup to:
Pull down code for git (working)
Archive (Archive fails)
Create .ipa
Deploy to TestFairy
My archive script is failing but still creating ProjectName-Daily.xcarchive file:
xcodebuild -workspace ProjectName.xcworkspace -scheme ProjectName-Daily -configuration Release clean archive -archivePath ~/ProjectName-Daily.xcarchive DEVELOPMENT_TEAM=1234567890
Fails with the following on the terminal with no description on error. I also tried -verbose and no luck
I then tried to build it manually and get a build succeeds with the following errors:
I then went to archive the build on Xcode and it worked just fine. Not sure why the script isn't working on the CI machine. Also tried the script on my personal macbook pro and it worked just fine.
Any thoughts?

Xcode Build for Profiling via Terminal

I'm trying to build my XCode project via the terminal. I'd like use Xcode's Product > Build for > Profiling option. So far I have:
xcodebuild -project "MyGame.xcodeproj" -target "MyGameEditor - Mac" -destination 'name=My Mac 64-bit' -configuration Profile
The project builds but not for profiling. I get an error that configuration 'Profile' does not exist.
Any help is appreciated.
What you are trying to sepcify with -configuration is the build configuration, not the build action. Unless you have added extra configurations to your project, you only have "Debug" and "Release" configurations.
What Xcode does when you tell it to profile is it builds the configuration that your scheme specifies to use when profiling, launches the simulator, installs the app, then launches Instruments.
So you need to do a similar thing with two command line calls, one to xcodebuild, one to instruments.
Some helpful links that should help you figure out what you need to do:
http://blog.manbolo.com/2013/04/09/launching-uiautomation-tests-in-command-line
Can the UI Automation instrument be run from the command line?
It is also worth noting that rather than specifying a target and configuration, you should just specify a scheme which provides both and other optional additional features.

Checking for Errors Running xcodebuild (Command Line) for 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 .

Resources