当前位置: 首页 > 知识库问答 >
问题:

无法获取提供程序com.google.火基。供应商。FirebaseInitProvider

黄弘盛
2023-03-14

我正在测试新的崩溃工具:https://firebase.google.com/docs/crash/

完成步骤后,应用程序启动,它崩溃了,说:

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

共有3个答案

陶俊晤
2023-03-14

公认的答案并没有解决我的问题。

如果您使用的是Multidex,您的应用程序应该扩展MultiDexApplication,而不是Application

我的申请。JAVA

public class MyApplication extends MultiDexApplication{
     ...
}

AndroidManifest。xml

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

希望能有帮助。

於和志
2023-03-14

我在使用SDK的设备中遇到了同样的问题

如果您使用的是MultiDex,请尝试以下操作:

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 

    }
}

应用程序/构建。格拉德尔:

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'

    }
...
祖迪
2023-03-14

1.

将应用程序ID添加到应用程序的build.gradle:

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

而不是清洁项目-

2.如果你的minSdkVersion

正确使用多重索引。

应用程序的构建。格拉德尔

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

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

显示xml

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

3.

如果使用自定义Application类

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

显示xml

<application
    ...
    android:name="com.example.my.app.MyApplication" >
    ...
 类似资料: