How can I build a specific architecture using xcodebuild?

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.


xcodebuild 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(it save a build time) and No for Release build.

enter image description here

Note: it is safety to run on simulator

To check the version use lipo -info[About]