我正在尝试在Codemagic上构建一个Flutter应用程序。该应用程序使用多个firebase项目,因此我已对其进行了相应配置。我能够在本地运行适用于android和iOS的所有版本。 Android构建在Codemagic上也成功,但iOS构建失败。
在下面的屏幕截图中,您可以看到到达Firebase安装运行脚本文件后,iOS构建失败
我的Firebase安装文件的代码是
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}"
我正在关注https://medium.com/@animeshjain/build-flavors-in-flutter-android-and-ios-with-different-firebase-projects-per-flavor-27c5c5dac10b文章进行设置。
这是我根据Codemagic团队的建议采取的另一种方法
我没有创建风味,而是将
firebase
文件作为环境变量上传到了codemagic。一切都适用于android,但iOS构建失败,提示无法获取GOOGLE_APP_ID。我知道很多人在堆栈上都问过这个问题,但是他们都不适合我,因为它们与代码魔术无关,而是手动将文件拖到Xcode。我还进行了SSH检查,以检查firebase文件是否已添加到iOS文件夹中,并且确实在预构建脚本的帮助下被添加了,但是iOS构建仍然失败。
最佳答案
我使用同一篇中型文章在本地计算机上设置风味(prod和dev)。
我遵循Codemagic教程为Google Service文件设置环境变量,但始终遇到相同的Could not get GOOGLE_APP_ID
错误。
对我而言,关键的见解是尽可能在Codemagic中复制本地环境,并在Codemagic构建过程中利用Xcode中的Firebase设置脚本。
就我而言,这意味着为Runner/Firebase/prod/GoogleService-Info.plist
重新创建完全相同的文件夹和文件结构,以便Build Phases中的Firebase安装脚本可以正常运行。
首先,我在Codemagic中更改了预构建脚本,以确保Firebase安装脚本可以找到GoogleService-Info.plist
:
#!/bin/bash
set -e # exit on first failed commandset
rm -rf $FCI_BUILD_DIR/iOS/Runner/GoogleService-Info.plist
mkdir -p “${FCI_BUILD_DIR}/iOS/Runner/Firebase/${FCI_FLUTTER_SCHEME}”
echo $IOS_FIREBASE_SECRET | base64 —decode > $FCI_BUILD_DIR/iOS/Runner/Firebase/prod/GoogleService-Info.plist
其次,Xcode必须注意这些文件。目录中存在的文件并不意味着它在Xcode上。将
Firebase/
目录添加到Xcode by File->将文件添加到“Runner ..”,并确保取消选中“如果需要,请复制”。如果您已经在本地进行构建而没有任何问题,则可以跳过此步骤。
Here is how my folders appear in Xcode
然后使用
FCI_FLUTTER_SCHEME=prod
在Codemagic上运行构建。最后,阅读Codemagic构建工件中的
xcodebuild.log
可能会为您提供更多详细信息。关于ios - Codemagic无法在iOS中使用自定义运行脚本吗?,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/60149203/