Flutter Flavors GoogleService-Info.plist 不根据 IOS 方案进行切换

问题描述 投票:0回答:1

我最近将 Flutter Flavors 添加到我的 Flutter 项目中,因为我想要生产、暂存和开发环境。我还希望每种风格都有不同的 Firebase 项目,因此我为每个 Firebase 项目 GoogleService-Info.plist 文件创建了一个配置文件夹,其中包含各自的文件夹

enter image description here

我还在跑步者目标中添加了此构建阶段脚本 -

environment="default"
# Regex to extract the scheme name from the Build Configuration
# We have named our Build Configurations as Debug-dev, Debug-prod etc.
# Here, dev and prod are the scheme names. This kind of naming is required by Flutter for flavors to work.
# We are using the $CONFIGURATION variable available in the XCode build environment to extract 
# the environment (or flavor)
# For eg.
# If CONFIGURATION="Debug-prod", then environment will get set to "prod".
if [[ $CONFIGURATION =~ -([^-]*)$ ]]; then
environment=${BASH_REMATCH[1]}
fi
echo $environment
# Name and path of the resource we're copying
GOOGLESERVICE_INFO_PLIST=GoogleService-Info.plist
GOOGLESERVICE_INFO_FILE=${PROJECT_DIR}/config/${environment}/${GOOGLESERVICE_INFO_PLIST}
# Make sure GoogleService-Info.plist exists
echo "Looking for ${GOOGLESERVICE_INFO_PLIST} in ${GOOGLESERVICE_INFO_FILE}"
if [ ! -f $GOOGLESERVICE_INFO_FILE ]
then
echo "No GoogleService-Info.plist found. Please ensure it's in the proper directory."
exit 1
fi

位于构建阶段中的此处(名为“将 GoogleService-Info.plist 复制到正确位置”的脚本

enter image description here

我知道这些文件没有被使用,因为我在使用 Flutter Flavors 之前有另一个 GoogleService-Info.plist 并且只有一个 Firebase 帐户。

enter image description here

当我删除原始的 GoogleService-Info.plist (不是配置文件中的)时,我的 flutter 项目抱怨它找不到 GoogleService-Info.plist 文件。不知道为什么会发生这种情况。

我关注了这个 中等教程 - https://medium.com/@animeshjain/build-flavors-in-flutter-android-and-ios-with- Different-firebase-projects-per-flavor-27c5c5dac10b

还有这个 YouTube 视频 - https://www.youtube.com/watch?v=Vhm1Cv2uPko

ios flutter xcode firebase dart
1个回答
0
投票

然后只需保留原来的GoogleService-Info.plist

您的脚本有问题,请用以下内容替换您的 shell 脚本:

environment="default"

# Regex to extract the scheme name from the Build Configuration
# We have named our Build Configurations as Debug-dev, Debug-prod etc.
# Here, dev and prod are the scheme names. This kind of naming is required by Flutter for flavors to work.
# We are using the $CONFIGURATION variable available in the XCode build environment to extract 
# the environment (or flavor)
# For eg.
# If CONFIGURATION="Debug-prod", then environment will get set to "prod".
if [[ $CONFIGURATION =~ -([^-]*)$ ]]; then
environment=${BASH_REMATCH[1]}
fi

echo $environment

# Name and path of the resource we're copying
GOOGLESERVICE_INFO_PLIST=GoogleService-Info.plist
GOOGLESERVICE_INFO_FILE=${PROJECT_DIR}/config/${environment}/${GOOGLESERVICE_INFO_PLIST}

# Make sure GoogleService-Info.plist exists
echo "Looking for ${GOOGLESERVICE_INFO_PLIST} in ${GOOGLESERVICE_INFO_FILE}"
if [ ! -f $GOOGLESERVICE_INFO_FILE ]
then
echo "No GoogleService-Info.plist found. Please ensure it's in the proper directory."
exit 1
fi

# Get a reference to the destination location for the GoogleService-Info.plist
# This is the default location where Firebase init code expects to find GoogleServices-Info.plist file
PLIST_DESTINATION=${BUILT_PRODUCTS_DIR}/${PRODUCT_NAME}.app
echo "Will copy ${GOOGLESERVICE_INFO_PLIST} to final destination: ${PLIST_DESTINATION}"

# Copy over the prod GoogleService-Info.plist for Release builds
cp "${GOOGLESERVICE_INFO_FILE}" "${PLIST_DESTINATION}"
© www.soinside.com 2019 - 2024. All rights reserved.