Unable to get provider com.google.firebase.provider.FirebaseInitProvider

Firebase

Firebase Problem Overview


I am testing the new Crash tool: https://firebase.google.com/docs/crash/

After going through the steps, the app launches and it crashes saying:

05-18 17:28:18.870 28743 28743 E AndroidRuntime: java.lang.RuntimeException: Unable to get provider com.google.firebase.provider.FirebaseInitProvider: java.lang.IllegalStateException: Incorrect provider authority in manifest. Most likely due to a missing applicationId variable in application's build.gradle.
05-18 17:28:18.870 28743 28743 E AndroidRuntime: 	at android.app.ActivityThread.installProvider(ActivityThread.java:5156)
05-18 17:28:18.870 28743 28743 E AndroidRuntime: 	at android.app.ActivityThread.installContentProviders(ActivityThread.java:4748)
05-18 17:28:18.870 28743 28743 E AndroidRuntime: 	at android.app.ActivityThread.handleBindApplication(ActivityThread.java:4688)
05-18 17:28:18.870 28743 28743 E AndroidRuntime: 	at android.app.ActivityThread.-wrap1(ActivityThread.java)
05-18 17:28:18.870 28743 28743 E AndroidRuntime: 	at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1405)
05-18 17:28:18.870 28743 28743 E AndroidRuntime: 	at android.os.Handler.dispatchMessage(Handler.java:102)
05-18 17:28:18.870 28743 28743 E AndroidRuntime: 	at android.os.Looper.loop(Looper.java:148)
05-18 17:28:18.870 28743 28743 E AndroidRuntime: 	at android.app.ActivityThread.main(ActivityThread.java:5417)
05-18 17:28:18.870 28743 28743 E AndroidRuntime: 	at java.lang.reflect.Method.invoke(Native Method)
05-18 17:28:18.870 28743 28743 E AndroidRuntime: 	at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:726)
05-18 17:28:18.870 28743 28743 E AndroidRuntime: 	at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:616)
05-18 17:28:18.870 28743 28743 E AndroidRuntime: Caused by: java.lang.IllegalStateException: Incorrect provider authority in manifest. Most likely due to a missing applicationId variable in application's build.gradle.
05-18 17:28:18.870 28743 28743 E AndroidRuntime: 	at com.google.firebase.provider.FirebaseInitProvider.zza(Unknown Source)
05-18 17:28:18.870 28743 28743 E AndroidRuntime: 	at com.google.firebase.provider.FirebaseInitProvider.attachInfo(Unknown Source)
05-18 17:28:18.870 28743 28743 E AndroidRuntime: 	at android.app.ActivityThread.installProvider(ActivityThread.java:5153)
05-18 17:28:18.870 28743 28743 E AndroidRuntime: 	... 10 more

Firebase Solutions


Solution 1 - Firebase

1.

Add the applicationId to the application's build.gradle:

android {
    ...
    defaultConfig {
        applicationId "com.example.my.app"
        ...
    }
}

And than Clean Project -> Build or Rebuild Project


2. If your minSdkVersion <= 20 (https://developer.android.com/studio/build/multidex)

Use Multidex correctly.

application's build.gradle

android {
...               
    defaultConfig {
    ....
        multiDexEnabled true
    }
    ...
}

dependencies {
    implementation 'com.android.support:multidex:1.0.3'
    ...
}

manifest.xml

<application
    ...
    android:name="android.support.multidex.MultiDexApplication" >
    ...

3.

If you use a custom Application class

public class MyApplication extends MultiDexApplication {
    @Override
    protected void attachBaseContext(Context context) {
        super.attachBaseContext(context);
        MultiDex.install(this);
    }
}

manifest.xml

<application
    ...
    android:name="com.example.my.app.MyApplication" >
    ...

Solution 2 - Firebase

I was with the same problem in devices with SDK < 22, but for me the reason is the MultiDex, the MultiDex.install must be in the attachBaseContext method.

If you are using MultiDex, try this:

public class YourApplication extends Application {

    @Override
    protected void attachBaseContext(Context context) {
        super.attachBaseContext(context);
        MultiDex.install(this);
    }
    @Override
    public void onCreate() {
        super.onCreate();
        Realm.init(this); //initialize other plugins 

    }
}

app/build.gradle:

android {

    compileSdkVersion 24
    buildToolsVersion "24.0.2"

    defaultConfig {
        applicationId "com.test.app"
        minSdkVersion 16
        targetSdkVersion 24
        versionCode 1
        versionName "1.0"
        multiDexEnabled true

    }

    dexOptions {
        javaMaxHeapSize "4g"
    }

....
}

    dependencies {
        compile fileTree(dir: 'libs', include: ['*.jar'])
    
        compile 'com.android.support:appcompat-v7:24.2.1'
        ...
        compile 'com.google.firebase:firebase-messaging:9.6.1'
        compile 'com.google.android.gms:play-services:9.6.1'
        compile 'com.android.support:multidex:1.0.1'
    
    }
...

Solution 3 - Firebase

The accepted answer didn't solve my problem.

If you are using Multidex, your Application should extends MultiDexApplication instead of Application.

MyApplication.java

public class MyApplication extends MultiDexApplication{
     ...
}

AndroidManifest.xml

<application
      android:name="your.package.name.MyApplication"
      android:allowBackup="true"
      android:icon="@mipmap/ic_launcher"
      ...
      />

Hope it helps.

Solution 4 - Firebase

If you get the same problem but already have the applicationId set in build.gradle, you can also try the following:

  • in Android Studio: Build > Clean Project
  • in other IDEs: Clean, Rebuild, whatever...

Solution 5 - Firebase

I had the same problem in Pre Lollipop devices. To solve that I did as follows. Meantime I was using multiDex in the project.

  1. add this for build.gradle in module: app

    multiDexEnabled = true

    dexOptions { javaMaxHeapSize "4g" }

  2. add this dependancy

    compile 'com.android.support:multidex:1.0.1'

3.Then in the MainApplication

public class MainApplication extends MultiDexApplication {

private static MainApplication mainApplication;

@Override
public void onCreate() {
    super.onCreate();
    mainApplication = this;
}

@Override
protected void attachBaseContext(Context context) {
    super.attachBaseContext(context);
    MultiDex.install(this);
}


public static synchronized MainApplication getInstance() {
    return mainApplication;
}
}

4.In the manifests file

<application
    android:allowBackup="true"
    android:name="android.support.multidex.MultiDexApplication"

This works for me. Hope this Helps you too :)

Solution 6 - Firebase

you should be sure

to add this line at your manifest

https://developer.android.com/studio/run/index.html#instant-run

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="com.example.android.multidex.myapplication">
    <application
        ...
        android:name="android.support.multidex.MultiDexApplication">
        ...
    </application>
</manifest>

Solution 7 - Firebase

Don't include the whole play services library but use the one that you need.Replace the line in your build.gradle:

compile 'com.google.android.gms:play-services:9.6.1'

with the appropriate one from Google Play Services APIs,like for example:

compile 'com.google.android.gms:play-services-gcm:9.6.1'

Solution 8 - Firebase

Add this to your module-level build.gradle :

android {               
defaultConfig {
    ....
    multiDexEnabled true
}
...
}

dependencies {
    compile 'com.android.support:multidex:1.0.1'
    .........
}

If you override Application class then extend it from MultiDexApplication :

YourApplicationClass extends MultiDexApplication

If you cant extend it from MultiDexApplication class then override attachBaseContext() method as following :

protected void attachBaseContext(Context base) {
     super.attachBaseContext(context);
     Multidex.install(this);
  }

And dont run anything before MultiDex.install(this) is executed.

If you dont override the Application class simply edit your manifest file as following :

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    .......>
     <application
         ......
            android:name="android.support.multidex.MultiDexApplication" >
        ...
    </application>
    ......
</manifest>

Solution 9 - Firebase

This should works:

Step1:

defaultConfig {
    applicationId "service.ingreens.com.gpsautoon"
    minSdkVersion 17
    targetSdkVersion 25
    versionCode 1
    versionName "1.0"
    multiDexEnabled true
    testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
}

Step 2:

compile 'com.android.support:multidex:1.0.1'

Step 3: Take another class

public class MyApplication extends MultiDexApplication {
}

Step 4: Add this line on manifest

<application
    android:name="android.support.multidex.MultiDexApplication">
</application>

Solution 10 - Firebase

In my case, the problem was solved by adding this line to the module build.gradle:

// ADD THIS AT THE BOTTOM

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

[Source][1]

[1]: https://firebase.google.com/docs/android/setup "Source"

Solution 11 - Firebase

For react native app, the error was java.lang.RuntimeException: Unable to get provider com.google.firebase.provider.FirebaseInitProvider: java.lang.ClassNotFoundException: Didn't find class "com.google.firebase.provider.FirebaseInitProvider" It was only getting for devices with Android Version < ~4.4

Solved it by just replacing Application in MainApplication.java with MultiDexApplication

NOTE: import android.support.multidex.MultiDexApplication;

Solution 12 - Firebase

In my case the problem happened after we migrated to AndroidX. For some reason, app was calling MultiDex.install() with reflection:

    final Class<?> clazz = Class.forName("android.support.multidex.MultiDex");
    final Method method = clazz.getDeclaredMethod("install", Context.class);
    method.invoke(null, this);

I changed package from android.support.multidex.MultiDex to androidx.multidex.MultiDex. It worked.

Solution 13 - Firebase

Instead of manually adding the package name on the build.gradle, you can do it this way:

first add this line at the beggining

import java.util.regex.Pattern

Then add this on the defaultConfig

android {
    ...
    defaultConfig {
        ...
        applicationId = doExtractStringFromManifest("package")
        ...
    }
    ...
}

And finally add the doExtractStringFromManifest method

def doExtractStringFromManifest(name) {
     def manifestFile = file(android.sourceSets.main.manifest.srcFile)
     def pattern = Pattern.compile(name + "=\"(\\S+)\"")
     def matcher = pattern.matcher(manifestFile.getText())
     matcher.find()
     return matcher.group(1)
}

As there are a lot of Cordova comments on the answer, if you are working with Cordova, you shouldn't really edit the build.gradle yourself, it has a comment at the beggining that say > // GENERATED FILE! DO NOT EDIT!

So, if you are using a Cordova, the best thing you can do is to update to cordova-android 5.1.0 or greater where this changes are already present.

Solution 14 - Firebase

Mine was because Firebase SDK in Gradle file was set to a wrong number version.

I removed the Firebase debs from Gradle and re-installed them again using Firebase Assistant

Solution 15 - Firebase

Go to android studio setting (by pressing Ctrl+Alt+S in windows), search for Instant Run and uncheck Enable Instant Run.

By disabling Instant Run and running your application again, problem will be resolved.

Solution 16 - Firebase

I added the following code in proguard file.

-keep public class * extends android.app.Activity
-keep public class * extends android.app.Application

and it worked in my case.

Solution 17 - Firebase

in my case, I forget to add (or deleted accidentally) firebase core in build gradle

implementation 'com.google.firebase:firebase-core:xx.x.x'

Solution 18 - Firebase

I've got this error just on devices with API lower that 21. In my case, I have had to work with a project where multiDexEnabled option in build.gradle was already set to true. I checked dex file from APK and referenced methods number was less than 64k, so project doesn't need to be a multidex one, therefore I set multiDexEnabled to false. This solution worked for me.

Solution 19 - Firebase

I had the same issue and fixed by using project level crashlytics gradle version 2.1.1

classpath 'com.google.firebase:firebase-crashlytics-gradle:2.1.1'

Solution 20 - Firebase

If you enable "multidex" then the issue will be resolved but this issue is all about Android studio cache. So before adding "multidex" clear cache hope the issue will be resolved.

Delete .gradle, .idea and .build file after that clean cache.

Android studio > File > Invalidate Caches / Restart

enter image description here

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionMacarseView Question on Stackoverflow
Solution 1 - FirebasenorbDEVView Answer on Stackoverflow
Solution 2 - FirebaseluizMelloView Answer on Stackoverflow
Solution 3 - FirebaseYe Min HtutView Answer on Stackoverflow
Solution 4 - FirebaseBarthyView Answer on Stackoverflow
Solution 5 - Firebasethilina KjView Answer on Stackoverflow
Solution 6 - FirebaseJuan SalamancaView Answer on Stackoverflow
Solution 7 - FirebaseAyanView Answer on Stackoverflow
Solution 8 - FirebaseNurlan SofiyevView Answer on Stackoverflow
Solution 9 - FirebaseSoumen DasView Answer on Stackoverflow
Solution 10 - FirebaseBorjaView Answer on Stackoverflow
Solution 11 - FirebaseMalithView Answer on Stackoverflow
Solution 12 - FirebasecgrView Answer on Stackoverflow
Solution 13 - FirebasejcesarmobileView Answer on Stackoverflow
Solution 14 - FirebaseSuhaibView Answer on Stackoverflow
Solution 15 - FirebaseVSBView Answer on Stackoverflow
Solution 16 - FirebaseAnanta PrasadView Answer on Stackoverflow
Solution 17 - FirebaseAlexa289View Answer on Stackoverflow
Solution 18 - FirebaseCristianBananView Answer on Stackoverflow
Solution 19 - FirebaseAmir RazaView Answer on Stackoverflow
Solution 20 - FirebaseMd Imran ChoudhuryView Answer on Stackoverflow