问题:
项目接入Hilt后编译时报ClassCastException错误:
Caused by: java.lang.ClassCastException: com.agile.base.DaggerBaseApplication_HiltComponents_SingletonC$ActivityRetainedCImpl$ActivityCImpl cannot be cast to com.example.myapplication.MainActivity_GeneratedInjector
at com.example.myapplication.Hilt_MainActivity.inject(Hilt_MainActivity.java:67)
at com.example.myapplication.Hilt_MainActivity$1.onContextAvailable(Hilt_MainActivity.java:38)
at androidx.activity.contextaware.ContextAwareHelper.dispatchOnContextAvailable(ContextAwareHelper.java:99)
at androidx.activity.ComponentActivity.onCreate(ComponentActivity.java:322)
at androidx.fragment.app.FragmentActivity.onCreate(FragmentActivity.java:273)
at com.example.myapplication.MainActivity.onCreate(MainActivity.kt:22)
原因:
BaseApplication存在另一个模块中
解决办法:
将BaseApplication移到主项目模块中