java.lang.ClassCastException:android.app.Application无法强制转换为com.xxx.xxx.MyApplication

Ped*_*dro 6 android

我在Play商店发布的应用程序崩溃很少发生(<1%),我找不到原因.

应用程序在启动时崩溃,在Play商店控制台中,我使用以下堆栈跟踪记录崩溃:

    at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2707)
    at android.app.ActivityThread.-wrap12(ActivityThread.java)
    at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1460)
    at android.os.Handler.dispatchMessage(Handler.java:102)
    at android.os.Looper.loop(Looper.java:154)
    at android.app.ActivityThread.main(ActivityThread.java:6077)
    at java.lang.reflect.Method.invoke(Method.java)
    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:865)
    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:755)
Caused by: java.lang.ClassCastException: android.app.Application cannot be cast to com.xxx.xxx.MyApplication
    at com.xxx.xxx.activities.BaseActivity.getApplicationComponent(BaseActivity.java:83)
    at com.xxx.xxx.views.activities.BaseActivity.onCreate(BaseActivity.java:65)
    at com.xxx.xxx.views.activities.startup.StartupActivity.onCreate(StartupActivity.java:78)
    at android.app.Activity.performCreate(Activity.java:6664)
    at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1118)
    at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2599)
    ... 9 more
Run Code Online (Sandbox Code Playgroud)

崩溃方法getApplicationComponent如下所示:

public ApplicationComponent getApplicationComponent() {
    return ((MyApplication) getApplication()).getApplicationComponent();
}
Run Code Online (Sandbox Code Playgroud)

清单引用了我的自定义应用程序类:

<application
        android:name=".MyApplication"
Run Code Online (Sandbox Code Playgroud)

该应用程序安装在几十万个设备(相同的apk),它的工作完美.

到目前为止,这似乎只发生在运行Nougat的一些Nexus 5X/6P设备上.

我没有想法.有没有人知道为什么这只会发生几次?

编辑

MyApplication类:

public class MyApplication extends Application {
    private ApplicationComponent applicationComponent;

    @Override
    public void onCreate() {
        super.onCreate();

        this.applicationComponent = this.createApplicationComponentBuilder().build();
    }

    public ApplicationComponent getApplicationComponent() {
        return this.applicationComponent;
    }

    protected DaggerApplicationComponent.Builder createApplicationComponentBuilder() {
        return DaggerApplicationComponent.builder()
                .applicationModule(new ApplicationModule(this));
    }
}
Run Code Online (Sandbox Code Playgroud)