Dagger 2 Error in AppCompatActivity

I'm new to the dagger. I am currently creating a sample project for some abbreviations:

MyComponent.java

@PerActivity @Component(modules = MyModule.class) public interface MyComponent { void inject(TutorialActivity activity); } 

Mymodule.java

 @Module public class MyModule { @Provides Position providePosition() { return new Position(); } } 

PerActivity.java

 @Scope @Retention(RUNTIME) public @interface PerActivity {} 

TutorialActivity.java

 public class TutorialActivity extends AppCompatActivity{} 

When compiling a project, I get an error:

 Error:Execution failed for task ':app:compileDebugJavaWithJavac'. > java.lang.IllegalArgumentException: expected one element but was: <android.support.v4.app.FragmentActivity, android.support.v4.app.TaskStackBuilder.SupportParentable> 

So, if I change the TutorialActivity as:

 public class TutorialActivity extends Activity{} or even public class TutorialActivity{} // Without extends 

Then it will work fine (I see a class created by Dagger2).

Please, help!

Thanks.

UPDATE

My project structure:

  • common .
  • app . (the application module will use the general module as defined in gradle).

In both build.gradle (generic and application module) I added:

 apt "com.google.dagger:dagger-compiler:${daggerVersion}" compile "com.google.dagger:dagger:${daggerVersion}" 

In build.gradle in the general module:

 provide "org.glassfish:javax.annotation:${javaxAnnotationVersion}" 

The error only occurs if I have 2 modules. ( app module depends on common ). If I translate my component / module into a common module -> It works. But when I go to the app module -> Error compiling.

+6
source share
2 answers

Thanks @plash for your answer.

After re-checking for both modules. I found that I added only:

 provide "org.glassfish:javax.annotation:${javaxAnnotationVersion}" 

in the common module.

After I added what to provide for both modules, compile success. (A class created by the dagger.)

0
source

I'm not sure if your problem is with the dagger, because I do not see you request any dependencies in your Android components.

However, you'll need this in build.gradle to use depdendency insert annotations.

  provided 'javax.annotation:jsr250-api:1.0' 
+2
source

All Articles