I'm in the middle of adding Dagger dependency injection to my Android project. Although Android Studio gives shows me no errors before trying to compile, I cannot get my code to build successfully for some reason.
I use the MVPC strcture for my app and I have implemented it as follows:
public class Application extends com.activeandroid.app.Application {
private static Application instance;
private ApplicationComponent component;
public ApplicationComponent component() {
return component;
}
@Singleton @Component(modules = { AboutActivityModule.class })
public interface ApplicationComponent {
void inject(AboutActivity aboutActivity);
}
@Override
public void onCreate() {
super.onCreate();
instance = this;
component = DaggerApplication_ApplicationComponent.create();
}
}
My module looks so:
@Module public class AboutActivityModule {
@Provides @Singleton AboutActivityPresenter provideAboutActivityPresenter(AboutActivityController aboutActivityController) {
return new AboutActivityPresenter(aboutActivityController);
}
}
Here's my presenter:
public class AboutActivityPresenter {
private AboutActivityController aboutActivityController;
public AboutActivityPresenter(AboutActivityController aboutActivityController) {
this.aboutActivityController = aboutActivityController;
}
public AboutActivityPresenter register(AboutActivityController aboutActivityController) {
this.aboutActivityController = aboutActivityController;
if (aboutActivityController != null) {
aboutActivityController.displayAboutPageFromLocalResources();
aboutActivityController.displayAppVersionNumber();
}
return this;
}
}
My controller:
public interface AboutActivityController{
void displayAboutPageFromLocalResources();
void displayAppVersionNumber();
}
And last, but not least, my activity:
public class AboutActivity extends CringleActivity implements AboutActivityController {
@Inject AboutActivityPresenter presenter;
private ActivityAboutBinding binding;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
((Application) getApplication()).component().inject(this);
setContentView(R.layout.activity_about);
binding = DataBindingUtil.setContentView(this, R.layout.activity_about);
presenter.register(this);
}
@Override
protected void onResume() {
super.onResume();
}
}
When I try to build this, it fails and gives me the following errors:
/yo/yo/yo/yo-yo/yo/yo/yo/yo/yo/yo/yo/yo//FeedbackDialog.java
Error:(18, 39) error: yo.yoyo.yoyoyo.databinding does not exist
/yo/yo/yo/yo-yo/yo/yo/yo/yo/yo/yo/yo/yo/YoFragment.java
Error:(17, 39) error: package yo.yoyo.yoyoyo.databinding does not exist
Error:(31, 5) error: cannot find symbol class FragmentYoBinding
/yo/yo/yo/yo-yo/yo/yo/yo/yo/yo/yo/yo/yo/YoYoActivity.java
Error:(11, 39) error: package yo.yoyo.yoyoyo.databinding does not exist
Error:(57, 13) error: cannot find symbol class ActivityPinlockBinding
As far as I understand, databinding generates code from a compiled package, so if the project I write fails to build, databinding will have nothing to generate code from. I am fairly certain that my problem does not lie in databinding and that I am doing something wrong with Dagger. When I comment out the injection of the presenter in my activity (and of course its registering the activity in onCreate), the whole things builds just fine. Dagger generates the component and provider factory. However, I cannot, for some reason inject the presenter and have a functioning app. I tried injecting an Integer object through the module into the activity, and that worked(!), so I don't understand why I am not able to inject my presenter through my module.