Choose or get xcodebuild destination directory for app - ios

Is there a way I can choose the destination folder (directory) for when I build an iOS app via command line using xcodebuild?
Right now I am using a command like
xcodebuild -sdk iphonesimulator -workspace /<path_to_project>/ios-app/CompanyName-iOS.xcworkspace -scheme AppName -configuration Debug RUN_APPLICATION_TESTS_WITH_IOS_SIM=YES ONLY_ACTIVE_ARCH=NO clean build 2>&1
In the output I see something like
GenerateDSYMFile /Users/<username>/Library/Developer/Xcode/DerivedData/CompanyName-iOS-fcvhojqctgtmvgdaavahmjutbfyy/Build/Products/Debug-iphonesimulator/AppNAme.app.dSYM
Is there a way I could get this location where the app is output to or even specify where I would rather have the app be sent to? I need access to the app to run Appium selenium tests and just having a build execute and run tests is not helpful. Also trying to incorporate jenkins into the mix and need to have commands to fully automate the process

Set the CONFIGURATION_BUILD_DIR Build Setting to be the directory you want.
https://developer.apple.com/library/mac/documentation/DeveloperTools/Reference/XcodeBuildSettingRef/1-Build_Setting_Reference/build_setting_ref.html#//apple_ref/doc/uid/TP40003931-CH3-SW40
So in your example:
xcodebuild ...cut... CONFIGURATION_BUILD_DIR=<desired dir> ...cut...

use -derivedDataPath path to get compiled output onto specific folder.
xcodebuild -scheme xxx -workspace xxx.xcworkspace ONLY_ACTIVE_ARCH=NO -sdk iphonesimulator -configuration Debug -derivedDataPath ./build build
https://developer.apple.com/library/mac/documentation/Darwin/Reference/ManPages/man1/xcodebuild.1.html

Related

xcodebuild manually building framework in run-script and follow same destination

I have a framework that I need to build manually as a part of my run-script in xcode.
How can I copy the build setting from the current project when building it?
xcodebuild
-project "$PROJECT_DIR/myProject/MyProject.xcodeproj"
-scheme MyProject
-configuration "$MY_PROJECT_CONFIGURATION"
CONFIGURATION_BUILD_DIR="$APP_BUILD_DIR"
build
I'm specifically having problem matching -destination. Is there a way to get the -destination used to build the current project and pass it to xcodebuild
Xcode offers this as a Environmental Variable:
build_dir=${BUILD_DIR}
//use it
... -destination $build_dir ...
This answer shows how to get all Environmental Variables.

Aggregate Script for iOS framework with Bitcode

I have a iOS framework and I want to generate a universal target full bitcode support, right now I create an aggregate script and I'm using the xcodebuild command to generate the different versions (device and simulator) but when we try to generate the archive we always receive the error because the library doesn't have full bitcode support.
This is how I'm using the xcodebuild command:
xcodebuild -fembed-bitcode -project ${PROJECT_NAME}.xcodeproj -sdk iphonesimulator -configuration ${CONFIGURATION} clean build CONFIGURATION_BUILD_DIR=${BUILD_DIR}/${CONFIGURATION}-iphonesimulator 2>&1
xcodebuild -fembed-bitcode -project ${PROJECT_NAME}.xcodeproj -sdk iphoneos -configuration ${CONFIGURATION} clean build CONFIGURATION_BUILD_DIR=${BUILD_DIR}/${CONFIGURATION}-iphoneos 2>&1
At the end the only way that I found to achieve this is first, generating the device build with Product -> Archive (Make sure to select on "Skip Installs" to NO on "Build Settings", to get the device framework) then create a package manually using the lipo command using the two builds: the Device's framework and the Simulator's framework.
The bitcode is only generated when you use the Archive command, if you use a build command Xcode won't generate the bitcode

Terminal Command build xcode project for 64 bit with all other also

I am using below command :
xcodebuild -project $PROJECT_NAME.xcodeproj -scheme $PROJECT_NAME -sdk iphonesimulator -configuration Debug
xcodebuild -project $PROJECT_NAME.xcodeproj -scheme $PROJECT_NAME -sdk iphoneos -configuration Debug
for building the application it's working but I need to build our application with iphone/ipad retina 64 bit but it' not working.
for combining
lipo -create "${WS_DIR}/Build/Debug-iphoneos/libRPCCore.a" "${WS_DIR}/Build/Debug-iphonesimulator/libCore.a" -output "${WS_DIR}/Build/RPCLib/libCore.a"
I am not able to build the application for ipad/ipahone retina 64 bit application using terminal command. please help to create the build script.
I suspect this is because you have Build Active Architecture Only set for Debug mode, which is the default setting I believe. This is because there is no need to build for all architectures during debugging as the build is expected to run only on the device being used for debugging.
This is normally turned off for release and you can test this from the command line by using -configuration Release.
BTW I don't believe you need to specify the -sdk option to xcodebuild as the build settings should have that covered.

Specify precompiled headers directory with xctool

I have an Xcode workspace with CocoaPods that I'm trying to build using xctool on travis. Here's the command that I'm using to do the build:
xctool -workspace MyApp.xcworkspace -scheme MyApp -sdk iphoneos -configuration Release SYMROOT=$PWD/build OBJROOT=$PWD/build ONLY_ACTIVE_ARCH=NO
This successfully builds the static libraries for each CocoaPod and the final app and dSYM into the $PWD/build directory, but the precompiled headers are still placed in DerivedData. I need them to be built into the $PWD/build directory for caching. Is there any way to specify where the precompiled headers are built to?
Thanks.
Figured it out. I needed to add SHARED_PRECOMPS_DIR=$PWD/build onto the xctool command.

Why won't my build phase scripts be executed when creating an IPA from command line?

Question - short version:
Why won't my build phase scripts be executed when creating an IPA from the command line?
When I'm running xcodebuild to create an IPA the predefined build phase scripts does not get executed. Why is that?
Question - lengthy version:
I have a workspace with a scheme I want to create an IPA out of from command line.
This works fine except for one thing; I have two scripts in the build phases of the target that is used to put the correct app version (CFBundleShortVersionString) and the correct svn revision number (CFBundleVersion). These to scripts works fine when archiving from xcode but for some reason they do not get run when archiving from command line.
First of all why is that?
Here are the scripts that are working (if archiving form xCode)
When archiving and creating the IPA from the command line I do (the essentials)
# Building
xcodebuild ARCHS="armv7 armv7s" ONLY_ACTIVE_ARCH=NO -workspace MyWorkspace.xcworkspace/ -scheme MyScheme CONFIGURATION_BUILD_DIR=${PROJECT_BUILD_DIR} -configuration Release clean build
# Creating IPA
/usr/bin/xcrun -sdk iphoneos PackageApplication -v "${PROJECT_BUILD_DIR}/${APPLICATION_NAME}.app" -o "${IPA_OUTPUT_PATH}/${APPLICATION_NAME}.ipa"
It works and creates an IPA but none of the build phase scripts gets executed leaving both the revision number and version number untouched.
All suggestions are appreciated!
UPDATE DUE TO BDASH's ANSWER
Instead of making a clean build I make an install as
xcodebuild install ARCHS="armv7 armv7s" ONLY_ACTIVE_ARCH=NO -workspace MyWorkspace.xcworkspace/ -scheme MyScheme CONFIGURATION_BUILD_DIR=${PROJECT_BUILD_DIR} -configuration Release
The predefined script will IN FACT be executed (can be seen in the project version number) with no errors during the install. However the created IPA will have a size of ~300 bytes (instead of ~10MB) and cannot be installed on a device.
Building the app before installing it, i.e.
# Building
xcodebuild clean build ARCHS="armv7 armv7s" ONLY_ACTIVE_ARCH=NO -workspace MyWorkspace.xcworkspace/ -scheme MyScheme CONFIGURATION_BUILD_DIR=${PROJECT_BUILD_DIR} -configuration Release
# Installing
xcodebuild install ARCHS="armv7 armv7s" ONLY_ACTIVE_ARCH=NO -workspace MyWorkspace.xcworkspace/ -scheme MyScheme CONFIGURATION_BUILD_DIR=${PROJECT_BUILD_DIR} -configuration Release
and then creating the IPA will result in an IPA with executed version script and of correct size BUT it is not possible installing it on a device. Trying to put it on a device will give an error message saying
"The program "MyApp" was not installed on you iPhone device "My Device" because an unknown error has occurred."
You have "Run script only when installing" checked for at least one of the script phases. That phase won't be run when using the build action to xcodebuild, only if using the install action.

Resources