Я сталкиваюсь с этим сбоем только на устройстве Kitkat. Мой logcat ниже. Сбой при getViewModel
Fatal Exception: java.lang.NoClassDefFoundError: kotlin.jvm.internal.Intrinsics
at com.transferhome.di.AppModule.provideViewModelFactories(AppModule.kt)
at com.transferhome.di.AppModule_ProvideViewModelFactoriesFactory.provideViewModelFactories(AppModule_ProvideViewModelFactoriesFactory.java:34)
at com.transferhome.di.DaggerAppComponent.getViewModelProviderFactory(DaggerAppComponent.java:281)
at com.transferhome.di.DaggerAppComponent.access$3500(DaggerAppComponent.java:124)
at com.transferhome.di.DaggerAppComponent$SplashActivitySubcomponentImpl.injectSplashActivity(DaggerAppComponent.java:920)
at com.transferhome.di.DaggerAppComponent$SplashActivitySubcomponentImpl.inject(DaggerAppComponent.java:916)
at com.transferhome.di.DaggerAppComponent$SplashActivitySubcomponentImpl.inject(DaggerAppComponent.java:909)
at dagger.android.DispatchingAndroidInjector.maybeInject(DispatchingAndroidInjector.java:113)
at dagger.android.DispatchingAndroidInjector.inject(DispatchingAndroidInjector.java:134)
at dagger.android.AndroidInjection.inject(AndroidInjection.java:63)
at dagger.android.support.DaggerAppCompatActivity.onCreate(DaggerAppCompatActivity.java:41)
at com.transferhome.commons.BaseActivity.onCreate(BaseActivity.kt:41)
at com.transferhome.splash.SplashActivity.onCreate(SplashActivity.kt:38)
, где Splash
class SplashActivity : BaseActivity() {
private lateinit var viewModel: SplashViewModel
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
viewModel = getViewModel()
viewModel.onMoveToNext.listen(this) {
Handler().postDelayed({
openActivityAndClearTask(it)
}, 2000)
}
}
}
BaseActivity.kt
abstract class BaseActivity : DaggerAppCompatActivity() {
@Inject
lateinit var factories: ViewModelProvider.Factory
inline fun <reified T : ViewModel> getViewModel(): T {
return ViewModelProviders.of(this, factories)[T::class.java]
}
}
, где AppModule.kt
@Module
class AppModule {
@Provides
fun provideViewModelFactories(viewModels: Map<Class<out ViewModel>,
@JvmSuppressWildcards Provider<ViewModel>>):
ViewModelProvider.Factory {
return object : ViewModelProvider.Factory {
override fun <T : ViewModel?> create(modelClass: Class<T>): T {
val factory = viewModels[modelClass]?.get() ?: error(
"No factory provided against ${modelClass.name}"
)
@Suppress("UNCHECKED_CAST")
return factory as T
}
}
}
}
РЕДАКТИРОВАТЬ
class App : DaggerApplication() {
override fun applicationInjector(): AndroidInjector<out DaggerApplication> {
return DaggerAppComponent.builder().addContext(this).build()
}
override fun onCreate() {
super.onCreate()
MultiDex.install(this)
}
}