관리 메뉴

cococo-coding

[Flutter] firebase와 연동하기(윈도우ver) 본문

[Flutter] 두번째 앱/트러블슈팅

[Flutter] firebase와 연동하기(윈도우ver)

_dani 2024. 3. 2. 18:55

정말 다사다난했던 firebase 연동기..

트러블슈팅 한 과정을 기록하기 위해 써보는 글이다.

설치 단계

설치하는 순서는 다음과 같다. 

파이어베이스 홈페이지에 나와있는 내용이다.


1. firebase-tools-instant-win.exe 열어주기

그러면 다음과 같은 창이 나온다. 

 

2. 파이어베이스 로그인 및 리스트 확인하기

 

나의 경우 이미 로그인이 되어있다고 뜨는데, 만약 안 되어 있다면 로그인 명령어와 파이어베이스 리스트를 보여주는 명령어로 확인을 한번 해준다. 


3. 환경변수 설정하기

 

어쩌면 가장 메인파트... 솔직히 어려운건 아닌데 제대로 어떻게하라는 방법이 없어서 서치하는데 시간이 오래걸림

> dart pub global activate flutterfire_cli 

 

위 명령어를 입력하는데 계속해서 다음 오류가 발생. 

Warning: Pub installs executables into C:\Users\사용자이름\AppData\Local\Pub\Cache\bin, which is not on your path.
You can fix that by adding that directory to your system's "Path" environment variable.
A web search for "configure windows path" will show you how.
Activated fltterfire_cli 0.2.7.

 

구글링 해봤는데 거의 다 macOS 해결만 나와서 계속 고전하다가 맨 아래 블로그글을 보고 겨우 해결했다. 

 

해결법

 

환경 변수 설정 (새 사용자 변수 등록 -> 새 환경 변수 등록)

 

 

4. flutterfire-cli 명령어 
> dart pub global deactivate flutterfire_cli 
> dart pub global activate flutterfire_cli

 

위의 명령어를 차례로 입력해준다. 그러면 다음과 같이 flutterfire_cli를 deactivated했다가 actived됨을 확인할 수 있다.

 

5. 플러터 프로젝트의 터미널 열어서 firebase_core 명령어 

 

지금까지는 파이어베이스 터미널로 했는데 여기서부터는 해당 플러터 프로젝트의 터미널에서 진행해야 한다!!!

이때 다음과 같은 오류가 날 수 있음

Building with plugins requires symlink support. Please enable Developer Mode in your system settings. Run start ms-settings:developers to open settings.

 

윈도우의 경우 설정에서 개발자모드를 켜주면 해결된다. 

 

* 해당 오류에 관한 참조

https://stackoverflow.com/questions/68089177/flutter-building-with-plugins-requires-symlink-support

 

Flutter: Building with plugins requires symlink support

I am getting the below error in log whenever I try to install any dependency in pubspec.yaml Building with plugins requires symlink support. Please enable Developer Mode in your system settings. R...

stackoverflow.com

 

6. main파일에 firebase 인포트 및 코드 추가
import 'package:flutter/material.dart';
import 'package:firebase_core/firebase_core.dart'; //추가
import 'firebase_options.dart'; //추가

//main() 코드가 아래처럼 되도록 추가
void main() async{
  WidgetsFlutterBinding.ensureInitialized();
  await Firebase.initializeApp(
    options: DefaultFirebaseOptions.currentPlatform,
  );
  runApp(const MyApp());
}

 

이렇게 하면 flutter프로젝트에 firebase연동이 끝난다. 


중간의 CLI 부분에서 계속 환경변수 설정 에러가 났는데 공식 홈페이지에서는 해당 설명이 없어서 구글링을 통해 해결했다. 

https://luvris2.tistory.com/839

 

Flutter - 플러터 앱에 파이어베이스 연동하기 (FlutterFire)

플러터파이어(FlutterFire) 란? Flutter의 응용 프로그램을 Firebase에 연결하는 Flutter 플러그인 세트이다. Flutter에서 Firebase 서비스를 사용하려면 FlutterFire 플러그인이 필요하다. 이 포스팅은 파이어베

luvris2.tistory.com

전체적으로 설명도 잘 되어있고, 특히 내가 골머리를 앓았던 CLI부분의 환경변수설정이 상세히 설명되어있다. 강추!!!!!