I have legacy code that relies on pointers being 32-bit and want to use xCodeBuild to build that code from command line. This doesn't work for some reason. Here's the command I use:
xcodebuild -configuration Debug -arch i386
-workspace MyProject.xcworkspace -scheme MyLib
here's the output I get
[BEROR]No architectures to compile for
(ONLY_ACTIVE_ARCH=YES, active arch=x86_64, VALID_ARCHS=i386).
Clearly it's trying to build x86_64 code and failing miserably since I only enabled i386 from VALID_ARCHS in xCode project settings.
Is there a way to make it understand I don't want a 64-bit library?
You have to set the ONLY_ACTIVE_ARCH to NO if you want xcodebuild to use the ARCHS parameters. By passing these parameters, you can force the proper architecture.
xcodebuild ARCHS=i386 ONLY_ACTIVE_ARCH=NO -configuration Debug -workspace MyProject.xcworkspace -scheme MyLib
See this reference for details.
Build Active Architecture Only(ONLY_ACTIVE_ARCH)
xcodebuild ONLY_ACTIVE_ARCH...
//or
Build Settings -> Build Active Architecture Only -> ONLY_ACTIVE_ARCH
YES - build binary with a single architecture for a connected device
NO - build binary for a specific -arch(valid architectures aka VALID_ARCHS) if it was specified or for all the architectures in other cases
The recommendation is to use Yes for Debug (to save on build time) and No for Release build.
Note: it is safe to run on simulator
To check the version use lipo -info[About]
Related
In iOS Framework project, we have Obj C and Swift code, we build a .framework and distribute through our code repo for other app projects to integrate.
The build we generate is an universal framework, so that it works on device as well as simulator.
Recently in Xcode 12 iOS 14, the build generation failed as we use lipo to combine the frameworks for simulator and device architectures as shown here iOS 14, lipo error while creating library for both device and simulator, as suggested in the answer, excluded the arm64 arch from simulator build then the lipo cmd worked and Framework got built, following is the build command(s) we use
simulator:
MySDK -target MySDK ONLY_ACTIVE_ARCH=NO -configuration ${CONFIGURATION} -sdk iphonesimulator BUILD_DIR="${BUILD_DIR}" BUILD_ROOT="${BUILD_ROOT}" OBJROOT="${OBJROOT}/DependentBuilds" EXCLUDED_ARCHS="arm64"
device:
MySDK -target MySDK ONLY_ACTIVE_ARCH=NO -configuration ${CONFIGURATION} -sdk iphoneos BUILD_DIR="${BUILD_DIR}" BUILD_ROOT="${BUILD_ROOT}" OBJROOT="${OBJROOT}/DependentBuilds"
Now when this .framework is integrated with other app project(MyProject) using cocoapods. Upon building the project with below command gives following errors
xcodebuild install -scheme MyProject -workspace MyProject.xcworkspace -destination 'platform=iOS Simulator,name=iPhone 8'
Errors
** INSTALL FAILED **
The following build commands failed:
CompileSwift normal x86_64
CompileSwift normal x86_64
CompileSwiftSources normal x86_64 com.apple.xcode.tools.swift.compiler
CompileSwift normal x86_64
/Users/path/to/MyProject/Pods/MySDK/MySDK.framework/Modules/MySDK.swiftmodule/x86_64-apple-ios-simulator.swiftinterface:21:96: error: 'someStruct' is not a member type of 'MySDK'
#objc public func someMethod(some: args) -> Swift.void)
Note: The project with MySDK(Framework) integrated works fine we run on a device or simulator through Xcode, but when the above command is run it is giving these errors
Recently I'm trying to use Jenkins for Oclint statically analyzing objective-c sources.
So I followed the guide on the Oclint.org, especially this page oclint_guide_with_Jenkins
And then, I run the build job on the Jenkins.
But the job was always failed with below logs.
(Extra logs were just about svn check-out)
+ oclint-json-compilation-database -- -report-type pmd -o oclint.xml -rc=LONG_LINE=120
Error: compile_commands.json not found at current location.
Can anyone show me the way to solve this problem? :)
You need to generate the compile_commands.json , I am not sure if xcodebuild can do that , but you can use Facebook's xctool : https://github.com/facebook/xctool which is a wrapper over xcodebuild and provides different reporters.
You can use Homebrew to install xctool as well, once install use the following commands to generate compile_commands.json and then run the oclint command.
If you have a workspace file :
xctool -scheme $scheme -workspace $workspaceFile -sdk iphonesimulator ARCHS=i386 VALID_ARCHS=i386 CURRENT_ARCH=i386 ONLY_ACTIVE_ARCH=NO -reporter json-compilation-database:compile_commands.json build
If you have project file :
xctool -scheme $scheme -project $projectFile -sdk iphonesimulator ARCHS=i386 VALID_ARCHS=i386 CURRENT_ARCH=i386 ONLY_ACTIVE_ARCH=NO -reporter json-compilation-database:compile_commands.json build
I have a strange issue when trying to compile a static library using xcodebuild.
Project's configuration is:
ARCHS = $(ARCHS_STANDARD)
VALID_ARCHS = $ARCHS
It's executed using Xcode 5.1.1.
Now comes the weird part - the project built on machines connected to Jenkins produces fat libary with all 5 architectures (armv7 armv7s arm64, i386, x86_64), but when a build is launched on my (64bit) Mac I'm getting only four - x86_64 is missing. No code change, clean repo, exactly the same build routine.
I wonder what may be causing that difference. I guess it might be some kind of an environment setup on my side, but have no idea what it might be. Project configuration is not under suspicion - it creates proper fat library on a different machine.
I'd be thankful for your advices.
EDIT: No error is thrown either. xcodebuild behaves just like that architecture is not specified - compiles iphonesimulator build just for i386.
Also worth noticing - Xcode creates all architectures, only xcodebuild executed from command line has issues.
Try adding the -destination flag to your xcodebuild command.
xcodebuild -workspace MyWorkspace.xcworkspace -scheme MyScheme -destination 'platform=OS X,arch=x86_64' test
The above is an example from the xcodebuild manual page.
I had a similar issue where I wanted xcodebuild to make an i386 build for simulator and continued to create Armv7 until I added that flag to my command.
I am trying to solve a cryptic puzzle that I really appreciate the explanation for as this will help me understand the tools and be confident about what i do.
I came across the puzzle when cranking up xcodebuild commandline to build my iPhone app. I found it to reject '-sdk iphonesimulator6.0" with this message:
"No architectures to compile for (ARCHS=i386, VALID_ARCHS=armv7)."
I then saw my VALID_ARCHS were set to armv7 and that appeared to explain why xcodebuild refused to build for simulator (which i led myself to believe was intel).
But how on earth does my XCode IDE go around it and manages to build for simulator (which it does)?
Changing VALID_ARCHS to:
VALID_ARCHS = "$(ARCHS_STANDARD_32_BIT)";(which expands to armv7 and armv7a)
or
VALID_ARCHS = armv7 i386
Seemed to have satisfied xcodebuild enough to agree to build for simulator. Mind you, the first case still doesn't list i386! And I must conclude i386 becomes, in certain conditions, implicit. Can anyone confirm and/or expand on any of this?
When xcode build on i386 it changes these variables, you can witness this in xcode Log navigator...
These are the Variables xcode manipulate in order to allow running on i386
VALID_ARCHS=i386
ARCHS=i386
You can do the same by invoking xcodebuild command in the following manner:
xcrun xcodebuild VALID_ARCHS=i386 ARCHS=i386 ONLY_ACTIVE_ARCH=NO -arch i386 -sdk iphonesimulator7.1 -configuration Debug
Running in Xcode is correctly, but when I want to use command line with
$ /usr/bin/xcodebuild -scheme projectA -workspace projectA.xcworkspace -configuration Debug clean build
And come up with the following.
=== BUILD NATIVE TARGET projectA OF PROJECT projectA WITH CONFIGURATION Debug ===
Check dependencies
No architectures to compile for (ONLY_ACTIVE_ARCH=YES, active arch=x86_64, VALID_ARCHS=armv7 armv7s).
In Build Settings are:
Architectures: Starndard (armv7, armv7s)
Base SDK: Latest iOS (iOS 6.0)
Build Active Architecture Only: Debug Yes, Release No
Valid Architectures: armv7 armv7s
After I change Build Active Architecture Only = No, then the build was BUILD SUCCEEDED.
What is the suggestion setting for this situation, to build success under commend line mode? Thanks.
You can set the "Build Active Architecture Only" and "Archs" values from command line itself. We set ARCHS="armv7 armv7s" ONLY_ACTIVE_ARCH=NO.
Eg
/usr/bin/xcodebuild ARCHS="armv7 armv7s" ONLY_ACTIVE_ARCH=NO -workspace -scheme ......
This will free you from manually changing the values in your project settings.
In my case it was empty cell in the 'valid architectures' on the target level which resulted in empty 'resolved' cell.
That lead to empty 'valid architectures' parameter and at the end linker error.