Why firebase messaging is not working although I made android x modifications

1,545

Please upgrade your package to latest version firebase_messaging: 6.0.1. It will work

Share:
1,545
Aya Elsisy
Author by

Aya Elsisy

Updated on December 12, 2022

Comments

  • Aya Elsisy
    Aya Elsisy over 1 year

    I have a problem working fire base messaging package the following error appear. I have tried all the posted solutions. I have tried flutter clean, upgrading min sdk to 28 and complied one but this not worked

    but nothing worked for me wish to find help in this it wasted a day of developing. thank you

    E:\flutter\flutter\.pub-cache\hosted\pub.dartlang.org\firebase_messaging-2.2.0+1\android\src\main\java\io\flutter\plugins\firebasemessaging\FirebaseMessagingPlugin.java:12: error: package android.support.annotation does not exist
    import android.support.annotation.NonNull;
                                     ^
    E:\flutter\flutter\.pub-cache\hosted\pub.dartlang.org\firebase_messaging-2.2.0+1\android\src\main\java\io\flutter\plugins\firebasemessaging\FirebaseMessagingPlugin.java:13: error: package android.support.v4.content does not exist
    import android.support.v4.content.LocalBroadcastManager;
                                     ^
    E:\flutter\flutter\.pub-cache\hosted\pub.dartlang.org\firebase_messaging-2.2.0+1\android\src\main\java\io\flutter\plugins\firebasemessaging\FlutterFirebaseInstanceIDService.java:9: error: package android.support.v4.content does not exist
    import android.support.v4.content.LocalBroadcastManager;
                                     ^
    
                                     ^
    E:\flutter\flutter\.pub-cache\hosted\pub.dartlang.org\firebase_messaging-2.2.0+1\android\src\main\java\io\flutter\plugins\firebasemessaging\FirebaseMessagingPlugin.java:81: error: cannot find symbol
      @NonNull
       ^
      symbol:   class NonNull
      location: class FirebaseMessagingPlugin
    E:\flutter\flutter\.pub-cache\hosted\pub.dartlang.org\firebase_messaging-2.2.0+1\android\src\main\java\io\flutter\plugins\firebasemessaging\FirebaseMessagingPlugin.java:57: error: cannot find symbol
        LocalBroadcastManager manager = LocalBroadcastManager.getInstance(registrar.context());
        ^
      symbol:   class LocalBroadcastManager
      location: class FirebaseMessagingPlugin
    E:\flutter\flutter\.pub-cache\hosted\pub.dartlang.org\firebase_messaging-2.2.0+1\android\src\main\java\io\flutter\plugins\firebasemessaging\FirebaseMessagingPlugin.java:57: error: cannot find symbol
        LocalBroadcastManager manager = LocalBroadcastManager.getInstance(registrar.context());
                                        ^
      symbol:   variable LocalBroadcastManager
      location: class FirebaseMessagingPlugin
    E:\flutter\flutter\.pub-cache\hosted\pub.dartlang.org\firebase_messaging-2.2.0+1\android\src\main\java\io\flutter\plugins\firebasemessaging\FirebaseMessagingPlugin.java:122: error: cannot find symbol
                    public void onComplete(@NonNull Task<InstanceIdResult> task) {
                                            ^
     );
        ^
      symbol:   variable LocalBroadcastManager
      location: class FlutterFirebaseInstanceIDService
    E:\flutter\flutter\.pub-cache\hosted\pub.dartlang.org\firebase_messaging-2.2.0+1\android\src\main\java\io\flutter\plugins\firebasemessaging\FlutterFirebaseMessagingService.java:27: error: cannot find symbol
        LocalBroadcastManager.getInstance(this).sendBroadcast(intent);
        ^
      symbol:   variable LocalBroadcastManager
      location: class FlutterFirebaseMessagingService
    Note: E:\flutter\flutter\.pub-cache\hosted\pub.dartlang.org\firebase_messaging-2.2.0+1\android\src\main\java\io\flutter\plugins\firebasemessaging\FlutterFirebaseInstanceIDService.java uses or overrides a deprecated API.
    Note: Recompile with -Xlint:deprecation for details.
    10 errors
    
    FAILURE: Build failed with an exception.
    
    * What went wrong:
    Execution failed for task ':firebase_messaging:compileDebugJavaWithJavac'.
    > Compilation failed; see the compiler error output for 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 7s
    Running Gradle task 'assembleDebug'...
    Running Gradle task 'assembleDebug'... Done                         8.9s
    *******************************************************************************************
    The Gradle failure may have been because of AndroidX incompatibilities in this Flutter app.
    
    *******************************************************************************************
    Gradle task assembleDebug failed with exit code 1
    

    here you can find my build.gradle /app

    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 from: "$flutterRoot/packages/flutter_tools/gradle/flutter.gradle"
    
    // def keystoreProperties = new Properties()
    // def keystorePropertiesFile = rootProject.file('key.properties')
    // if (keystorePropertiesFile.exists()) {
        // keystoreProperties.load(new FileInputStream(keystorePropertiesFile))
    // }
    
    def keystoreProperties = new Properties()
    def keystorePropertiesFile = rootProject.file('key.properties')
    if (keystorePropertiesFile.exists()) {
        keystoreProperties.load(new FileInputStream(keystorePropertiesFile))
    }
    
    android {
        compileSdkVersion 28
        lintOptions {
            disable 'InvalidPackage'
        }
    
        defaultConfig {
            // TODO: Specify your own unique Application ID (https://developer.android.com/studio/build/application-id.html).
            applicationId "com.cantina.user"
            minSdkVersion 16
            multiDexEnabled true
            targetSdkVersion 28
            versionCode 17
            versionName "0.0.5"
            testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
        }
    
    
    signingConfigs {
        release {
            keyAlias keystoreProperties['keyAlias']
            keyPassword keystoreProperties['keyPassword']
            storeFile file(keystoreProperties['storeFile'])
            storePassword keystoreProperties['storePassword']
        }
    }
    configurations.all {
            resolutionStrategy {
                    force 'com.android.support:support-v4:27.1.0'
        }
    } 
    
    buildTypes {
        release {
            signingConfig signingConfigs.release
        }
    }
    }
    
    flutter {
        source '../..'
    }
    
    dependencies {
        implementation 'com.android.support:appcompat-v7:27.1.1'
        implementation 'com.android.support:support-v4:27.1.1'
        implementation 'com.google.android.gms:play-services-maps:16.1.0'
        implementation 'com.google.android.gms:play-services-location:16.0.0'
        implementation 'com.google.firebase:firebase-core:16.0.9'
        implementation 'com.google.firebase:firebase-messaging:18.0.0'
    }
    
    apply plugin: 'com.google.gms.google-services'