1

I'm having trouble using Firebase authentication in conjunction with FirebaseUI. When I run my application the following problem appears: "Default FirebaseApp is not initialized in this process. Make sure to call FirebaseApp.initializeApp (Context) first."

In my app / build.gradle I have the dependencies:     

     implementation 'com.google.firebase: firebase-core: 16.0.1'
     implementation 'com.google.firebase: firebase-auth: 16.0.1'
     implementation 'com.google.firebase: firebase-database: 16.0.1'
     implementation 'com.firebaseui: firebase-ui-auth: 4.1.0'

and the "apply plugin: 'com.google.gms.google-services" at the end.

in my module / build.gradle I have dependency:         

classpath 'com.google.gms: google-services: 4.1.0'
classpath 'com.android.tools.build:gradle:3.3.0-alpha07'

I have already exported my googleservices.json to the "app" folder. I was left with no options and the problem continues. Any suggestions?

Logcat:

--------- beginning of crash

08-31 19:40:12.718 2865-2865/? E/AndroidRuntime: FATAL EXCEPTION: main
    Process: br.com.luccas.buscaperto, PID: 2865
    java.lang.RuntimeException: Unable to start activity ComponentInfo{br.com.luccas.buscaperto/br.com.luccas.buscaperto.MainActivity}: java.lang.IllegalStateException: Default FirebaseApp is not initialized in this process br.com.luccas.buscaperto. Make sure to call FirebaseApp.initializeApp(Context) first.
        at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2416)
        at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2476)
        at android.app.ActivityThread.-wrap11(ActivityThread.java)
        at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1344)
        at android.os.Handler.dispatchMessage(Handler.java:102)
        at android.os.Looper.loop(Looper.java:148)
        at android.app.ActivityThread.main(ActivityThread.java:5417)
        at java.lang.reflect.Method.invoke(Native Method)
        at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:726)
        at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:616)
     Caused by: java.lang.IllegalStateException: Default FirebaseApp is not initialized in this process br.com.luccas.buscaperto. Make sure to call FirebaseApp.initializeApp(Context) first.
        at com.google.firebase.FirebaseApp.getInstance(SourceFile:218)
        at com.google.firebase.auth.FirebaseAuth.getInstance(Unknown Source)
        at br.com.luccas.buscaperto.MainActivity.instantiateUser(MainActivity.java:89)
        at br.com.luccas.buscaperto.MainActivity.onCreate(MainActivity.java:64)
        at android.app.Activity.performCreate(Activity.java:6237)
        at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1107)
        at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2369)
        at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2476) 
        at android.app.ActivityThread.-wrap11(ActivityThread.java) 
        at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1344) 
        at android.os.Handler.dispatchMessage(Handler.java:102) 
        at android.os.Looper.loop(Looper.java:148) 
        at android.app.ActivityThread.main(ActivityThread.java:5417) 
        at java.lang.reflect.Method.invoke(Native Method) 
        at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:726) 
        at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:616)

my top level gradle:

buildscript {
    ext {
        release = [
                versionName: "6.1.0-rc01",
                versionCode: 6100
        ]

        setup = [
                compileSdk: 28,
                buildTools: "28.0.2",
                minSdk    : 14,
                targetSdk : 28
        ]

        versions = [
                androidX: '1.0.0-rc01'
        ]
    }

    repositories {
        google()
        jcenter()
    }
    dependencies {
        classpath 'com.android.tools.build:gradle:3.3.0-alpha07'
        classpath 'com.google.gms:google-services:4.1.0'
    }
}

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

my app level gradle:

apply plugin: 'com.android.application'

android {
    compileSdkVersion 28
    defaultConfig {
        applicationId "br.com.luccas.buscaperto"
        minSdkVersion 21
        targetSdkVersion 28
        versionCode 1
        versionName "1.0"
        testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
    }
    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
    }
    buildToolsVersion '28.0.2'
}

dependencies {
    implementation fileTree(include: ['*.jar'], dir: 'libs')
    implementation "androidx.legacy:legacy-support-v4:${versions.androidX}"
    implementation "androidx.appcompat:appcompat:${versions.androidX}"
    implementation "androidx.constraintlayout:constraintlayout:${versions.androidX}"
    implementation "androidx.recyclerview:recyclerview:${versions.androidX}"
    implementation "androidx.annotation:annotation:${versions.androidX}"

    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'

    implementation 'com.mikepenz:materialdrawer:6.1.0-rc01'
    implementation "com.google.android.material:material:${versions.androidX}"

    implementation 'com.google.firebase:firebase-core:16.0.3'
    implementation 'com.google.firebase:firebase-auth:16.0.3'
    implementation 'com.google.firebase:firebase-database:16.0.1'
    implementation 'com.firebaseui:firebase-ui-auth:4.1.0'

    implementation 'com.jakewharton:butterknife:8.8.1'
    annotationProcessor 'com.jakewharton:butterknife-compiler:8.8.1'
}
apply plugin: 'com.google.gms.google-services'
Luccas Freitas
  • 41
  • 1
  • 1
  • 9

7 Answers7

4

Please upgrade your project level gms dependencies, I upgraded to 4.2.0 and it worked

classpath 'com.android.tools.build:gradle:3.3.2'
classpath 'com.google.gms:google-services:4.2.0'
Naveed Ahmad
  • 6,627
  • 2
  • 58
  • 83
3

I had same issue and the issue was with google-services.json that was not in proper format and some how, google-services.json had following in the file

COMMENT start clone the project and in firefox create a database and give the package name as .....

Raj
  • 747
  • 1
  • 9
  • 19
1

Try to do like so:

implementation 'com.google.firebase:firebase-core:16.0.3'
implementation 'com.google.firebase:firebase-auth:16.0.3'
implementation 'com.google.firebase:firebase-database:16.0.1'
implementation 'com.firebaseui:firebase-ui-auth:4.1.0

And change this:

classpath 'com.android.tools.build:gradle:3.3.0-alpha07'

to

classpath 'com.android.tools.build:gradle:3.1.4'
Alex Mamo
  • 130,605
  • 17
  • 163
  • 193
  • if I remove the "classpath 'com.android.tools.build:gradle:3.3.0-alpha07", I get the error: Plugin with id 'com.android.application' not found. – Luccas Freitas Sep 03 '18 at 16:50
  • I didn't say to remove it but to change it to `classpath 'com.google.gms:google-services:4.1.0'` Have you tried this approach? – Alex Mamo Sep 03 '18 at 16:53
  • I'm using both: `classpath 'com.google.gms: google-services: 4.1.0' classpath 'com.android.tools.build:gradle:3.3.0-alpha07'` – Luccas Freitas Sep 03 '18 at 17:26
  • No, you need to use only one, the one from my last comment. Does it work this way? – Alex Mamo Sep 03 '18 at 17:28
  • then it says: Plugin with id 'com.android.application' not found. – Luccas Freitas Sep 03 '18 at 18:00
  • In this case update the gradle in your top level `build.gradle` file to `classpath 'com.android.tools.build:gradle:3.1.4'` Does it work now? – Alex Mamo Sep 03 '18 at 18:07
  • I edited the question and attached the build.gradle files – Luccas Freitas Sep 03 '18 at 18:33
  • Remove this `classpath 'com.android.tools.build:gradle:3.3.0-alpha07'` and add this `classpath 'com.android.tools.build:gradle:3.1.4'`. Does it work? – Alex Mamo Sep 03 '18 at 18:36
  • Failed to resolve: androidx.constraintlayout:constraintlayout:1.0.0-rc01 – Luccas Freitas Sep 03 '18 at 18:39
  • I see that you get now another error, which means that basically the inital error disappeared. So your initial problem is now solved. Good to hear that :-) The fact that you are getting now another error should not scare you but this sound as another question. My personal hint is to comment that line of code and add this `implementation 'com.android.support.constraint:constraint-layout:1.1.3'`. – Alex Mamo Sep 03 '18 at 18:48
  • If my above hint doesn't solve the second problem, in order to follow the rules of this comunity, please post another fresh question, so me and other users can help you. – Alex Mamo Sep 03 '18 at 18:48
  • Ok! Thanks for the help – Luccas Freitas Sep 03 '18 at 18:51
  • Actualy I downgraded de version to " classpath 'com.android.tools.build:gradle:3.2.0-alpha14'" and it works! – Luccas Freitas Sep 03 '18 at 19:00
  • I recommend you always use the latest versions but if you say it worked, these are good news, cheers! – Alex Mamo Sep 03 '18 at 19:06
  • 1
    @AlexMamo you are mixing Gradle Build Tools and Google Services Plugin which both does totally different things and later recommend use an old version of build tools... You should check what which do: https://developer.android.com/studio/releases/gradle-plugin and https://developers.google.com/android/guides/google-services-plugin :) – mtrakal Sep 12 '18 at 12:31
  • @mtrakal Oh ya, you're right, my mistake. It should be `classpath 'com.android.tools.build:gradle:3.1.4'`. I have copied and paste the wrong line of code. Sorry about that. Just updated my answer. – Alex Mamo Sep 12 '18 at 12:35
  • 1
    @AlexMamo using 3.1.4 will not solve it when you work with AS 3.2 or 3.3 canary :). Using 3.1.4 is not possible too when you use Gradle 4.6+ :) – mtrakal Sep 12 '18 at 12:38
  • @mtrakal Why do you say that? I've tested with `3.3.0-alpha07` and it doesn't work. – Alex Mamo Sep 12 '18 at 12:39
1

you need to update your google_services.json file. Download it from firebase and replace with the existing one. In json file there is a configuration which automatically merged the content provider which intitalizes your Firebase for the app with your manifest by default on building with gradle. But your current json file is missing that configuration. So you need to replace or you need to call static FirebaseApp(Context) method to solve this problem.Read Here

Add this in your app launcher onCreate method as

...... onCreate(.....)
       {
          FirebaseApp.initializeApp(this);
          ..........   

       }
Faiizii Awan
  • 1,615
  • 1
  • 13
  • 28
0

It works by downgradind to: classpath 'com.android.tools.build:gradle:3.2.0-alpha14'

Luccas Freitas
  • 41
  • 1
  • 1
  • 9
0

I had same issue in my app, but according to https://issuetracker.google.com/issues/112716914 this issue tracker I have updated to version classpath 'com.google.gms:google-services:4.2.0' and issue got resolved.

Amin Pinjari
  • 2,129
  • 3
  • 25
  • 53
-2

Edit your dependencies in build.gradle Project level:

     classpath 'com.android.tools.build:gradle:3.3.2'
     classpath 'com.google.gms:google-services:4.2.0' 

Oncreate method add this:

     FirebaseApp.initializeApp(this);
Dwarkamoye
  • 37
  • 2