You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I seen an error saying : java.lang.IllegalStateException: android.content.Context must be set even though I have set context using customizeBuilder. I may be doing something wrong can you please help.
The text was updated successfully, but these errors were encountered:
Hi, why did you define the context method in the RepositoryComponent builder instead of the ApplicationComponent builder? I have never tried this configuration but I think it's the reason of your problem. Can you try to modify the code?
Thanks for your report
Hi Fabio,
Here is my Component and Dependent Component
Main Component
@AppScope
@component(modules = {AndroidInjectionModule.class, ActivityModule.class}, dependencies = RepositoryComponent.class)
public interface ApplicationComponent {
void inject(Application application);
}
Dependent Component
@singleton
@component(modules = RepositoryModule.class)
public interface RepositoryComponent {
ApiService apiService();
@Component.Builder
interface Builder {
RepositoryComponent build();
@BindsInstance
Builder context(@nAmed("ApplicationContext") Context context);
}
}
Custom Dagger Rule
public class DaggerRule extends DaggerMockRule {
public DaggerRule() {
super(ApplicationComponent.class);
customizeBuilder(new BuilderCustomizer<RepositoryComponent.Builder>() {
@OverRide
public RepositoryComponent.Builder customize(RepositoryComponent.Builder builder) {
Application application = (Application) RuntimeEnvironment.application;
return builder.context(application);
}
});
addComponentDependency(RepositoryComponent.class, new RepositoryTestModule());
set(component -> {
Application application = (Application) RuntimeEnvironment.application;
application.setApplicationComponent(component);
});
}
}
I seen an error saying : java.lang.IllegalStateException: android.content.Context must be set even though I have set context using customizeBuilder. I may be doing something wrong can you please help.
The text was updated successfully, but these errors were encountered: