Flutterfire: [firebase_messaging] Issue after follow documentation

Created on 11 Dec 2019  Â·  22Comments  Â·  Source: FirebaseExtended/flutterfire

Describe the bug
Hi,

After follow the README, I got build errors (new flutter app) :


Launching lib/main.dart on AOSP on IA Emulator in debug mode...
e: Supertypes of the following classes cannot be resolved. Please make sure you have the required dependencies in the classpath:
    class io.flutter.plugins.firebasemessaging.FlutterFirebaseMessagingService, unresolved supertypes: com.google.firebase.messaging.FirebaseMessagingService

e: /home/william/Documents/test/android/app/src/main/kotlin/com/example/test/Application.kt: (16, 45): Type mismatch: inferred type is PluginRegistry but FlutterEngine was expected

FAILURE: Build failed with an exception.

* What went wrong:
Execution failed for task ':app:compileDebugKotlin'.
> Compilation error. See log for more details

* Try:
Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output. Run with --scan to get full insights.

* Get more help at https://help.gradle.org

BUILD FAILED in 26s
Gradle task assembleDebug failed with exit code 1
Exited (sigterm)

 import io.flutter.app.FlutterApplication
 import io.flutter.plugin.common.PluginRegistry
 import io.flutter.plugin.common.PluginRegistry.PluginRegistrantCallback
 import io.flutter.plugins.GeneratedPluginRegistrant
 import io.flutter.plugins.firebasemessaging.FlutterFirebaseMessagingService

 class Application: FlutterApplication(), PluginRegistrantCallback {
   override fun onCreate() {
     super.onCreate()
     FlutterFirebaseMessagingService.setPluginRegistrant(this)
   }

   override fun registerWith(registry: PluginRegistry) {
     GeneratedPluginRegistrant.registerWith(registry)
   }
 }

To Reproduce
Steps to reproduce the behavior:

  1. Create Flutter app
  2. Use firebase_messaging 0.6.7
  3. Follow the documentation for Android

Expected behavior
No build problem

Additional context

bug

Most helpful comment

I was able to get rid of the error by doing these below changes

in android/build.gradle
classpath 'com.google.gms:google-services:4.3.3'

in android/app/build.gradle
implementation "com.google.firebase:firebase-analytics:17.2.1" (you probably wont need this)
implementation "com.google.firebase:firebase-messaging:20.1.0"

All 22 comments

same here!

I fixed by replace

override fun registerWith(registry: PluginRegistry?) {
        registry?.registrarFor("io.flutter.plugins.firebasemessaging.FirebaseMessagingPlugin");
    }

same here!

I used firebase_messaging: ^6.0.8
Same Error

Same error

• Flutter version 1.12.13+hotfix.5 at /Users/user/Documents/Java/flutter
    • Framework revision 27321ebbad (32 hours ago), 2019-12-10 18:15:01 -0800
    • Engine revision 2994f7e1e6
    • Dart version 2.7.0

Firebase version:
firebase_messaging: ^6.0.8

I downgrade firebase_messaging in my pubspec waiting fix error :
firebase_messaging: 6.0.3

Same error

same error and same environment
dart 2.7 and firebase_messaging: 6.0.8 and flutter 1.12.13+hotfix.5

Hi @woprandi
I see there's an open issue addressing the case you described.
Please follow up on that issue,
I'm closing the current one as duplicate.
If you disagree please write in the comments
and I will reopen it.
Thank you

@iapicca And the code of the Application.java in the README is invalid

same error

I was able to get rid of the error by doing these below changes

in android/build.gradle
classpath 'com.google.gms:google-services:4.3.3'

in android/app/build.gradle
implementation "com.google.firebase:firebase-analytics:17.2.1" (you probably wont need this)
implementation "com.google.firebase:firebase-messaging:20.1.0"

@mrifni work perfectly

Why add firebase-messaging dependency in the build.gradle since it wasn't necessary until now ?

not sure, flutter docs doesnt cover adding of dependencies of firebase-messaging

for me decided by doing this:

Aplication.kt

package br.gov.rj.riodasostras.appsescverao

import android.os.Bundle

import io.flutter.app.FlutterActivity
import io.flutter.app.FlutterApplication
import io.flutter.plugin.common.PluginRegistry
import io.flutter.plugin.common.PluginRegistry.PluginRegistrantCallback
import io.flutter.plugins.GeneratedPluginRegistrant
import io.flutter.plugins.firebasemessaging.FlutterFirebaseMessagingService
//import com.google.firebase.messaging.FirebaseMessagingService

 class Application : FlutterApplication() , PluginRegistrantCallback {

   override fun onCreate() {
     super.onCreate();
     FlutterFirebaseMessagingService.setPluginRegistrant(this);
   }

   override fun registerWith( registry: PluginRegistry) {
     GeneratedPluginRegistrant.registerWith(registry);
   }
 }

android/build.gradle


buildscript {
    ext.kotlin_version = '1.3.0' //1.2.71
    repositories {
        google()
        jcenter()
    }

    dependencies {
        classpath 'com.android.tools.build:gradle:3.3.1' //3.2.1 //3.5.3
        classpath 'com.google.gms:google-services:4.3.3' //4.3.2
        classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
    }
}

allprojects {
    repositories {
        google()
        jcenter()
    }
}

rootProject.buildDir = '../build'
subprojects {
    project.buildDir = "${rootProject.buildDir}/${project.name}"
}
subprojects {
    project.evaluationDependsOn(':app')
}

task clean(type: Delete) {
    delete rootProject.buildDir
}

android/app/build.gradle


def localProperties = new Properties()
def localPropertiesFile = rootProject.file('local.properties')
if (localPropertiesFile.exists()) {
    localPropertiesFile.withReader('UTF-8') { reader ->
        localProperties.load(reader)
    }
}

def flutterRoot = localProperties.getProperty('flutter.sdk')
if (flutterRoot == null) {
    throw new GradleException("Flutter SDK not found. Define location with flutter.sdk in the local.properties file.")
}

def flutterVersionCode = localProperties.getProperty('flutter.versionCode')
if (flutterVersionCode == null) {
    flutterVersionCode = '1'
}

def flutterVersionName = localProperties.getProperty('flutter.versionName')
if (flutterVersionName == null) {
    flutterVersionName = '1.0'
}

apply plugin: 'com.android.application'
apply plugin: 'kotlin-android'
apply from: "$flutterRoot/packages/flutter_tools/gradle/flutter.gradle"
//inicio alteração
apply plugin: 'com.google.gms.google-services'
//fim

//importa arquivo de configuração da chave de assinatura do App
def keystoreProperties = new Properties()
def keystorePropertiesFile = rootProject.file('key.properties')
if (keystorePropertiesFile.exists()) {
    keystoreProperties.load(new FileInputStream(keystorePropertiesFile))
}


android {
    compileSdkVersion 28

    sourceSets {
        main.java.srcDirs += 'src/main/kotlin'
    }

    lintOptions {
        disable 'InvalidPackage'
    }

    defaultConfig {
        // TODO: Specify your own unique Application ID (https://developer.android.com/studio/build/application-id.html).
        applicationId "br.gov.rj.riodasostras.appsescverao"
        minSdkVersion 21
        multiDexEnabled true
        targetSdkVersion 28
        versionCode flutterVersionCode.toInteger()
        versionName flutterVersionName
        testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
    }
    //sign release
    signingConfigs {
        release {
            keyAlias localProperties['keyAlias']
            keyPassword localProperties['keyPassword']
            storeFile file(localProperties['storeFile'])
            storePassword localProperties['storePassword']
        }
    }

    buildTypes {
        release {
            // Signing with the debug keys for now, so `flutter run --release` works.
            //signingConfig signingConfigs.debug
            //abilita a versão assinada para publicação na Play store
            signingConfig signingConfigs.release
            //abilita obfuscação e mimificação
            minifyEnabled true
            useProguard true
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'

        }
    }
}

flutter {
    source '../..'
}

dependencies {
    //inicio alteração para abilita multidex e firebase
    implementation 'com.android.support:multidex:2.0.0' //1.0.3
    implementation 'com.google.firebase:firebase-core:17.2.1'
    implementation "com.google.firebase:firebase-analytics:17.2.1" 
    implementation "com.google.firebase:firebase-messaging:20.1.0"
    //fim
    implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"
    testImplementation 'junit:junit:4.12'
    androidTestImplementation 'com.android.support.test:runner:1.0.2'
    androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.2'
}

//inicio alteração
apply plugin: 'com.google.gms.google-services'
//fim

pubspec.yaml

name: appsescverao
description: Aplicativo do Sesc Verão Rio das Ostras

version: 2.0.0+2

environment:
  sdk: ">=2.1.0 <3.0.0"

dependencies:
  flutter:
    sdk: flutter
  flutter_localizations:
    sdk: flutter

  cupertino_icons: ^0.1.3
  http: ^0.12.0+2
  path_provider: ^1.5.1
  flutter_advanced_networkimage: ^0.6.2
  sqflite: ^1.2.0
  connectivity: ^0.4.6+1
  url_launcher: ^5.4.1
  cloud_firestore: ^0.13.0+1
  firebase_auth: ^0.15.2
  google_sign_in: ^4.1.0
  firebase_database: ^3.1.1
  rxdart: ^0.23.1
  webview_flutter: ^0.3.18+1
  auto_size_text: ^2.1.0
  flutter_map: ^0.8.0
  latlong: ^0.6.1
  queries: ^0.1.12
  firebase_analytics: ^5.0.9
  shared_preferences: ^0.5.6
  share: ^0.6.3+5
  map_launcher: ^0.3.2
  #audioplayers: ^0.13.5
  #audio_streams: ^1.0.0+2
  firebase_messaging: ^6.0.9

dev_dependencies:
  flutter_test:
    sdk: flutter

  intl_translation: ^0.17.7

flutter:

  uses-material-design: true

  assets:
    - assets/logo.png
    - assets/background.png
    - assets/background2.png
    - assets/background3.png
    - assets/user-avatar.png
    - assets/logo-pmro-cinza.png
    - assets/logo-pmro-branco.png
    - assets/wave-bottom.png
    - assets/wave-top.png
    - assets/logo2.png
    - assets/logo-branca.png

  fonts:
    - family: Big Noodle Titling
      fonts:
        - asset: fonts/big_noodle_titling.ttf
    - family: GlosaDisplayW01-Bold
      fonts:
        - asset: fonts/glosa_display_w01_bold.ttf
    - family: BakerieSmoothCondensedMedium
      fonts:
        - asset: fonts/BakerieSmoothCondensed-Medium.otf
    - family: BakerieSmoothBold
      fonts:
        - asset: fonts/BakerieSmooth-Bold.otf
    - family: iconsmind
      fonts:
        - asset: fonts/iconsmind.ttf

in android/build.gradle
classpath 'com.google.gms:google-services:4.3.3'

in android/app/build.gradle
implementation "com.google.firebase:firebase-messaging:20.1.0"

Doing this solved it for me

@insinfo your answer is too long. you should point out what you add / update on your code like what @mrifni did

I was able to get rid of the error by doing these below changes

in android/build.gradle
classpath 'com.google.gms:google-services:4.3.3'

in android/app/build.gradle
implementation "com.google.firebase:firebase-analytics:17.2.1" (you probably wont need this)
implementation "com.google.firebase:firebase-messaging:20.1.0"

Thanks
It Solve my Problem

Hi @woprandi
I see there's an open issue addressing the case you described.
Please follow up on that issue,
I'm closing the current one as duplicate.
If you disagree please write in the comments
and I will reopen it.
Thank you

@iapicca Please mention this https://github.com/FirebaseExtended/flutterfire/issues/1607#issuecomment-565793930 as the solution for this issue.
I surely believe #1606 is not the duplicate of #1607

This comment https://github.com/FirebaseExtended/flutterfire/issues/1607#issuecomment-565793930 has worked for several people:

for me decided by doing this:

Aplication.kt

```kotlin
package br.gov.rj.riodasostras.appsescverao

...

@insinfo what are we looking at here? what are your specific changes to the default steps provided by the documentation?

Could everyone who still has this problem please file a new issue with the exact descriptions what happens, logs and the output of 'flutter doctor -v' please.
All system setups can be slightly different so it's always better to open new issues and reference related issues.

Was this page helpful?
0 / 5 - 0 ratings