【发布时间】:2018-09-18 07:00:15
【问题描述】:
我有以下基类:
abstract class BaseFragment<T : BaseViewModel> : Fragment(), JobHolder {
protected lateinit var viewModel: T
private set
protected fun provideViewModel(type: Class<T>) {
viewModel = ViewModelProviders.of(this).get(type)
}
}
还有以下类:
class SubjectEditor : BaseFragment<SubjectEditorViewModel>() {
override fun onAttach(context: Context?) {
super.onAttach(context)
provideViewModel(SubjectEditorViewModel::class.java)
}
}
但 ProGuard 抱怨:
Warning: cz.x.ui.subjects.SubjectEditor: can't find referenced method 'void setViewModel(cz.x.ui.BaseViewModel)' in program class cz.x.ui.subjects.SubjectEditor
我为 ProGuard 尝试了一些 -keep 规则,但没有任何效果。正确的解决方案是什么?
【问题讨论】: