0

Flutter firebase auth UI have some issue, because of firebase_auth version miss match issue

My flutter app crashed and unable to identify an issue, after opening in an android studio, I got the issue and it is here

Caused by: java.lang.IllegalStateException: Default FirebaseApp is not initialized in this process com.mycom.mypetshop. Make sure to call FirebaseApp.initializeApp(Context) first.
        at com.google.firebase.FirebaseApp.getInstance(com.google.firebase:firebase-common@@16.0.2:240)
        at com.google.firebase.auth.FirebaseAuth.getInstance(Unknown Source)
        at io.flutter.plugins.firebaseauth.FirebaseAuthPlugin.<init>(FirebaseAuthPlugin.java:54)
        at io.flutter.plugins.firebaseauth.FirebaseAuthPlugin.registerWith(FirebaseAuthPlugin.java:47)
        at io.flutter.plugins.GeneratedPluginRegistrant.registerWith(GeneratedPluginRegistrant.java:20)
        at com.vyapari2online.mypetshop.MainActivity.onCreate(MainActivity.java:11)
        at android.app.Activity.performCreate(Activity.java:5990)

How to solve this?

In project 'app' a resolved Google Play services library dependency depends on another at an exact version (e.g. "[15.0. 1]", but isn't being resolved to that version. Behavior exhibited by the library will be unknown.

Dependency failing: com.google.android.gms:play-services-flags:15.0.1 -> com.google.android.gms:play-services-basement@[ 15.0.1], but play-services-basement version was 16.0.1.

The following dependencies are project dependencies that are direct or have transitive dependencies that lead to the art ifact with the issue. -- Project 'app' depends on project 'firebase_auth' which depends onto com.google.firebase:[email protected] -- Project 'app' depends on project 'firebase_core' which depends onto com.google.firebase:[email protected] -- Project 'app' depends on project 'cloud_firestore' which depends onto com.google.firebase:[email protected] -- Project 'app' depends on project 'google_sign_in' which depends onto com.google.android.gms:[email protected]

For extended debugging info execute Gradle from the command line with ./gradlew --info :app:assembleDebug to see the dep endency paths to the artifact. This error message came from the google-services Gradle plugin, report issues at https:// github.com/google/play-services-plugins and disable by adding "googleServices { disableVersionCheck = false }" to your b uild.gradle file.

#flutter_firebase_ui have a lot of issues #google please hire me, I can help your developers

1
  • How are you getting on with the below, Midhilaj? Commented Dec 29, 2018 at 19:43

3 Answers 3

1

Dependency Configuration

For the gradle issue, make sure your Android SDK and Firebase/Firestore plugins are compatible versions are compatible. Here's what worked for me:

dependencies {
        classpath 'com.android.tools.build:gradle:3.2.1'
        classpath 'com.google.gms:google-services:4.2.0'
        classpath 'com.google.firebase:firebase-auth:16.0.5'
}

In the module/app build.gradle:

android {
    compileSdkVersion 27

    lintOptions {
        disable 'InvalidPackage'
    }

    defaultConfig {
        // TODO: Specify your own unique Application ID (https://developer.android.com/studio/build/application-id.html).
        applicationId "com.timeswap.timeswapcore"
        minSdkVersion 17
        targetSdkVersion 27
        versionCode flutterVersionCode.toInteger()
        versionName flutterVersionName
        multiDexEnabled true
        testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
    }

...
}

Specifically, pay attention to the compileSdkVersion, targetSdkVersion, and the version numbers of google-services and firebase_auth. Fiddling with those numbers eventually led me to this config, and it may help you find your appropriate config.

Firebase or Firestore Initialization

As for the App initialization, I have this

Firestore firestore = Firestore.instance;
firestore.settings(timestampsInSnapshotsEnabled: true);

in my _initFirestore, which is called right after super.initState()

@override
void initState() {
    super.initState();
    _initFirestore();
    checkCurrentUser();
}

Firebase (and all other Firebase plugins that I've used) is initialized similarly, but with the firebase_core: dependency instead of cloud_firestore: in pubspec.yaml.

For instance, from the flutter/plugins/packages/firebase_storage GitHub repo:

void main() async {
  final FirebaseApp app = await FirebaseApp.configure(
    name: 'test',
    options: FirebaseOptions(
      googleAppID: Platform.isIOS
          ? '1:159623150305:ios:4a213ef3dbd8997b'
          : '1:159623150305:android:ef48439a0cc0263d',
      gcmSenderID: '159623150305',
      apiKey: 'AIzaSyChk3KEG7QYrs4kQPLP1tjJNxBTbfCAdgg',
      projectID: 'flutter-firebase-plugins',
    ),
  );
  final FirebaseStorage storage = FirebaseStorage(
      app: app, storageBucket: 'gs://flutter-firebase-plugins.appspot.com');
  runApp(MyApp(storage: storage));
}

You can also use this Medium post as a guide to get started with the flutter Firebase Auth UI.

For future reference, you can navigate to flutter/plugins/packages/{package name} on Github and find main.dart inside of examples/lib for a demo. Feel free to leverage this to solve your dependency issue as well!

Sign up to request clarification or add additional context in comments.

Comments

0

You need to initialize the FirebaseApp before using it. You can add it to your onCreate method.

@Override
public void onCreate() {
    super.onCreate();
    FirebaseApp.initializeApp(this);
}

Also make sure you have the dependency in your build.gradle

dependencies {
    ....
}

apply plugin: 'com.google.gms.google-services'

Comments

0

I also face same issue and solved by adding Facebook app id in AndroidManifest.xml Try run Android app with Android studio you will get the error message

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.