Bharat Kul Ratan Bharat Kul Ratan - 1 year ago 224
Java Question

Dagger 2 giving error '...cannot be provided without an @Provides-annotated method'

I'm trying to build a simple android project for dagger 2 understanding. I currently have the component

@Component(modules = {MyModule.class})
public interface MyComponent {
MyModule provideModule();

public class MyModule {
Repo provideRepo(){
return new Repo();

public class Repo {
private String name;
public String getName() {
return name;
public void setName(String name) { = name;

I've added these to build.gradle for app

apt ''
compile ''
provided 'javax.annotation:jsr250-api:1.0'

Also in dependencies for project I've used this

classpath 'com.neenbedankt.gradle.plugins:android-apt:1.8'

When building the project, I'm getting this error

Error:(10, 14) error: com.example.bharatkulratan.daggernotworking.MyModule cannot be provided without an @Inject constructor or from an @Provides-annotated method.

The error reads out for missing
annotation but

method is already having the annotation of
. I'm unable to figure out the missing part. Please help.

Answer Source

Remove this

MyModule provideModule();

And add this in its place

Repo provideRepo();
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download