Codemagic预构建Firebase配置报错:文件不存在,疑$FCI_BUILD_DIR异常
I’ve run into similar path-related issues with Codemagic’s environment variables before, so let’s break down how to debug this step by step:
First, verify what
FCI_BUILD_DIRactually points to
Add a debug line at the start of your pre-build script to print the variable’s value:echo "FCI_BUILD_DIR is set to: $FCI_BUILD_DIR"When the build runs, check the logs to confirm it’s pointing to
/Users/builder/clone(the standard Codemagic clone directory). If it’s empty or wrong, you might have accidentally renamed this variable without updating the script, or the variable isn’t being injected correctly by Codemagic.Double-check your variable renaming and file write command
Since you renamed variables from the original guide, make sure the environment variable holding your Firebase config content matches exactly what you’ve set in Codemagic’s dashboard. For example, if you renamedFIREBASE_ANDROID_CONFIGtoMY_ANDROID_FIREBASE_CONFIG, your write command should be:echo "$MY_ANDROID_FIREBASE_CONFIG" > "$FCI_BUILD_DIR/android/app/google-services.json"A typo here (like a missing underscore or wrong case) will result in writing an empty file—or failing to write it entirely—leading to the "no such file" error.
Confirm the target directory exists
It’s possible theandroid/apppath doesn’t exist yet (unlikely, but worth checking). Add this line before writing the file to create the directory if needed:mkdir -p "$FCI_BUILD_DIR/android/app"Add a post-write verification step
After writing the file, check if it actually exists to narrow down the issue:if [ -f "$FCI_BUILD_DIR/android/app/google-services.json" ]; then echo "✅ google-services.json created successfully" # Optional: Print the first few lines to confirm content head "$FCI_BUILD_DIR/android/app/google-services.json" else echo "❌ Failed to create google-services.json" fi
Most often, this error boils down to a misspelled variable name or a mismatch between the environment variable you defined in Codemagic and the one you’re using in your script. The debug lines will make it obvious where the breakdown is happening.
内容的提问来源于stack exchange,提问作者oodavid

