How to get the Xcode build directory?
Solution 1
If you need the build directory path for use within an Xcode build script (Build Phases > Run Script
), then use the following variable:
$TARGET_BUILD_DIR
For an exhaustive list of all variables exposed by Xcode in build scripts, follow this answer:
$ xcodebuild -project myProject.xcodeproj -target "myTarget" -showBuildSettings
Solution 2
Building up on Daniel Jones answer above, to get the BUILD_DIR of a workspace, you should run:
xcodebuild -workspace ios/myApp.xcworkspace -scheme myApp
-showBuildSettings | grep BUILD_DIR
example of response:
BUILD_DIR = /Users/Olivier/Library/Developer/Xcode/DerivedData/myApp-ceetrcnutlegngflgvvfjaaaycrc/Build/Products
naz
Updated on June 17, 2022Comments
-
naz almost 2 years
How do I get the URL or url string to the build directory of a workspace or a project? I don't want to set it myself to know what it is instead I want to know the default set by Xcode.
How to get the directory programmatically?
-
Sergio about 9 yearsWhat is the purpose of programmatically accessing build dir for mobile app? It is more probably that you need info about some path inside bundle app.
-
naz about 9 yearsTo access compiled resources. Anyway i figured out a better solution. I created a bundle target and shared it with the main app.
-
Sergio about 9 yearsThat is not better solution, that is the only solution. Getting build directory path programmatically to access compiled resources is not something that can work. It only makes sense to use it in the build scripts.
-
naz about 9 yearsNot a solution to my question I agree. I have several projects in a workspace and I want to access the resources of another project/framework. I now can do that. I know your answer the clue was when I said I don't want to set the build path which means I know where to get it manually. Thanks for the help.