我尝试在应用中使用dagger-reflect来提高应用调试版本的构建速度。
不幸的是,我的应用程序在运行时崩溃并显示堆栈跟踪,并显示以下错误:
@model Loek.Business.ViewModels.Companies.CurrentCompanyProfileViewModel.CompanyAddressViewModel2
@model Loek.Business.ViewModels.Companies.CurrentCompanyProfileViewModel.CompanyAddressViewModel2
@model Loek.Business.ViewModels.Companies.CurrentCompanyProfileViewModel
用kotlin编写的MyClass看起来像这样:
java.lang.IllegalStateException: com.example.MyClass defines multiple
@Inject-annotations constructors
并且我使用像这样的dagger模块提供主机:
class MyClass @Inject constructor(@HostQualifier host: String = "")
答案 0 :(得分:0)
问题在于在注入的构造函数中使用kotlin的默认值。
这样的代码:
class MyClass @Inject constructor(@HostQualifier host: String = "")
生成带有@Inject
批注的第二个构造函数。
这就是它导致异常的原因:
MyClass defines multiple @Inject-annotations constructors
解决方案只是从构造函数中删除默认值:
class MyClass @Inject constructor(@HostQualifier host: String)