trOnk12
trOnk12

Reputation: 723

Android Dagger 2 not generating component in java/kotlin project

I really need your help as I can't proceed with my project. The issue I am having is when I try to generate dagger component it seems not available. I use java classes for Dagger component/module and Kotlin classes for the rest of application. I tried it with java only classes and it also doesnt work.

Gradle :

apply plugin: 'com.android.application'

apply plugin: 'kotlin-android'

apply plugin: 'kotlin-android-extensions'

apply plugin: 'kotlin-kapt'

 android {
compileSdkVersion 26
  defaultConfig {
    applicationId "com.example.gebruiker.beertime1"
    minSdkVersion 15
    targetSdkVersion 26
    versionCode 1
    versionName "1.0"
    testInstrumentationRunner 
   "android.support.test.runner.AndroidJUnitRunner"
     }
    buildTypes {
       release {
        minifyEnabled false
        proguardFiles getDefaultProguardFile('proguard-android.txt'), 
'proguard-rules.pro'
    }
}



     }

   dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar'])
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.0.2'

implementation 'com.google.dagger:dagger-android:2.14'
annotationProcessor 'com.google.dagger:dagger-android-processor:2.14'


implementation 'com.google.dagger:dagger:2.14'
annotationProcessor 'com.google.dagger:dagger-compiler:2.14'
kapt 'com.google.dagger:dagger-compiler:2.14'

implementation 'com.squareup.retrofit2:converter-gson:2.3.0'
implementation 'com.squareup.retrofit2:adapter-rxjava2:2.3.0'

implementation 'com.squareup.retrofit2:retrofit:2.3.0'
implementation 'io.reactivex.rxjava2:rxandroid:2.0.2'
implementation 'io.reactivex.rxjava2:rxjava:2.1.9'

testImplementation 'junit:junit:4.12'
androidTestImplementation 'com.android.support.test:runner:1.0.1'
androidTestImplementation 'com.android.support.test.espresso:espresso-
core:3.0.1'
implementation 'com.android.support:recyclerview-v7:26.1.0'
 }

My repository component :

package com.example.gebruiker.beertime1.di;

 import com.example.gebruiker.beertime1.MainScreen.MainActivity;

  import javax.inject.Singleton;

  import dagger.Component;

  @Component(modules = NetworkModule.class)
  public interface RepositoryComponent {
   void inject(MainActivity mainActivity);
 }

My mainactivity component :

@Component(dependencies = RepositoryComponent.class ,modules = 
{AppModule.class,RepositoryModule.class,NetworkModule.class})
 interface MainActivityComponent{

void inject(MainActivity mainActivity);

 }

Upvotes: 3

Views: 1011

Answers (1)

Benjamin
Benjamin

Reputation: 7368

You're using annotationProcessor instead of kapt for some of your dependencies. Change your build.gradle to the following and it should work:

def final dagger_version = '2.14.1'

implementation "com.google.dagger:dagger:${dagger_version}"
implementation "com.google.dagger:dagger-android:${dagger_version}"
implementation "com.google.dagger:dagger-android-support:${dagger_version}"
kapt "com.google.dagger:dagger-compiler:${dagger_version}"
kapt "com.google.dagger:dagger-android-processor:${dagger_version}"

Upvotes: 4

Related Questions