Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can not resolve symbol DaggerApplicationComponent

I use Dagger2 with java and I got "Can not resolve symbol DaggerApplicationComponent error in my application." Seems there is something wrong with dependencies. Any help would be really appreciated. My complete code is here- https://github.com/rohitku860/AndroidMvpDagger2

Here is my app graddle with dependencies:

 apply plugin: 'com.android.application'
    android {
    compileSdkVersion 26
    defaultConfig {
        applicationId "com.example.android.androidmvpdagger2"
        minSdkVersion 16
        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 'com.android.support:appcompat-v7:26.1.0'
    implementation 'com.android.support.constraint:constraint-layout:1.0.2'
    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.google.dagger:dagger:2.13'
    annotationProcessor 'com.google.dagger:dagger-compiler:2.13'
    implementation 'com.jakewharton:butterknife:8.5.1'
    annotationProcessor 'com.jakewharton:butterknife-compiler:8.5.1'

}

and here is project one:

        buildscript {

        repositories {
            google()
            jcenter()
        }
        dependencies {
            classpath 'com.android.tools.build:gradle:3.1.0'
        }
    }

        allprojects {
        repositories {
            google()
            jcenter()
        }
    }



           task clean(type: Delete) {
            delete rootProject.buildDir
        }
like image 906
Rohit Upadhyay Avatar asked Apr 01 '18 20:04

Rohit Upadhyay


1 Answers

The proper setup of your Dagger solves this issue.

Update (March 29, 2020)

Inside your app-level build.gradle inside dependencies block, add these lines:

     //dagger2
     api 'com.google.dagger:dagger:2.24'
     api 'com.google.dagger:dagger-android:2.24'
     api 'com.google.dagger:dagger-android-support:2.24'

     annotationProcessor 'com.google.dagger:dagger-compiler:2.24'
     kapt 'com.google.dagger:dagger-compiler:2.24'

     annotationProcessor 'com.google.dagger:dagger-android-processor:2.24'
     kapt 'com.google.dagger:dagger-android-processor:2.24'

     compileOnly 'javax.annotation:jsr250-api:1.0'
     implementation 'javax.inject:javax.inject:1'

Inside android block of app-level build.gradle,

kapt {
        generateStubs = true
    }

At the top of the app-level build.gradle, Do this in exactly below order.

apply plugin: 'com.android.application'
apply plugin: 'kotlin-android'
apply plugin: 'kotlin-kapt'
apply plugin: 'kotlin-android-extensions'

Finally, You need to configure Annotation Process as provided in the screenshot below. You can do this File>Other Settings>Settings for New Projects>search"Annotation processor"

After this, do from Menu Build > Rebuild. You are done!

Test:

@Component
public interface ApplicationComponent {

}

Now, you can use DaggerApplicationComponent that was generated at compile-time for your ApplicationComponent interface.

public class MyApplication extends Application {

    ApplicationComponent applicationComponent = DaggerApplicationComponent.create();


}
like image 182
Uddhav P. Gautam Avatar answered Oct 28 '22 14:10

Uddhav P. Gautam