Collectives™ on Stack Overflow
Find centralized, trusted content and collaborate around the technologies you use most.
Learn more about Collectives
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
Learn more about Teams
I get a
[Dagger/MissingBinding]
error and I can not figure out why on this error.
Here is the full error stack:
error: [Dagger/MissingBinding] java.io.File cannot be provided without
an @Inject constructor or an @Provides-annotated method. java.io.File
is injected at service.KeyStoreService(keyStoreFile)
service.KeyStoreService is injected at
di.Module.WalletRepositoryModule.getWalletRepository(…,
keyStoreService) repository.WalletRepositoryInterface is provided at
di.component.ApplicationComponent.getWalletRepository()
The following
other entry points also depend on it:
dagger.android.AndroidInjector.inject(T)
[di.component.ApplicationComponent ?
di.Module.BindModule_BindStartModule.StartActivitySubcomponent]
dagger.android.AndroidInjector.inject(T)
[di.component.ApplicationComponent ?
di.Module.BindModule_BindAddWalletActivity.AddWalletActivitySubcomponent]
KeyStoreService class:
public class KeyStoreService implements KeyStoreServiceInterface {
private final KeyStore keyStore;
@Inject
public KeyStoreService(File keyStoreFile) {
keyStore = new KeyStore(keyStoreFile.getAbsolutePath(), Geth.LightScryptN, Geth.LightScryptP);
WalletRepositoryModule class:
@Module
public class WalletRepositoryModule {
@Provides
@ApplicationScope
WalletRepositoryInterface getWalletRepository(SharedPreferencesHelper sharedPreferencesHelper, KeyStoreService keyStoreService){
return new WalletRepository(sharedPreferencesHelper, keyStoreService);
ApplicationComponent class:
@ApplicationScope
@Component(modules = {ApplicationContextModule.class,
SharedPreferencesModule.class,
KeyStoreModule.class,
SharedPreferenceHelperModule.class,
AndroidInjectionModule.class,
AndroidsupportInjectionModule.class,
WalletRepositoryModule.class})
public interface ApplicationComponent {
@Component.Builder
interface Builder {
@BindsInstance
Builder application(MyApplication myApplication);
ApplicationComponent build();
void inject(MyApplication myApplication);
@ApplicationContext
Context getApplicationContext();
SharedPreferences getSharedPreferences();
KeyStoreServiceInterface getKeyStoreService();
SharedPreferencesHelper getSharedPreferencesHelper();
WalletRepositoryInterface getWalletRepository();
All the other modules are/was working. It's only after adding WalletRepositoryModule I got this error. Any suggestions?
–
you have to tell Dagger how to resolve File
. I would suggest you a @Provides
@Named
annotated method. EG
@Provides
@Named("KEY_STORE_FILE")
public File provideKeyStoreFile() {
return new File(path/to/keystore)
and change
@Inject
public KeyStoreService(File keyStoreFile) {
@Inject
public KeyStoreService(@Named("KEY_STORE_FILE") File keyStoreFile) {
–
–
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.