I need to build an Xcode project within a Today Extension by 'xcodebuild'. The bundle is of the main target is com.myapp, while the bundle id of the extension is com.myapp.todayextension. I'd like to pass both the bundle id's as parameters of xcodebuild: I tried to replace the bundle id's in the xcode project by custom environment variables (e.g. ${MAIN_TARGET_BUNDLEID} and ${EXTENSION_BUNDLEID}) but the xcodebuild fails. Could you please help me with the correct syntax of xcodebuild command ? Thanks.
Better too late than never; We can't directly use an environment variable in General
tab, you will need to go into Build Settings
tab, then set Product Bundle Identifier
to your environment-variable, for example $(PRODUCT_NAME)
.
See below for another approach.
How to load prefix set by parent project?
- Create an
.xcconfig
file (with content like example). - Set up the
.xcconfig
file in project settings'sInfo
tab (not target'sInfo
tab). - In target's
Build Settings
tab, ensurePRODUCT_BUNDLE_IDENTIFIER
is not bold (click it and pressdelete
).
But Podfile
users should see also: How to make Xcode use multiple xcconfig files?
Example
My extension.xcconfig
file (which is in MyApp/MyLib/MyExtension
directory), looks something like:
// Below loads `MyApp/config/mylib.xcconfig` file.
#include "../../config/mylib.xcconfig"
PRODUCT_BUNDLE_IDENTIFIER = $(MYLIB_BUNDLE_PREFIX).$(PRODUCT_NAME)
Note that:
- You want to use some environment as prefix, but above I use
PRODUCT_NAME
as suffix (simply edit as you wish).- The
mylib.xcconfig
file setsMYLIB_BUNDLE_PREFIX
, and is outside of myMyLib.xcodeproj
file's directory (so is in parent project'sconfig
directory, I describe in MyLib'sREADME.md
that users should create it there).- So, beside showing my
#include
approache, I try to introduce use of environment-variable.
That's called PRODUCT_BUNDLE_IDENTIFIER
, as per the documentation.
A string that uniquely identifies the bundle. The string should be in reverse DNS format using only alphanumeric characters (A-Z, a-z, 0-9), the dot (.), and the hyphen (-). This value is used as the CFBundleIdentifier in the Info.plist of the built bundle.
© 2022 - 2024 — McMap. All rights reserved.