Flutter

[flutter][firebase] flutter에 firebase 연결하기 (FlutterAppRequiredException, FirebaseCommandException 에러 해결)

옐그멍이 2023. 2. 25. 15:32
flutter에 firebase 연결하기 순서
1. 파이어베이스 콘솔에서 프로젝트 생성하기
2. 앱을 추가하여 시작하기 (플랫폼 선택)
3. 작업공간 준비
4. FlutterFire CLI 설치 및 실행
    4-1. 환경 변수 Path에 추가
    4-2. 프로젝트 내에 firebase cli 복사
    4-3. firebase_cli에서 명령어 실행하기
5. Firebase 초기화 및 플러그인 추가
6. 그 외의 문제 상황
    6-1. FlutterAppRequiredException: The current directory does not appear to be a Flutter application project.
    6-2. FirebaseCommandException: An error occured on the Firebase CLI when attempting to run a command.

 

1. 파이어베이스 콘솔에서 프로젝트 생성하기

프로젝트 추가를 누른 후 이름, 애널리틱스 사용여부를 설정해준다.

 

2. 앱을 추가하여 시작하기 (플랫폼 선택)

자신의 플랫폼에 맞는 앱을 선택한다. 왼쪽부터 iOS / Android / web / unity / flutter

저는 플러터를 연결할 것이므로 마지막에 있는 플러터 로고를 선택했습니다.

 

3. 작업공간 준비

https://firebase.google.com/docs/cli#windows-standalone-binary

 

Firebase CLI 참조  |  Firebase 문서

 

firebase.google.com

위의 사이트로 가서 윈도우(각자 OS에 맞게)의 standalone binary에서 1. Download the Firebase CLI binary for Windows를 눌러 FlutterFire CLI를 설치한다.

 

4. FlutterFire CLI 설치 및 실행

4-1. 환경 변수 Path에 추가

시스템 환경 변수 편집 > 고급 > 환경 변수 > 시스템 변수 > Path 더블클릭 > 새로 만들기

C:\Users\%유저 네임%\AppData\Local\Pub\Cache\bin

위의 Path를 추가해줍니다.

4-2. 프로젝트 내에 firebase cli 복사

위의 명령어를 실행하기 전에 우선 방금전 설치했던 firebase-tools-instant-win.exe 파일을 프로젝트 파일내에 복사해서 이름을 firebase로 바꿔줍니다.

4-3. firebase_cli에서 명령어 실행하기

프로젝트 안에 복사한 exe파일(cli)말고 기존의 exe파일(cli)에서 cd %프로젝트 경로% 로 이동해준 후 명령어를 실행해줍니다.

프로젝트 내에 lib 폴더에 firebase_options.dart 파일이 생기면 연결된 것입니다!!

 

5. Firebase 초기화 및 플러그인 추가 

main.dart에 다음과 같이 코드를 넣어줍니다.

pubspec.yaml에서 firebase_core 패키지를 다운(적고 pub get 누르기)해주면 끝입니다.

6. 그 외 문제 상황

6-1. FlutterAppRequiredException: The current directory does not appear to be a Flutter application project.

위의 경우에서는 프로젝트 밖에 있는 cli에서 프로젝트 안으로 이동하지 않고 명령어를 실행해주어서 제대로 연결이 되지 않은 상황입니다.

 

6-2. FirebaseCommandException: An error occured on the Firebase CLI when attempting to run a command.

i Found 0 Firebase projects. Selecting project netflix-clone-89f02.
FirebaseCommandException: An error occured on the Firebase CLI when attempting to run a command.
COMMAND: firebase --version
ERROR: The FlutterFire CLI currently requires the official Firebase CLI to also be installed, see https://firebase.google.com/docs/cli#install_the_firebase_cli for how to install it.

위와 같은 에러가 떴을 경우에는 제대로 파이어베이스 계정에 로그인이 안되었기 때문입니다. 제 경우에는 프로젝트 내에 있는 flutterfire cli에서는 로그인이 안되어서 처음에 다운로드 되었던 위치에서 위의 4부터의 과정을 해주니 실행되었습니다.

728x90