Xcode 7: changing product bundle identifier
Asked Answered
C

6

52

I'm setting up Jenkins to automate the build process. In particular, for my needs, I'd like to be able to set different bundle identifiers.

I'm using the Xcode Jenkins plugin to set the bundle identifier:

Jenkins Xcode plugin - Code signing & OS X keychain options

The problem is that this will change the bundle identifier in the Info.plist file and in MyTarget > General > Bundle Identifier. But it won't change the bundle identifier in Build Settings > Packaging > Product Bundle Identifier.

The same thing happens if I do it manually. I create a new project in Xcode 7. By default, the three values are:

Info plist beforetarget general beforepackaging

When I change the value in the Info.plist file like this:

Info plist changed

The other two value will be:

target general after packaging after

So how you can see the value in Build Settings is not changing. If I'm in Xcode I change that value manually, but if I'm building the project in Jenkins this is a bis issue.

Anyone encountered the same problem? How do you tackle it?

Thanks!

Certain answered 30/9, 2015 at 9:13 Comment(2)
Encountering the same issue since today. I use plistbuddy shell command to change the bundle identifier. It changes the info.plist but doesn't change the bundle identifier inside the build settings in xCode.Callimachus
Big thanx, didn't realize it has to be changed in 3 places!Olaolaf
A
37

Faced the same problem.

The PRODUCT_BUNDLE_IDENTIFIER is a variable in your project.pbxproj file. Change that to whatever you want and it will reflect both in your Info.plist as well as the project settings.

Alysaalyse answered 30/9, 2015 at 14:8 Comment(6)
so I should pass PRODUCT_BUNDLE_IDENTIFIER=$CB_APP_ID to xcodebuild, right?Certain
that worked. For the record, I'm passing PRODUCT_BUNDLE_IDENTIFIER=$CB_APP_ID to xcodebuild command.Certain
how you and where you added this PRODUCT_BUNDLE_IDENTIFIER=$CB_APP_ID?Plutonium
I have added in Custom xcodebuild arguments like : PRODUCT_BUNDLE_IDENTIFIER = 'com.w.test' but it is not changing in build settings :(Plutonium
@LucaTorella can you please helpPlutonium
yes it's just an extra xcodebuild argument. xcodebuild PRODUCT_BUNDLE_IDENTIFIER="com.w.test"Certain
M
30

udit's answer is correct. The best practice is in plist set Bundle ID value as $PRODUCT_BUNDLE_IDENTIFIER. Then in Build Settings, use different configurations(Debug, Release .etc) to set up different bundle ID by required: enter image description here

You don't need xCode plugin to change bundle id anymore but need to specify configuration in there.

enter image description here

Malley answered 2/10, 2015 at 14:40 Comment(5)
in most of the cases that's the best practice, I agree. But I want all these parameters to be customizable. Basically I want to have a web interface were the customer can add p12 file, mobile provisioning profile, bundle identifier, and they'll get a customized .ipaCertain
@Aoke Li- This seems like a better approach. I just have one doubt with this. When I use different bundle identifiers depending on build configurations, which value will reflect in Xcode summary general pane?Enright
@Rashmi Ranjan mallick- So after you setup your config file and build locally, you will notice the bundle ID in general pane also got update. And since there is nothing be injected in jekins build time for this area, the slave will work exactly like your dev machine.Malley
@AokeLi- Actually, I am not using Jenkins. I am building manually using Archive function. My scenario is- I want to use different bundle IDs for different configuration (as you demonstrated).Enright
This fails if you’re building 3rd party dependencies in your project, beacause all modules must agree on the build configurations. Most only support default ones Debug and Release. :/Miltiades
C
15

Refer to this for a simple solution to replace $PRODUCT_BUNDLE_IDENTIFIER using shell command like -

sed -i '' 's/com.example.oldbundleid/com.example.newbundleid/g' project.pbxproj

You can pass your variables accordingly using Jenkins/Shell.

Alternative approach to do this is using mod-pbxproj.

python -m mod_pbxproj -b -af PRODUCT_BUNDLE_IDENTIFIER=com.example.newbundleid -rf PRODUCT_BUNDLE_IDENTIFIER=com.example.oldbundleid project.pbxproj All

//edit

Old bundle id can be fetched by -

awk -F '=' '/PRODUCT_BUNDLE_IDENTIFIER/ {print $2; exit}' project.pbxproj

This can be stored in a string variable and used in place of com.example.oldbundleid

Callimachus answered 2/10, 2015 at 17:28 Comment(2)
It would be nicer with a solution that you didn't need to know the old bundle identifier.Unthread
Updated my solution. It fetches the stored bundle ID value from .pbxproj to replaced. @UnthreadCallimachus
K
3

For xcode 8.x

Changing app name under Targets > your_app_name - Info > addition of a new property key does not make complete changes of app name everywhere throughout the project.

When you do this, your project runs smoothly in your mac alone (i.e., in the system which you used to do these changes, as all your property keys & identities will be saved in your system). When you try to use your project in another system, yo'll get this weird error that your project is missing if in case your using pods in your project.

So, to overcome this, all you gotta do some changes in Build settings, leaving General tab and Info tab untouched.

Under Targets > Build settings, scroll to Packaging.

Change your Product name to the desired name & Product bundle identifier to the new one. Once you do this, automatically your project display name & bundle id changes to the new one in General tab.

Kleist answered 21/2, 2017 at 4:49 Comment(1)
I'm using XCode 9 and this doesn't work. App explodes when firing it up in Simulator.Glamour
D
2

If you use bundle id suffixes, don't set the Product Bundle Identifier on General tab of the Target Settings.

Set it on the Build Settings tab.

For example:

com.company.app${BUNDLE_ID_SUFFIX}
Dyun answered 26/9, 2019 at 16:18 Comment(0)
D
0

You can also see the data in plain text by going to Targets and select "Levels" which will show a column including the Bundle Identifier.

enter image description here

Dunstan answered 31/10, 2018 at 14:9 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.