Xcode 7:更改产品包标识符

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/32862253/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-08 18:12:32  来源:igfitidea点击:

Xcode 7: changing product bundle identifier

xcodejenkinsjenkins-pluginsxcode7bundle-identifier

提问by Luca Torella

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.

我正在设置 Jenkins 来自动化构建过程。特别是,根据我的需要,我希望能够设置不同的包标识符。

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

我正在使用 Xcode Jenkins 插件来设置包标识符:

Jenkins Xcode plugin - Code signing & OS X keychain options

Jenkins Xcode 插件 - 代码签名和 OS X 钥匙串选项

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.

问题是这将更改 Info.plist 文件和 MyTarget > General > Bundle Identifier 中的包标识符。但它不会更改 Build Settings > Packaging > Product Bundle Identifier 中的 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:

如果我手动执行,也会发生同样的事情。我在 Xcode 7 中创建了一个新项目。默认情况下,三个值是:

Info plist beforetarget general beforepackaging

之前的信息列表目标将军之前包装

When I change the value in the Info.plistfile like this:

当我Info.plist像这样更改文件中的值时:

Info plist changed

信息 plist 已更改

The other two value will be:

另外两个值将是:

target general afterpackaging 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.

因此,您如何在“构建设置”中查看值并没有改变。如果我在 Xcode 中,我会手动更改该值,但是如果我在 Jenkins 中构建项目,这是一个 bis 问题。

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

有人遇到过同样的问题吗?你如何解决它?

Thanks!

谢谢!

采纳答案by udit gupta

Faced the same problem.

面临同样的问题。

The PRODUCT_BUNDLE_IDENTIFIERis a variable in your project.pbxprojfile. Change that to whatever you want and it will reflect both in your Info.plistas well as the project settings.

PRODUCT_BUNDLE_IDENTIFIER是你的一个变量project.pbxproj文件。将其更改为您想要的任何内容,它将反映在您Info.plist和项目设置中。

回答by Aoke Li

udit's answeris 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

审计的答案是正确的。最佳实践是在 plist 中将 Bundle ID 值设置为 $PRODUCT_BUNDLE_IDENTIFIER。然后在 Build Settings 中,使用不同的配置(Debug、Release .etc)根据需要设置不同的 bundle ID: 在此处输入图片说明

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

您不再需要 xCode 插件来更改捆绑包 ID,但需要在其中指定配置。

enter image description here

在此处输入图片说明

回答by Sarthak Singhal

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

请参阅以获取使用 shell 命令替换 $PRODUCT_BUNDLE_IDENTIFIER 的简单解决方案,例如 -

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

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

You can pass your variables accordingly using Jenkins/Shell.

您可以使用 Jenkins/Shell 相应地传递您的变量。

Alternative approach to do this is using mod-pbxproj.

执行此操作的替代方法是使用mod-pbxproj

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

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 -

可以通过以下方式获取旧包 ID -

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

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

这可以存储在字符串变量中并代替 com.example.oldbundleid

回答by user6502515

For xcode 8.x

对于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 everywherethroughout the project.

在 Targets > your_app_name - Info > 添加新的属性键下更改应用程序名称不会在整个项目的任何地方完全更改应用程序名称

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.

当您这样做时,您的项目可以单独在您的 mac 中顺利运行(即,在您曾经进行这些更改的系统中,因为您的所有属性键和身份都将保存在您的系统中)。当您尝试在另一个系统中使用您的项目时,如果您在项目中使用 pod,您将收到这个奇怪的错误,即您的项目丢失了。

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

因此,要克服这个问题,您只需在 Build settings 中进行一些更改,同时保持 General 选项卡和 Info 选项卡不变。

Under Targets > Build settings, scroll to Packaging.

Targets > Build settings 下,滚动到Packaging

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

将您的产品名称更改为所需的名称,将产品包标识符更改为新名称。完成此操作后,您的项目显示名称和包 ID 会自动更改为常规选项卡中的新名称。

回答by Ron AndKim Stengel

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

在此处输入图片说明

回答by Denis Kutlubaev

If you use bundle id suffixes, don't set the Product Bundle Identifieron Generaltab of the Target Settings.

如果您使用的bundle id suffixes,不设置Product Bundle IdentifierGeneral的标签Target Settings

Set it on the Build Settingstab.

将其设置在Build Settings选项卡上。

For example:

例如:

com.company.app${BUNDLE_ID_SUFFIX}