50

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!

Luca Torella
  • 7,974
  • 4
  • 38
  • 48
  • 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. – Sarthak Singhal Sep 30 '15 at 16:43
  • Big thanx, didn't realize it has to be changed in 3 places! – JOM Dec 08 '17 at 06:16

6 Answers6

36

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.

Bruno Bieri
  • 9,724
  • 11
  • 63
  • 92
udit gupta
  • 786
  • 1
  • 6
  • 5
29

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

Community
  • 1
  • 1
Aoke Li
  • 499
  • 3
  • 16
  • 2
    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 .ipa – Luca Torella Oct 02 '15 at 16:51
  • 1
    @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? – Rashmi Ranjan mallick Oct 18 '16 at 13:10
  • @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. – Aoke Li Oct 18 '16 at 13:32
  • @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). – Rashmi Ranjan mallick Oct 18 '16 at 13:40
  • 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. :/ – quickthyme Jul 11 '19 at 23:15
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

Community
  • 1
  • 1
Sarthak Singhal
  • 665
  • 2
  • 10
  • 26
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.

user6502515
  • 143
  • 11
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}
Denis Kutlubaev
  • 15,320
  • 6
  • 84
  • 70
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