Firebase Flutter iOS initialization issue

503

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

Share:
503
user6788419
Author by

user6788419

Updated on December 27, 2022

Comments

  • user6788419
    user6788419 over 1 year

    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 :)

    • fartem
      fartem over 3 years
      Can you add place in code where you get this exception?
    • iwpz
      iwpz over 3 years
      you cp file to "${PROJECT_DIR}/Runner/GoogleService-Info.plist", but make sure "${PROJECT_DIR}/Runner/GoogleService-Info.plist" is in your iOS project.
    • user6788419
      user6788419 over 3 years
      @iwpz.. It doesn't work when I change the environment.