flutterfire icon indicating copy to clipboard operation
flutterfire copied to clipboard

[firebase_messaging] Issue after follow documentation

Open woprandi opened this issue 6 years ago • 22 comments

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

woprandi avatar Dec 11 '19 21:12 woprandi

same here!

wooks186 avatar Dec 12 '19 04:12 wooks186

I fixed by replace

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

hsangtini avatar Dec 12 '19 05:12 hsangtini

same here!

harloom avatar Dec 12 '19 07:12 harloom

I used firebase_messaging: ^6.0.8 Same Error

arasu33 avatar Dec 12 '19 08:12 arasu33

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

zeienko-vitalii avatar Dec 12 '19 10:12 zeienko-vitalii

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

MapleNoise avatar Dec 12 '19 11:12 MapleNoise

Same error

marinat avatar Dec 12 '19 13:12 marinat

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

mhadaily avatar Dec 12 '19 13:12 mhadaily

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 avatar Dec 12 '19 14:12 iapicca

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

woprandi avatar Dec 13 '19 16:12 woprandi

same error

xellDart avatar Dec 14 '19 23:12 xellDart

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 avatar Dec 15 '19 09:12 mrifni

@mrifni work perfectly

digarahayu avatar Dec 16 '19 02:12 digarahayu

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

woprandi avatar Dec 16 '19 17:12 woprandi

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

mrifni avatar Dec 17 '19 09:12 mrifni

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

insinfo avatar Dec 21 '19 21:12 insinfo

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

SEGVeenstra avatar Dec 30 '19 11:12 SEGVeenstra

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

meidikawardana avatar Jan 03 '20 09:01 meidikawardana

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

altafkhan8719 avatar Jan 22 '20 06:01 altafkhan8719

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:

  • @altafkhan8719 https://github.com/FirebaseExtended/flutterfire/issues/1607#issuecomment-577028200
  • @SEGVeenstra https://github.com/FirebaseExtended/flutterfire/issues/1607#issuecomment-569658215
  • @digarahayu https://github.com/FirebaseExtended/flutterfire/issues/1607#issuecomment-565876176
  • and at last, it worked for me as well

KrishnaPravin avatar Feb 01 '20 10:02 KrishnaPravin