我正在为我的android应用程序使用dagger 2库,但它没有为生成Daggercomponent类,所以我读到我应该启用注释处理器,但我在android studio 3.1.2中找不到它。它不在设置中,我还将此代码添加到gradle中,但它没有帮助
javaCompileOptions{
annotationProcessorOptions {
includeCompileClasspath true
}
}请注意,我说的是3.1.2版本的.in以前版本的批注处理器在菜单中,但我在这个版本中找不到它
apply plugin: 'com.android.application'
apply plugin: 'kotlin-android'
apply plugin: 'kotlin-android-extensions'
android {
compileSdkVersion 26
defaultConfig {
applicationId "com.example.moein.volley_download_kotlin"
minSdkVersion 21
targetSdkVersion 26
versionCode 1
versionName "1.0"
multiDexEnabled true
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
javaCompileOptions{
annotationProcessorOptions {
includeCompileClasspath true
}
}
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
}
dependencies {
implementation fileTree(include: ['*.jar'], dir: 'libs')
implementation "org.jetbrains.kotlin:kotlin-stdlib-jre7:$kotlin_version"
implementation 'com.android.support:appcompat-v7:26.1.0'
implementation 'com.android.support.constraint:constraint-layout:1.1.0'
testImplementation 'junit:junit:4.12'
androidTestImplementation 'com.android.support.test:runner:1.0.2'
androidTestImplementation 'com.android.support.test.espresso:espresso- core:3.0.2'
implementation 'com.tonyodev.fetch2downloaders:fetch2downloaders:2.0.0-RC21'
implementation 'com.android.volley:volley:1.1.0'
implementation 'com.google.dagger:dagger:2.13'
annotationProcessor 'com.google.dagger:dagger-compiler:2.13'
annotationProcessor 'com.google.dagger:dagger-android-processor:2.13'
}(我在github上的dagger实现代码不想在这里重写:https://github.com/codepath/android_guides/issues/331)
发布于 2018-06-05 02:23:10
如果你在你的项目中使用kotlin,你需要使用kotlin另类处理器。将其添加到gradle文件的开头:
apply plugin: 'kotlin-kapt'使用kapt而不是annotationProcessor
kapt 'com.google.dagger:dagger-compiler:2.13'
kapt 'com.google.dagger:dagger-android-processor:2.13'我正在检查你的dagger设置,这个模块看起来有点不对劲:
@Module
class globals {
lateinit var volleyinstance:VolleyController
fun golobals(volley:VolleyController){
volleyinstance=volley
}
@Provides
@Singleton
fun provideVolley():VolleyController{
return volleyinstance
}}
我没有看到您的volleyController是在任何其他模块中创建的。也许你想这样做:
@Module
class globals {
@Provides
@Singleton
fun provideVolley():VolleyController{
return VolleyController()
}
}https://stackoverflow.com/questions/50686086
复制相似问题