[英]How to change $(PRODUCT_BUNDLE_IDENTIFIER) in Xcode?
I am build different flavor of Flutter app with different Firebase environment (development and production). 我在不同的Firebase环境(开发和生产)下构建了Flutter应用程序的不同风格。 I need set different bundle ID for development and production in Xcode for iOS apps.
我需要为iOS应用程序的Xcode中的开发和生产设置不同的包ID。
I am use schemes to configure the different flavor (in Build Settings I add environment value for every configuration). 我使用方案来配置不同的样式(在“构建设置”中,为每个配置添加环境值)。
But I have big issue with change $(PRODUCT_BUNDLE_IDENTIFIER)
. 但是我对更改
$(PRODUCT_BUNDLE_IDENTIFIER)
有很大的疑问。 I need add suffix .development
to normal app id for development app id. 我需要在普通应用程序ID中添加后缀
.development
作为开发应用程序ID。
I have try follow this method (use User Defined Settings) and change info.plist
to get variable from User Defined Settings but it not work. 我已经尝试遵循此方法 (使用用户定义的设置)并更改
info.plist
以从用户定义的设置获取变量,但是它不起作用。
Error is: 错误是:
The operation couldn't be completed.
该操作无法完成。 Application “$(EXAMPLE_BUNDLE_ID)" is unknown to FrontBoard.
FrontBoard未知应用程序“ $(EXAMPLE_BUNDLE_ID)”。
So it seem when pass in User Defined Setting it is not interpolate correct. 因此,似乎在传递“用户定义的设置”时插值不正确。
I have also try mix method of add default PRODUCT_BUNDLE_IDENTIFIER
and User Defined Settings. 我也尝试添加默认
PRODUCT_BUNDLE_IDENTIFIER
和用户定义的设置的混合方法。 For example: com.example.app$(EXAMPLE_BUNDLE_ID)
where EXAMPLE_BUNDLE_ID
= .development
例如:
com.example.app$(EXAMPLE_BUNDLE_ID)
其中EXAMPLE_BUNDLE_ID
= .development
I also try reference User Defined Setting $(EXAMPLE_BUNDLE_ID)
by direct add it to Bundle Identifier in Target General tab under 'Identity'. 我也尝试通过直接将用户定义的设置
$(EXAMPLE_BUNDLE_ID)
添加到“目标常规”选项卡中“身份”下的捆绑包标识符中来引用它。 But this then change to : -- EXAMPLE_BUNDLE_ID-
但这会变为:
-- EXAMPLE_BUNDLE_ID-
I have also try in info.plist
use $(PRODUCT_BUNDLE_IDENTIFIER)$(EXAMPLE_BUNDLE_ID)
for Bundle Identifier value. 我也尝试在
info.plist
中将$(PRODUCT_BUNDLE_IDENTIFIER)$(EXAMPLE_BUNDLE_ID)
用作捆绑标识符值。 But this give similar error: 但这给出了类似的错误:
The operation couldn't be completed.
该操作无法完成。 Application “com.example.app$(EXAMPLE_BUNDLE_ID)" is unknown to FrontBoard.
FrontBoard未知应用程序“ com.example.app $(EXAMPLE_BUNDLE_ID)”。
Again this look like interpolation issue. 同样,这看起来像插值问题。
Anyone know solution? 有人知道解决方案吗? I have look but cannot find answer.
我看了但是找不到答案。
This easy for android because just use applicationIdSuffix ".development”
in productFlavors
. But I cannot find way like this for Xcode. 对于Android来说这很容易,因为只需在
productFlavors
使用applicationIdSuffix ".development”
,但是我无法为Xcode找到这种方式。
Do you need to have different package name
(Android) and bundle id
(iOS) because you need to use Firebase Auth
plugin? 因为需要使用
Firebase Auth
插件,您是否需要具有不同的package name
(Android)和bundle id
(iOS)?
In this case for iOS project you shold consider using PlistBuddy
and you could set it adding a Run Script
in your XCode build phases
like that 在这种情况下,对于iOS项目,您可以考虑使用
PlistBuddy
并且可以在XCode build phases
中将其设置为添加Run Script
。
if [ "${CONFIGURATION}" = "Debug" ]; then
/usr/libexec/PlistBuddy -c "Set :CFBundleIdentifier com.example.developmento.appName" "$PROJECT_DIR/Runner/Info.plist"
echo "Changed bundle id for developement $PROJECT_DIR/Runner/Info.plist"
else
echo "Nothing to do"
fi
Anyway if you don't use Firebase Auth
, you can have the same bundle id in different firebase projects. 无论如何,如果您不使用
Firebase Auth
,则可以在不同的firebase项目中使用相同的bundle id。
If you need then to differenziate firebase projects file between staging and production, you could have a look here: 然后,如果需要在登台和生产之间区分Firebase项目文件,可以在这里查看:
How to choose between development and production firebase project based on build flavours? 如何根据建筑风格在开发和生产火力基地项目之间进行选择?
UPDATE 更新
So following OP chat, knowing that he's following this tutorial to setup flutter flavors
I've tryed myself to see where we were stuck. 因此,在进行OP聊天之后,知道他正在按照本教程来设置
flutter flavors
所以我尝试了一下自己,看看我们遇到了什么问题。
Starting point is the following: 起点如下:
Firebase project
Firebase project
Firebase Auth
module (so the need to change the bundle id between projects) Firebase Auth
模块(因此需要在项目之间更改包ID) GoogleService-Info.plist
GoogleService-Info.plist
I start with Xcode bundle id
and GoogleService-Info.plist
set to production (just an option) 我首先将Xcode
bundle id
和GoogleService-Info.plist
设置为生产(只是一个选择)
Then I've save both GoogleServices-Info-staging.plist
and GoogleServices-Info-production.plist
save in my ios/Runner folder 然后,我将
GoogleServices-Info-staging.plist
和GoogleServices-Info-production.plist
保存在ios / Runner文件夹中
Then I setup this build script before the script for Compile Sources
然后我在
Compile Sources
脚本之前设置此生成脚本
# Type a script or drag a script file from your workspace to insert its path.
if [ "${CONFIGURATION}" == "Debug" ] || [ "${CONFIGURATION}" == "Debug-Runner-staging" ]; then
echo "Setting up staging firebase environment"
/usr/libexec/PlistBuddy -c "Set :CFBundleIdentifier com.example.staging.flutterAppAuthFlavours" "${PROJECT_DIR}/Runner/Info.plist"
cp -r "${PROJECT_DIR}/Runner/GoogleService-Info-staging.plist" "${PROJECT_DIR}/Runner/GoogleService-Info.plist"
echo "$(date) staging flavour - Configuration: ${CONFIGURATION}" > "${PROJECT_DIR}/environment.txt"
elif [ "${CONFIGURATION}" == "Debug-Runner-production" ]; then
echo "Setting up production firebase environment"
/usr/libexec/PlistBuddy -c "Set :CFBundleIdentifier com.example.flutterAppAuthFlavours" "${PROJECT_DIR}/Runner/Info.plist"
cp -r "${PROJECT_DIR}/Runner/GoogleService-Info-production.plist" "${PROJECT_DIR}/Runner/GoogleService-Info.plist"
echo "$(date) production flavour - Configuration: ${CONFIGURATION}" > "${PROJECT_DIR}/environment.txt"
fi
And I called it Setup Firebase Environment
(you can call it what you want) 我将其称为
Setup Firebase Environment
(您可以根据需要命名)
This script store also some logs (with timestamp) in a file called environment.txt
inside ios
folder in order to easy check what xcode build has done 该脚本还在
ios
文件夹内的名为environment.txt
的文件中存储了一些日志(带有时间戳),以便轻松检查xcode构建已完成
And now about Schemes
and Build Configurations
: 现在有关
Schemes
和Build Configurations
:
I've done two Build Configuration
that are the exact copy of my Debug Build Configuration
and I called them 我已经完成了两个
Build Configuration
,它们是我的Debug Build Configuration
的精确副本,我称它们为
Debug-Runner-staging
Debug-Runner-production
The rule of thumb is to name the build configurations as 'Debug-<your flavor>'
and you need to have a scheme for every flavors you have, so I have these: 经验
'Debug-<your flavor>'
构建配置命名为'Debug-<your flavor>'
,您需要针对每种风味都制定一个方案 ,因此我有以下几种:
Runner-staging
whose Run calls Debug-Runner-staging build configuration Runner-staging
其Run调用Debug-Runner-staging构建配置 Runner-production
whose Run calls Debug-Runner-production build configuration Runner-production
其Run调用Debug-Runner生产构建配置 So now if I call flutter run --flavor Debug-staging
I have a build that runs on my staging firebase project. 因此,现在如果我将
flutter run --flavor Debug-staging
称为我的构建,它将在我的暂存 firebase项目上运行。
and if I call flutter run --flavor Debug-production
I have a build that runs on my production firebase project. 如果我将其称为
flutter run --flavor Debug-production
,则可以在我的生产 firebase项目上运行一个构建。
UPDATE 2 更新2
Just for completness you could change bundle id also here: 仅出于完整性考虑,您还可以在此处更改包ID:
Anyway it seems that there's a strange behavior that once you build a flavour
a second time flutter
command build correctly the flavor but run the previos build flavor . 无论如何,似乎有一个奇怪的行为 ,那就是一旦您构建了
flavour
,第二次flutter
命令就可以正确地构建该风味,但是运行previos构建风味 。
As building with XCode
and switching with schemes all works as expected (even the run of the right application) I guess that this could be a flutter command issue. 使用
XCode
构建并使用方案进行切换时,所有的工作都可以按预期进行(甚至运行正确的应用程序),我想这可能是一个不稳定的命令问题。 So I suggest you trying file an issue here linking also this SO question/answer. 因此,我建议您尝试在此处提出一个问题,并将此问题/答案也链接在一起。
UPDATE 3 更新3
After a bit of intel I've found that flutter tools
set the applicaiton launching environment before building the project. 经过一番了解,我发现在构建项目之前,
flutter tools
设置应用程序启动环境。 So when we change CFBundleIdentifier
inside Info.plist
the first time, the second time we launch flutter run
it takes the previous modified value and try launching this bundle id while during build we are changing it because we are building a different variant. 因此,当我们第一次在
Info.plist
更改CFBundleIdentifier
时,第二次启动flutter run
它将采用先前修改的值,并在构建期间尝试启动此bundle id,因为我们正在构建其他变量,因此我们对其进行了更改。
A possible solution could be to launch a script that change the CFBundleIdentifier
inside Info.plist
before calling fluetter run
. 一个可能的解决方案是启动一个脚本 ,该脚本在调用
fluetter run
之前更改Info.plist
的CFBundleIdentifier
。
For example starting with a Info.plist
with a production bundle id of com.example.flutterAppAuthFlavours
we could do something like that 例如,从
Info.plist
开始,其生产捆绑包ID为com.example.flutterAppAuthFlavours
我们可以执行类似的操作
Here I've used sed
command just to think different, but you could call always our belowed PlistBuddy
to make the change before calling flutter run
. 在这里,我使用
sed
命令只是为了有所不同,但是您可以始终调用下面的PlistBuddy
进行更改,然后再调用flutter run
。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.