Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Dagger2 does not generate "Dagger_" files [duplicate]

Im using dagger 2 since a while, but today trying to compile got this error:

Error:(13, 31) error: cannot find symbol class Dagger_GlobalComponent

Error:(38, 21) error: cannot find symbol variable Dagger_GlobalComponent

So here is the code:

public class MyAppApplication extends Application {

private static GlobalComponent component;

@Override
public void onCreate() {
    super.onCreate();

    component = Dagger_GlobalComponent.builder()
            .busModule(new BusModule())
            .syncModule(new SyncModule())
            .serviceModule(new ServiceModule())
            .contextModule(new ContextModule(this))
            .persistenceModule(new PersistenceModule(this))
            .build();
}}

And gradle dependencies:

...
compile 'com.google.dagger:dagger:2.0-SNAPSHOT'
apt 'com.google.dagger:dagger-compiler:2.0-SNAPSHOT'
provided 'org.glassfish:javax.annotation:10.0-b28'
...

Any solutions? Already tried to: Clean, Rebuild, Change dependecy versions, also deleting the Gradle cache and reinstalling Android Studio.

If it helps also got the same error with this sample projects:

https://github.com/gk5885/dagger-android-sample

https://github.com/mgrzechocinski/dagger2-example

like image 876
FireZenk Avatar asked Apr 08 '15 10:04

FireZenk


3 Answers

I was trying to follow the Dagger2 tutorial on tutsplus here and ran into the same issue when trying to use the underscore syntax (Dagger_ClassnameComponent).

As others have stated, the new Dagger APIs don't use that underscore syntax, but rather just use the syntax DaggerClassnameComponent. However, on attempting to use the new syntax in my simple app, the class DaggerClassnameComponent was not found. I believe it should be located in the app/build/generated/source/apt/debug/packagename/component folder.

At first, I didn't have any files generated under the above mentioned folder. However, my solution was to clean and build the project, and then I could use the Component class as expected.

like image 98
stack_overflow_user Avatar answered Nov 05 '22 09:11

stack_overflow_user


Dagger 2 has now been released, so you'll need to change your gradle dependencies:

compile 'com.google.dagger:dagger:2.0'
provided 'com.google.dagger:dagger-compiler:2.0'
provided 'org.glassfish:javax.annotation:10.0-b28'
like image 43
steffandroid Avatar answered Nov 05 '22 09:11

steffandroid


Looks like they removed the underscore from the generated stuff. See Dagger2 generated class is all of a sudden missing from Android Studio.

like image 9
Darren Avatar answered Nov 05 '22 09:11

Darren