此版本(beta01)中没有DataStore 和preferencesDataStore。
答案 0 :(得分:2)
为此,您需要:
plugins {
id("com.google.protobuf")
}
protobuf {
protoc {
artifact = "com.google.protobuf:protoc:3.17.3"
}
generateProtoTasks {
all().forEach { task ->
task.builtins {
create("java") {
option("lite")
}
}
}
}
implementation("androidx.datastore:datastore-core:1.0.0-beta01")
implementation("com.google.protobuf:protobuf-javalite:3.11.0")
implementation("androidx.preference:preference-ktx:1.1.1")
并初始化
val data: DataStore<SomeMessage> = DataStoreFactory.create(
serializer = SessionSerializer, // your Serializer
corruptionHandler = null,
migrations = emptyList(),
scope = CoroutineScope(Dispatchers.IO + Job())
和以前一样继续
data.updateData {
it.toBuilder().setAddress("address").build()
}
data.collect { ChargingSession ->
ChargingSession.address
}
答案 1 :(得分:0)
使用下面的依赖
implementation("androidx.datastore:datastore-preferences:1.0.0-beta01")