Flutter - FCM

오픈소스·2024년 5월 6일
0
$ flutter pub add firebase_messaging
$ flutter pub add firebase_core
$ flutter pub add flutter_local_notifications
  • android/app/build.gradle

    android {
      compileSdkVersion 34
      ...
    }
  • App requires Multidex support

    Multidex support is required for your android app to build since the number of methods has exceeded 64k. See https://docs.flutter.dev/deployment/android#enabling-multidex-support for more information. You may pass the --no-multidex flag to skip Flutter's multidex support to use a manual solution.
    
    Flutter tool can add multidex support. The following file will be added by flutter:
    
        android/app/src/main/java/io/flutter/app/FlutterMultiDexApplication.java

    https://velog.io/@jhkim0122/Android-multidex-error-해결-방법-App-requires-Mutidex-support

    • /android/app/build.gradle

      android {
          defaultConfig {
              applicationId "com.jhkim.jhkimvelog"
              minSdkVersion 17
              targetSdkVersion flutter.targetSdkVersion
              versionCode flutterVersionCode.toInteger()
              versionName flutterVersionName
              multiDexEnabled true // this line
          }
          ...
      }
      
      dependencies {
          implementation 'com.android.support:multidex:2.0.1' // this line
      }
  • flutterfire configure

$ flutterfire configure  
? You have an existing `firebase.json` file and possibly already configured your project for Firebase. Would you prefer to reuse the values in your existing `firebase.json` fil
? You have an existing `firebase.json` file and possibly already configured your project for Firebase. Would you prefer to reuse the values in your existing `firebase.json` fil
✔ You have an existing `firebase.json` file and possibly already configured your project for Firebase. Would you prefer to reuse the values in your existing `firebase.json` file to configure your project? · no 
i Found 2 Firebase projects. Selecting project flutter-card-sms-app.                                                                                                            
✔ Which platforms should your configuration support (use arrow keys & space to select)? · android, ios                                                                          
i Firebase android app com.youngkiu.card_alarm registered.                                                                                                                      
i Firebase ios app com.youngkiu.cardalarm registered.                                                                                                                           

Firebase configuration file lib/firebase_options.dart generated successfully with the following Firebase apps:

Platform  Firebase App Id
android   1:...
ios       1:...

Learn more about using this file and next steps from the documentation:
 > https://firebase.google.com/docs/flutter/setup
  • dart source codes
void main() async {
  await Firebase.initializeApp(
      options: DefaultFirebaseOptions.currentPlatform
  );

  runApp(const MyApp());
}
    final token = await FirebaseMessaging.instance.getToken();
    debugPrint("token : ${token ?? 'token NULL!'}");

참고)

0개의 댓글