当我添加代码int activity
时 @Inject
lateinit var mCommonService:CommonService
错误来了
e:错误:无法访问Nullable
e:找不到javax.annotation.Nullable
e:有关详细信息,请参阅以下堆栈跟踪。
w:警告:任何注释处理器都不使用这些选项:'[kapt.kotlin.generated]'
e:处理注释时发生了一些错误。请参阅上面的错误消息。
这是我的模块build.gradle
dependencies {
compile fileTree(include: ['*.jar'], dir: 'libs')
androidTestCompile('com.android.support.test.espresso:espresso-core:2.2.2', {
exclude group: 'com.android.support', module: 'support-annotations'
})
compile 'com.android.support:appcompat-v7:25.3.1'
compile 'com.android.support.constraint:constraint-layout:1.0.2'
testCompile 'junit:junit:4.12'
compile 'com.squareup.retrofit2:retrofit:2.3.0'
compile 'com.squareup.retrofit2:converter-gson:2.3.0'
compile 'com.jakewharton.retrofit:retrofit2-rxjava2-adapter:1.0.0'
compile 'com.squareup.okhttp3:okhttp:3.8.0'
compile 'com.squareup.okhttp3:okhttp-urlconnection:3.8.0'
compile 'io.reactivex.rxjava2:rxjava:2.0.1'
compile 'io.reactivex.rxjava2:rxandroid:2.0.1'
compile 'com.google.dagger:dagger:2.11'
kapt 'com.google.dagger:dagger-compiler:2.11'
compile 'com.readystatesoftware.systembartint:systembartint:1.0.3'
compile 'com.google.code.gson:gson:2.7'
compile 'com.squareup.leakcanary:leakcanary-android:1.5.1'
// compile 'com.android.support:support-annotations:26.0.0-alpha1'
kapt "com.android.databinding:compiler:$rootProject.ext.gradle_version"
compile "org.jetbrains.kotlin:kotlin-stdlib-jre7:$kotlin_version"
}
这是我的组件
@ActivityScope
@Component(modules = arrayOf(CommonModule::class),dependencies = arrayOf(AppComponent::class))
interface CommonComponent {
fun inject(activity: MainActivity)
}
这是我的模块
@Module
class CommonModule {
@Singleton @Provides fun provideCommonService(retrofit: Retrofit): CommonService {
return retrofit.create(CommonService::class.java)
}
}
这是我的活动
@Inject
lateinit var mCommonService:CommonService// when i inject this,the error comes
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
getViewDataBinding(R.layout.activity_main)
DaggerCommonComponent.builder()
.appComponent(appComponent)
.commonModule(CommonModule())
.build()
.inject(this)
}
如果我删除了注入代码,程序运行正常,我尝试在CommomService @provides返回类型中添加@JvmWildcard,但它仍然不起作用