Unable to get provider com.google.firebase.provider.FirebaseInitProvider
Asked Answered
R

20

172

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
Rollandrollaway answered 19/5, 2016 at 0:31 Comment(6)
Do you have an applicationID in your build.gradle?Ameeameer
@IanBarber: Oh wow, while editing build.gradle I removed it. My bad.Rollandrollaway
only https://mcmap.net/q/113012/-getting-exception-java-lang-noclassdeffounderror-com-google-firebase-firebaseoptions-after-updating-to-the-new-firebase worked for meHight
Try Android studio > Build > Clean ProjectSecretary
I Fixed it by Making my application class extend MultiDexApplication when multiDexEnabled is true in app's graddle defaultConfig.Winegrower
This error shown up to me even though I am not using Firebase on my projectTribade
P
163

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" >
    ...
Persevere answered 19/5, 2016 at 8:33 Comment(12)
I got the same error and it has been fixed by the solution. I don't know the why, but it works.Cordey
This saved the day for me. Got the error while I was trying to run a Cordova app to an android device.Relic
I have the same problem and the applicationId on my build.gradle. What can I do in that case?Subset
@ekonstantinidis How did you fix it for your cordova app? Can it be added to a config somewhere that correctly adds it when build.gradle is generated? (During cordova platform add android) ?Harriettharrietta
@Harriettharrietta I don't think so. I added it after I ran cordova platform add android. I guess it will get fixed once cordova gets an updated? Ps. I'm not using Firebase at all.Relic
I have to comment, that, in my case it doen't work, even more, I got the applicationId in the build.gradle before I implemented the FCM .. is there any other knwon solution?Minaminabe
@Barthy I tested it, but didnt worked. Even though, I solve the problem. Was some kind of pc errror. I get BLue Screen on windows, it restored some files, etc, and worked again all the project :/ . With Windows.. my mind is going to explode some day.. XDMinaminabe
Strange that this didn't get set, never had this issue before. Thanks for the fix.Sampler
Accurate answer, thanks, worked for me... but, missing an explanation, why? And how did you figured it out?Liggins
I had force close on application start on API 15 and this solution wiped it out.Instil
This answer is no longer functional in 2020Morrow
What do do if I'm getting this error inside another library module, where I cannot add the applicationId?Ardenardency
P
94

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'

    }
...
Pickard answered 10/10, 2016 at 23:55 Comment(6)
It works, but there's a special class to do that instead of overriding one function and it's called MultiDexApplication, see answer below #37312603Quinine
Yeah it worked for me also, I always writing MultiDex.install(this) inside onCreate() method thanks dudeDana
in my case I just updated compile 'com.android.support:multidex:1.0.1' to last available versionSephira
This should be the accepted answer. I tried all the other answers and was following Google and Firebase guides but this is the correct one, you're awesome man!Region
Thanks , how can you found it? but my question is my code lines app is not upper than 65000 why i should use it multudex and why i work on sdk>22 and it does not work on sdk<22Leggat
If your minSdk is 21 or higher, you shouldn't have to do any of this as the docs say it's already enabled by default. And yet, this problem is coming for me with minSdk = 21, any solutions for this?Morrow
S
75

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.

Swizzle answered 15/11, 2016 at 6:23 Comment(4)
Worked perfectly! Thanks alot :)Partizan
How do you know these things?? Who told you??? I just started having this issue after updating to Android Studio 3 and installing "debug" apps. The "Release" version worked well. Now, with your solution also works the "Debug" version. I am so happy people like you exist!!Bicyclic
That's perfect answerAlidaalidade
In all of these answers, none actually explains what adding multidex actually does to solve the problem (a perplexingly random thing to do in the face of such an issue)Morrow
S
37

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...
  • delete the build directory and possibly other caches or intermediate build files
Spoofery answered 12/6, 2016 at 17:1 Comment(3)
And if you still have issues, delete the build directory and try again. I was stuck until I did that :)Withoutdoors
Only deleting build directory worked for me. Seems like it was messed up by my last pull from the repo.Bonanno
Deleting the build directory was the only solution for meBaluchi
L
18

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 :)

Lynch answered 14/3, 2017 at 13:7 Comment(2)
You shouldn't do all three jobs (extend MultiDexApplication, implement attacheBaseContext and change the menifest file) in order to make enable multidex only one is enough :D. developer.android.com/studio/build/multidex.htmlBerl
If your minSdk is 21 or higher, you shouldn't have to do any of this as the docs say it's already enabled by default. And yet, this problem is coming for me with minSdk = 21, any solutions for this?Morrow
B
15

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>
Badger answered 15/12, 2016 at 2:13 Comment(1)
Worked for me too along with multiDexEnabled trueMetternich
S
7

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'
Seton answered 14/10, 2016 at 10:17 Comment(0)
M
7

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>
Margaret answered 11/2, 2017 at 0:18 Comment(0)
S
3

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>
Susannsusanna answered 16/2, 2017 at 12:36 Comment(0)
E
2

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

Elbe answered 7/9, 2016 at 11:42 Comment(2)
I got "Plugin with id 'com.google.gms.play-services' not found."Glottochronology
@Glottochronology put this in yout project build.gradle dependencies { classpath 'com.google.gms:google-services:3.0.0' }Elbe
E
1

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;

Encounter answered 19/6, 2019 at 23:56 Comment(0)
C
1

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.

Chaim answered 19/7, 2019 at 11:15 Comment(0)
S
1

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

Shepp answered 14/6, 2021 at 13:40 Comment(0)
G
0

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.

Gunpowder answered 15/6, 2016 at 10:16 Comment(0)
K
0

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

Keyway answered 2/8, 2017 at 17:43 Comment(0)
A
0

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.

Aloeswood answered 8/11, 2018 at 18:23 Comment(0)
P
0

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.

Piscatory answered 27/9, 2019 at 12:15 Comment(0)
M
0

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

implementation 'com.google.firebase:firebase-core:xx.x.x'
Melva answered 12/11, 2019 at 7:21 Comment(1)
3 months have passed and this is now deprecated: DO NOT ADD THIS! Source = firebase.google.com/support/release-notes/android (Obligatory: Thanks Google)Morrow
H
0

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.

Harty answered 3/12, 2019 at 12:15 Comment(0)
R
0

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'
Regalado answered 4/11, 2020 at 12:14 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.