Unable to get provider com.google.firebase.provider.FirebaseInitProvider
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
Solution 1:
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:
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:
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:
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:
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 :)