Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to stop firebase error in flutter app

my app isn't building again, don't know what I did wrong. The error message is listed below

C:\flutter\flutter\.pub-cache\hosted\pub.dartlang.org\firebase_auth-0.8.0+1\android\src\main\java\io\flutter\plugins\firebaseauth\FirebaseAuthPlugin.java:9: error: package androidx.annotation does not exist
import androidx.annotation.NonNull;
                          ^
C:\flutter\flutter\.pub-cache\hosted\pub.dartlang.org\firebase_auth-0.8.0+1\android\src\main\java\io\flutter\plugins\firebaseauth\FirebaseAuthPlugin.java:10: error: package androidx.annotation does not exist
import androidx.annotation.Nullable;
                          ^
C:\flutter\flutter\.pub-cache\hosted\pub.dartlang.org\firebase_auth-0.8.0+1\android\src\main\java\io\flutter\plugins\firebaseauth\FirebaseAuthPlugin.java:638: error: cannot find symbol
like image 624
Gbadegesin Taiwo Avatar asked Jan 26 '19 03:01

Gbadegesin Taiwo


2 Answers

Solution

Add: implementation 'androidx.annotation:annotation:1.0.1' to the build.gradle of firebase_auth library. I used Android Studio to see the flutter android app structure.


From Android Studio

enter image description here

Sample Code:

build.graddle(firebase_auth library):
android {
    compileSdkVersion 28

    defaultConfig {
        minSdkVersion 16
        testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
    }
    lintOptions {
        disable 'InvalidPackage'
    }
    dependencies {
        api 'com.google.firebase:firebase-auth:16.0.1'
        implementation 'androidx.annotation:annotation:1.0.1'
    }
}
pubspec.yaml(dependencies)
  flutter:
    sdk: flutter
  rxdart: ^0.20.0
  firebase_core: ^0.3.0
  firebase_analytics: ^2.0.0
  firebase_auth: ^0.8.0+1
  google_sign_in: ^4.0.0
like image 123
ArtiomLK Avatar answered Oct 16 '22 15:10

ArtiomLK


There seems to be a bug in the latest version of some of the Google plugins where they migrated to AndroidX. I've made a pull request with a fix but it likely won't be reviewed before Monday.

A workaround meanwhile is to downgrade to a working version in your pubspec. E.g. I had firebase_storage: ^1.1.0, and after looking at the changelog to identify a previous version, I changed that line to firebase_storage: 1.0.4.

like image 3
Edman Avatar answered Oct 16 '22 16:10

Edman