您是否需要使用不同的package name (Android) 和bundle id (iOS),因为您需要使用Firebase Auth 插件?
在这种情况下,对于 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
无论如何,如果你不使用Firebase Auth,你可以在不同的firebase项目中拥有相同的bundle id。
如果您需要在 staging 和 production 之间区分 firebase 项目文件,您可以在这里查看:
How to choose between development and production firebase project based on build flavours?
更新
所以跟随 OP 聊天,知道他在关注这个 tutorial 来设置 flutter flavors 我已经尝试自己看看我们卡在哪里了。
起点如下:
-
两个
Firebase project
- 使用
Firebase Auth模块(所以项目之间需要改变bundle id)
- 当然还有两个不同的
GoogleService-Info.plist
我首先将 Xcode bundle id 和 GoogleService-Info.plist 设置为生产(只是一个选项)
然后我将 GoogleServices-Info-staging.plist 和 GoogleServices-Info-production.plist 都保存在我的 ios/Runner 文件夹中
然后我在 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
我叫它Setup Firebase Environment(你可以随便叫它)
此脚本还将一些日志(带有时间戳)存储在 ios 文件夹内名为 environment.txt 的文件中,以便轻松检查 xcode 构建完成了什么
现在关于Schemes 和Build Configurations:
我已经完成了两个 Build Configuration,它们与我的Debug Build Configuration 完全相同,我称它们为
Debug-Runner-staging
Debug-Runner-production
经验法则是将构建配置命名为'Debug-<your flavor>',并且您需要为您拥有的每一种风格制定一个方案,所以我有这些:
-
Runner-staging 其 Run 调用 Debug-Runner-staging 构建配置
-
Runner-production 其 Run 调用 Debug-Runner-production 构建配置
所以现在如果我打电话给flutter run --flavor Debug-staging,我有一个在我的 staging firebase 项目上运行的构建。
如果我打电话给flutter run --flavor Debug-production,我有一个在我的生产 firebase 项目上运行的构建。
更新 2
为了完整起见,您也可以在此处更改捆绑包 ID:
无论如何,似乎有一个奇怪的行为,一旦你第二次构建flavourflutter 命令正确构建风味但运行previos 构建风味。
随着使用XCode 构建并使用方案切换,所有工作都按预期工作(即使是正确的应用程序的运行)我猜这可能是一个颤动的命令问题。所以我建议你尝试提交一个问题here 也链接这个 SO 问题/答案。
更新 3
经过一点英特尔,我发现flutter tools 在构建项目之前设置了应用程序启动环境。因此,当我们第一次在Info.plist 中更改CFBundleIdentifier 时,第二次启动flutter run 时,它会采用先前修改的值并尝试启动此捆绑ID,而在构建期间我们正在更改它,因为我们正在构建一个不同的变体。
一种可能的解决方案是启动一个脚本,在调用fluetter run 之前更改Info.plist 中的CFBundleIdentifier。
例如,从 Info.plist 开始,生产捆绑包 id 为 com.example.flutterAppAuthFlavours,我们可以这样做
这里我使用sed 命令只是为了想不同,但您可以在调用flutter run 之前调用我们下面的PlistBuddy 进行更改。