Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Unable to inject SharedPreferences. #32

Closed
alex-berdnikov opened this issue Sep 13, 2017 · 3 comments
Closed

Unable to inject SharedPreferences. #32

alex-berdnikov opened this issue Sep 13, 2017 · 3 comments

Comments

@alex-berdnikov
Copy link

PreferencesHelper is not actually used anywhere in the project so the app compiles just fine, but try to inject it or SharedPreferences anywhere and you'll get compilation error:

Error:(22, 17) error: android.content.SharedPreferences cannot be provided without an @Provides-annotated method.
android.content.SharedPreferences is injected at...

@divadvo
Copy link

divadvo commented Jan 17, 2018

How did you solve this problem? I have the same issue..

@alex-berdnikov
Copy link
Author

Hi, to be honest I don't remember it already :)
But I may suggest you check if you use right Context scope.

@divadvo
Copy link

divadvo commented Jan 26, 2018

PR #31 solves this.
Specifically this change:

@Provides
@Singleton
SharedPreferences provideSharedPreference(@ApplicationContext Context context) {
return context.getSharedPreferences(PREF_FILE_NAME, Context.MODE_PRIVATE);
}

https://github.com/androidstarters/android-starter/pull/31/files#diff-12d90704750c0430abb5b207e0f529e6L33

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants