android / android/codelab-android-datastore

Proto DataStore: Unresolved reference dataStore

Open
#27 8 comments 10 reactions 1 assignee Claimed by @mmoczkowski View on GitHub
Dominant language
Kotlin
Stars
240
Forks
113
PR merge metrics
No merged PRs in 30d

Description

### Problem:
I followed every step mentined in the Codelab tutorial [https://developer.android.com/codelabs/android-proto-datastore](https://developer.android.com/codelabs/android-proto-datastore), but Android Studio can't resolve `dataStore` (unable to import `androidx.datastore.dataStore`)

### How to reproduce the issue:
1. Download the base project `git clone https://github.com/googlecodelabs/android-datastore`
2. modify gradle file according to [https://developer.android.com/codelabs/android-proto-datastore#4](https://developer.android.com/codelabs/android-proto-datastore#4)
3. create folder `/app/src/main/proto`
4. create file `user_prefs.proto` in `/app/src/main/proto` according to [https://developer.android.com/codelabs/android-proto-datastore#5](https://developer.android.com/codelabs/android-proto-datastore#5)
5. Build -> Clean Project
6. Build -> Rebuild Project (proto files get successfully generated)
7. Generate `UserPreferencesSerializer` in package `data` and insert Code mentioned in [https://developer.android.com/codelabs/android-proto-datastore#5](https://developer.android.com/codelabs/android-proto-datastore#5)
8. Add all missing imports in class `UserPreferencesSerializer`
9. Modify `TasksActivity` according to [https://developer.android.com/codelabs/android-proto-datastore#6](https://developer.android.com/codelabs/android-proto-datastore#6)

Now Android Studio marks `by dataStore` as `Unresolved reference: dataStore` and I'm also unable to import `import androidx.datastore.dataStore`

```
private val Context.userPreferencesStore: DataStore by dataStore(
fileName = DATA_STORE_FILE_NAME,
serializer = UserPreferencesSerializer
)
```

**Please can someone tell me how I can resolve this issue? I followed every steps mentioned in the tutorial and compared the solution files with my local project, but it still doesn't work.**

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.