I had a crash with an application published on the Play Store, which is very rare (<1%), and I canβt find the reason.
The application starts at startup, and in the Play Store console, I crashed with the following stack trace:
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
The getApplicationComponent
drop getApplicationComponent
looks like this:
public ApplicationComponent getApplicationComponent() { return ((MyApplication) getApplication()).getApplicationComponent(); }
And the manifest refers to my own application class:
<application android:name=".MyApplication"
The application is installed in several hundred thousand devices (the same apk), and it works great.
So far, this is similar to some Nexus 5X / 6P devices that work with Nougat.
I have no ideas. Does anyone know why this will happen just a few times?
change
MyApplication Class:
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)); } }
source share