1

I have tried a great deal debugging this issue but unable to find the cause. Dagger simply doesn't create the DaggerComponent classes. I've checked SO for duplicates but none of the solutions provided worked.

project's build.gradle

buildscript {
    repositories {
        jcenter()
    }
    dependencies {
        classpath 'com.android.tools.build:gradle:2.1.0'
        classpath 'me.tatarka:gradle-retrolambda:3.2.3'
        classpath 'com.neenbedankt.gradle.plugins:android-apt:1.8'
        classpath 'me.tatarka:gradle-retrolambda:3.0.1'

        // NOTE: Do not place your application dependencies here; they belong
        // in the individual module build.gradle files
    }
}

allprojects {
    repositories {
        jcenter()
        jcenter {
            url "http://jcenter.bintray.com"
        }
        mavenCentral()
        maven {
            url "https://oss.sonatype.org/content/repositories/snapshots"
        }

    }
}

task clean(type: Delete) {
    delete rootProject.buildDir
}

app's build.gradle

apply plugin: 'com.android.application'
apply plugin: 'com.neenbedankt.android-apt'
apply plugin: 'me.tatarka.retrolambda'


android {
    compileSdkVersion 23
    buildToolsVersion "23.0.2"

    compileOptions {
        sourceCompatibility JavaVersion.VERSION_1_8
        targetCompatibility JavaVersion.VERSION_1_8
    }
    defaultConfig {
        applicationId "com.hr.crux"
        minSdkVersion 18
        targetSdkVersion 23
        versionCode 1
        versionName "1.0"

        testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
    }
    buildTypes {
        debug {

        }
        release {
            minifyEnabled false

            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
    }
}

retrolambda {
    jvmArgs '-noverify'
}

dependencies {
    compile fileTree(dir: 'libs', include: ['*.jar'])

    compile 'com.android.support:appcompat-v7:23.2.1'
    compile 'com.android.support:appcompat-v7:23.1.1'
    compile 'com.android.support:design:23.1.1'
    compile 'com.android.support:recyclerview-v7:23.1.1'
    compile 'com.google.code.gson:gson:2.6.2'
    compile 'com.squareup.retrofit2:retrofit:2.0.2'
    provided 'javax.annotation:jsr250-api:1.0'
    apt 'com.google.dagger:dagger-compiler:2.2'
    compile 'com.google.dagger:dagger:2.2'
    provided 'javax.annotation:jsr250-api:1.0'
    testCompile 'junit:junit:4.12'

}

HttpModule.java

@Module
public class HttpModule {
    @Provides
    @Singleton
    Retrofit getRetrofit() {

        Retrofit retrofit = new Retrofit.Builder()
                .baseUrl("https://maps.googleapis.com/maps/api/place/")
                .build();
        return retrofit;

    }
}

HttpComponent.java

@Singleton
@Component(modules = {HttpModule.class})
public interface HttpComponent {

    void inject(MainActivity activity);

}

Application.java

public class Application extends android.app.Application {

private static Application application;

private HttpComponent appComponent;

@Override
public void onCreate() {
    super.onCreate();
    application = this;
    appComponent = //Cannot find DaggerHttpComponent
}


public static Application getInstance() {
    return application;
}
}

MainActivity.java

public class MainActivity extends AppCompatActivity {

@Inject
Retrofit retrofit;

@Override
protected void onCreate(Bundle savedInstanceState) {

    super.onCreate(savedInstanceState);

    setContentView(R.layout.activity_main);
  }
}

Dagger is failing to generate the component class in my Application class. I've tried clean building, I've tried invalidating cache but nothing works.

humblerookie
  • 4,717
  • 4
  • 25
  • 40
  • is it *failing* with an error, or is it not generating anything and the build itself succeeds? If there is an error, provide the error. – David Medenjak May 09 '16 at 17:54
  • Thanks, but Its not failing with any error. The build succeeds but the DaggerComponent class is never generated – humblerookie May 09 '16 at 17:55
  • Does it generat anything at all? There should be a whole bunch of factories and the sorts. – David Medenjak May 09 '16 at 17:57
  • Nope man its not generating anything.The apt folder is empty which I suppose contains the dagger generated files – humblerookie May 09 '16 at 18:02
  • I just successfully clean built a project with your gradle configuration, so this seems not to be it. Do you know that you have `support:appcompat` included twice? I doubt that this would be the issue, though. – David Medenjak May 09 '16 at 18:20
  • I've removed the same, it doesn't compile all the same. As suggested before I've clean built a lot to no avail – humblerookie May 09 '16 at 19:12
  • 1
    Thanks @David, Finally go it to work removed the duplicate imports and clean built it and removed all other libraries.WIll debug this seems like some library was interfearing and post a proper solution – humblerookie May 10 '16 at 02:32
  • @humblerookie could you share that proper solution ? – oldergod Nov 28 '16 at 06:52

2 Answers2

0

You can start a fresh project by yourself instead of following the tutorial project. If you do so, here is the solution.

These two lines are responsible to generate the compile-time framework in Dagger 2.

compile 'com.google.dagger:dagger:2.14.1'//generates framework in compile time annotationProcessor 'com.google.dagger:dagger-compiler:2.14.1' //generates framework in compile time based on the annotations you provided.

Full setup Dagger

        //dagger 2
        compile 'com.google.dagger:dagger:2.14.1'
        annotationProcessor 'com.google.dagger:dagger-compiler:2.14.1'

        //to enable DaggerActivity, DaggerBroadcastReceiver, DaggerFragment etc classes
        compile 'com.google.dagger:dagger-android:2.14.1'
        annotationProcessor 'com.google.dagger:dagger-android-processor:2.14.1'

        //support libraries with dagger 2
        compile 'com.google.dagger:dagger-android-support:2.14.1'

Note: You need to configure Annotation Process as provided in the screenshot below. You can do this File>Other Settings>Default Settings>search"Annotation processor" enter image description here

Uddhav P. Gautam
  • 7,362
  • 3
  • 47
  • 64
0

As Other threads' Answers does NOT work for me:

I've answered here

Pref -> Editor -> File Types -> Ignore Files And Folders -> Remove "Dagger*.java;"

Alireza Akbari
  • 2,153
  • 2
  • 28
  • 53