相关文章推荐
睿智的眼镜  ·  sqldataadapter fill ...·  1 年前    · 
坚强的打火机  ·  Document对象 - ...·  1 年前    · 
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?

Some people stumbling upon this from Google might have the same problem I did: Lombok can be very inconsistent in its compatibility with Dagger. If you're generating the injected constructor, always start troubleshooting by writing out the constructor manually. – forresthopkinsa Sep 6, 2022 at 17:21

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! I worked. Just some quick follow up questions, if you have time.  Why did this error occur after adding WalletrepositoryModule and not before that? It didnt need to be "@Named" ealier and did not throw any errors. Could I use Qualifier instead of "@Named", and could I take care of the naming/qualifying in the modules instead so I don't have to have "@Named/@Qualifier" in my Keystoreservice class?
– CJR
                Dec 4, 2018 at 15:31
                because WalletRepositoryInterface has KeyStoreService as dependency. You could use an annotated @Provides method that returns a KeyStoreService dependencies. In the method you will have to call the new KeyStoreService manually
– Blackbelt
                Dec 4, 2018 at 15:35
        

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.