Member-only story
Get Your Hand Dirty With Jetpack Datastore.
It’s time to write some codes.

In the previous blog, I have talked about what Datastore is, why it is created and also made a quick comparison with SharePreference. In this blog, we will see how to implement it.
Configuration
First, we need to configure some dependencies and plugins to our project.
Add this plugin on top of build.gradle file of the desired module:
plugins {
id "com.google.protobuf" version "0.8.12"
}
Next, add the protobuf convention to the same build.gralde file:
protobuf {
protoc {
artifact = "com.google.protobuf:protoc:3.10.0"
}
generateProtoTasks {
all().each { task ->
task.builtins {
java {
option 'lite'
}
}
}
}
}
And then this dependency:
implementation "com.google.protobuf:protobuf-javalite:3.10.0"
All these plugin, convention and library will help to generate java code from protobuf schema.
And now, we add datastore libraries to the project:
// Preferences DataStore
implementation…