플러터에서 Firebase 연동하는 방법에 대해서 소개하고자 글을 남긴다.
목차는 Firebase와 연동하는 패키지 , Android 연동 , Ios 연동 으로 나누어 보았다.
Flutter에서 Firebase를 사용하기 위해, firebase_core 패키지를 설치할 필요가 있다.
터미널에서 다음 명령어를 사용하여 firebase_core를 설치한다.
flutter pub add firebase_core
firebase_core 패키지를 설치한 후, Firebase를 초기화해야 한다.
main.dart 파일을 열고 다음과 같이 수정하여 Firebase를 초기화 한다.
import 'package:firebase_core/firebase_core.dart';
void main() async {
WidgetsFlutterBinding.ensureInitialized();
await Firebase.initializeApp(); // Firebase 초기화
runApp(const MyApp());
}
iOS에서 firebase_core를 사용하기 위해서는 ios/Podfile을 수정해야 한다.
또한 firebase_core는 다음 플랫폼 버전 이상을 요구한다.
ios/Podfile 파일을 열고 다음과 같이 수정한다.
패키지 이름은 AndroidManifest.xml에 있는걸 그대로 복사한다.
buildscript {
repositories {
// Make sure that you have the following two repositories
google() // Google's Maven repository
mavenCentral() // Maven Central repository
}
dependencies {
...
// Add the dependency for the Google services Gradle plugin
classpath 'com.google.gms:google-services:4.3.13' // 추가
classpath 'com.android.tools.build:gradle:4.1.0'
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
}
}
allprojects {
...
repositories {
// Make sure that you have the following two repositories
google() // Google's Maven repository
mavenCentral() // Maven Central repository
}
}
Unable to install /Users/hoon/AndroidStudioProjects/medication_manage/build/ios/iphonesimulator/Runner.app on 83A2E900-4206-4EFD-A263-0B5E1D56AF8A. This is sometimes caused by a malformed plist file:
ProcessException: Process exited abnormally:
An error was encountered processing the command (domain=NSPOSIXErrorDomain, code=22):
Failed to install the requested application
The bundle identifier of the application could not be determined.
Ensure that the application's Info.plist contains a value for CFBundleIdentifier.
Command: xcrun simctl install 83A2E900-4206-4EFD-A263-0B5E1D56AF8A /Users/hoon/AndroidStudioProjects/medication_manage/build/ios/iphonesimulator/Runner.app
Error launching application on iPhone