Points encountered by flutter integrated firebase push

Background, when I did this, the results of the integrated flutter firebase search were all configurable in a few sentences. When I did this, I found a bit more pits. Everyone in the regular process would write about them, but the important pits must be of concern to everyone. So I wrote this article, I hope it can help friends like me who have met many pits.

1: Android firebase Configuration

1: Apply for an account in the firebase console and create an application. Download the google-services.json file and place it in the app/directory in the android project

2: Configure the gradle file, one is the project's gradle file, the other is the app's gradle file, the role of gradle I will not cover much here, you can go to the gradle official website to see if you are interested.

Project-level build.gradle (<project>/build.gradle):
// Configure third-party plug-ins related
buildscript {
  // Indicates where the following plug-ins will be downloaded. Here they are downloaded from the google and maven repositories. They are downloaded sequentially. If google downloads them, they will not be downloaded from the maven repository.
  repositories {
    // Make sure that you have the following two repositories
    google()  // Google's Maven repository

    mavenCentral()  // Maven Central repository

  }
  // Plug-in dependency
  dependencies {
    ...
    // Add the dependency for the Google services Gradle plugin
    classpath 'com.google.gms:google-services:4.3.13'

  }
}

allprojects {
  ...
  repositories {
    // Make sure that you have the following two repositories
    google()  // Google's Maven repository

    mavenCentral()  // Maven Central repository

  }
}

Notable is app/build.gradle, the scheme given by the website is not very good. Here's what firebase officially gave us: the placement is ambiguous, and various errors are detected.

plugins {
  id 'com.android.application'

  // Add the Google services Gradle plugin
  id 'com.google.gms.google-services'

  ...
}

dependencies {
  // Import the Firebase BoM
  implementation platform('com.google.firebase:firebase-bom:30.3.2')


  // TODO: Add the dependencies for Firebase products you want to use
  // When using the BoM, don't specify versions in Firebase dependencies
  implementation 'com.google.firebase:firebase-analytics'


  // Add the dependencies for any other desired Firebase products
  // https://firebase.google.com/docs/android/setup#available-libraries
}

Last of all this site firebase_flutter Helped me get ashore successfully. Paste the correct configuration below

android/app/build.gradle
apply plugin: 'com.google.gms.google-services'

In that short sentence, let's go, then the flutter project is introduced, firebase_core and firebase_messaging

3: Initialize firebase in code

Firebase.initializeApp().then((value) async {
    print("firebase init over");
    String? token = await FirebaseMessaging.instance.getToken();
    print("token is $token");
    if(token != null && token.isNotEmpty) {
        // Upload token to back-end and let back-end control send push notifications
    }
})

The firebase integration on android is now complete.

2: firebase configuration on IOS side, this step is very hard for me, it is a footprint step by step!

1: Or download the Google-Services.plist file

2: Configure firebase

Take a look at the firebase website first

A few sentences are over, so I thought it was easy to do so, but the xcode report wasn't found. Check to see if it's a network problem, but no. I cut to the ios file and added pod install, but mistakenly said FirebaseCore relied on the GoogleUitls cloud, so I searched the Internet for a real solution to the problem.

Report errors:

[!] The following Swift pods cannot yet be integrated as static libraries:

The Swift pod FirebaseCoreInternal-library depends upon GoogleUtilities-library, which does not define modules. To opt into those targets generating module maps (which is necessary to import them from Swift when building as static libraries), you may set use_modular_headers! globally in your Podfile, or specify :modular_headers => true for particular dependencies.

Solution: Modify Podfile

 platform :ios, '12.4'
  ...
  ...
  
  pod 'Firebase', :modular_headers => true
  pod 'FirebaseCoreInternal', :modular_headers => true
  pod 'GoogleUtilities', :modular_headers => true
  #....add any library need headers

Connection Address: Solution

Take a look at the website Official website method - Garbage

Never mention the most vital thing.

:modular_headers => true

3: IOS needs to configure the certificate for notification before it can push it, and then download it. p8 files uploaded to the firebase configuration background will succeed, otherwise apns-not recognized string will be reported, and push settings will need to be added at the project location

Tags: Android Flutter Gradle

Posted by rfighter on Tue, 16 Aug 2022 22:39:22 +0530