0

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)

Moeinh77
  • 347
  • 5
  • 14

1 Answers1

3

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()
 }

 }
Levi Moreira
  • 11,917
  • 4
  • 32
  • 46
  • hey tnx but i did this and it didnt fix the problem any other idea? – Moeinh77 Jun 05 '18 at 04:19
  • Usually the dagger component is generated but not imported automatically. Did you check if you can ctrl+enter to import it after clean building? – Levi Moreira Jun 05 '18 at 06:23
  • tnx, i tried this and still nothing .my android studio gradle has become really slow do you have any idea why? i was just trying to make the dagger work and now gradle has become so slow i reverted everything but still its slow – Moeinh77 Jun 06 '18 at 05:53
  • https://stackoverflow.com/questions/50713883/gradle-is-taking-a-long-time-to-build – Moeinh77 Jun 06 '18 at 06:50
  • this code that you wrote gives me this error: Folder D:\StudioProjects\Volley_Download_KOTLIN\app\build\generated\source\kaptKotlin\debug Folder D:\StudioProjects\Volley_Download_KOTLIN\app\build\generated\source\kaptKotlin\release 3rd-party Gradle plug-ins may be the cause – Moeinh77 Jun 06 '18 at 08:05
  • that is usually a warning, not an error > https://stackoverflow.com/questions/49518223/3rd-party-gradle-plug-ins-may-be-the-cause – Levi Moreira Jun 06 '18 at 11:33
  • Any luck here @Moeinh77? – Levi Moreira Jun 09 '18 at 00:24
  • no unfortunately ,i just doesnt generate it i even installed android studio 2.3 with older gradle 3.3 and it doesnt either – Moeinh77 Jun 09 '18 at 08:02