iosxcodefirebaseflutterplist

Firebase Flutter iOS initialization issue


Hi I am getting following issue while I am trying to initialze firebase.

Unhandled Exception: [core/not-initialized] Firebase has not been correctly initialized. Have you added the "GoogleService-Info.plist" file to the project?

My code is:

await Firebase.initializeApp();

I am using separate Google Service Info Plist for development and production.

enter image description here

So I am using following script in Xcode under Target > Build Phase > Run New Script Phase to copy the plist to main directory.

if [ "${CONFIGURATION}" == "Debug-prod" ] || [ "${CONFIGURATION}" == "Release-prod" ] || [ "${CONFIGURATION}" == "Release" ]; then
cp -r "${PROJECT_DIR}/Runner/Firebase/prod/GoogleService-Info.plist" "${PROJECT_DIR}/Runner/GoogleService-Info.plist"

echo "Production plist copied"

elif [ "${CONFIGURATION}" == "Debug-dev" ] || [ "${CONFIGURATION}" == "Release-dev" ] || [ "${CONFIGURATION}" == "Debug" ]; then

cp -r "${PROJECT_DIR}/Runner/Firebase/dev/GoogleService-Info.plist" "${PROJECT_DIR}/Runner/GoogleService-Info.plist"

echo "Development plist copied"
fi

Any help would be appreciated :)


Solution

  • You have to add some default GoogleService-Info.plist into ${PROJECT_DIR}/Runner/GoogleService-Info.plist (best option would be the dev one)

    After you start building, your script will override that one.

    XCode project have to know that GoogleService-Info.plist exists in project, your script is about overriding it's content