Reputation: 377
i'm using dagger 2 library for my android app but it doesn't generate the Daggercomponent class for so i read that i should enable annotation processor but i cant find it anywhere in android studio 3.1.2 its not in settings i also added this code to gradle and it didn't help
javaCompileOptions{
annotationProcessorOptions {
includeCompileClasspath true
}
}
please pay attention that i'm talking abut 3.1.2 version .in previous version annotation processor is in menu but i cant find it in this version
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'
}
(my dagger implementation code on github did'nt want to rewrite here :https://github.com/codepath/android_guides/issues/331)
Upvotes: 0
Views: 477
Reputation: 11995
If you're using kotlin in your project, you need to use the kotlin anotation processor. Add it to the begining of your gradle file:
apply plugin: 'kotlin-kapt'
and instead of using annotationProcessor
use kapt
:
kapt 'com.google.dagger:dagger-compiler:2.13'
kapt 'com.google.dagger:dagger-android-processor:2.13'
I was checking your dagger setup and this module seems to be a bit off:
@Module
class globals {
lateinit var volleyinstance:VolleyController
fun golobals(volley:VolleyController){
volleyinstance=volley
}
@Provides
@Singleton
fun provideVolley():VolleyController{
return volleyinstance
}
}
I don't see your volleyController being created in any other module. Maybe you wanted to do something like:
@Module
class globals {
@Provides
@Singleton
fun provideVolley():VolleyController{
return VolleyController()
}
}
Upvotes: 3