Dagger2 not generating Daggercomponent classes

强颜欢笑 提交于 2019-12-12 11:14:48

问题


Dagger2 is not generating any component classes in android studio i know its a known problem while i have gone through almost all ways to implement in my android studio and have tried on various tutorials but every time i got struck here, it fails to build the daggercomponent class . I have also tried to rebuild ,clean gradles and invalidate caches but it does not help . Here is my one of sample project build.gradle

buildscript {
repositories {
    jcenter()
}
dependencies {
    classpath 'com.neenbedankt.gradle.plugins:android-apt:1.8'

   }
}
apply plugin: 'com.android.application'
apply plugin: 'com.neenbedankt.android-apt'

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

repositories{
maven{url "https://jetpack.io"}
}

dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
androidTestCompile('com.android.support.test.espresso:espresso-core:2.2.2', {
    exclude group: 'com.android.support', module: 'support-annotations'
})
compile 'com.android.support:appcompat-v7:25.1.0'
testCompile 'junit:junit:4.12'
compile 'com.google.dagger:dagger:2.0.2'
apt 'com.google.dagger:dagger-compiler:2.0.2'
provided 'javax.annotation:jsr250-api:1.0'
}

vehiclemodule.java

@Module
public class vehiclemodule {
@Provides
@Singleton
Motor providesMotor(){
    return new Motor();
}
@Provides
@Singleton
Vehicle provideVehicle(){
    return new Vehicle(new Motor());
}
}

vehicleComponent.java

 @Singleton
 @Component(modules = {vehiclemodule.class})
public interface VehicleComponent {
Vehicle provideVehicle();
 }

Is there any problem in the android studio or i am doing something wrong?


回答1:


Is there any problem in the android studio or i am doing something wrong?

If nothing is being generated then you most likely do not have annotation processing enabled:




回答2:


You also need to have modules, and build them. Please check this full tutorial

https://github.com/codepath/android_guides/wiki/Dependency-Injection-with-Dagger-2



来源:https://stackoverflow.com/questions/41855361/dagger2-not-generating-daggercomponent-classes

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!