it's my first time diving in with protobuf and jetpack's DataStore but I've encountered an issue which is quite confusing.
I've created my .proto file in src/main/java/proto, it's really simple:
syntax = "proto3";
option java_package = "com.test.appname.proto";
option java_multiple_files = true;
message WalkInfo {
float distance = 1;
bool run = 2;
}
Then I've written in kotlin a serializer class for some data in my app.
object WalkInfoSerializer : Serializer<Walker.WalkInfo>{
override val defaultValue: Walker.WalkInfo
get() = WalkInfo.getDefaultInstance()
override fun readFrom(input: InputStream): Walker.WalkInfo {
try {
return WalkInfo.parseFrom(input)
} catch (exception: InvalidProtocolBufferException) {
throw CorruptionException("Cannot read proto.", exception)
}
}
override fun writeTo(t: Walker.WalkInfo, output: OutputStream) {
t.writeTo(output)
}
}
I've also set up my build.gradle file like this:
plugins {
id 'com.android.application'
id 'kotlin-android'
id "com.google.protobuf" version "0.8.14"
}
...
dependencies {
...
//DataStore
implementation "androidx.datastore:datastore:1.0.0-alpha05"
implementation 'com.google.protobuf:protobuf-javalite:3.14.0'
}
protobuf {
protoc {
artifact = "com.google.protobuf:protoc:3.10.0"
}
generateProtoTasks {
all().each { task ->
task.builtins {
java {
option 'lite'
}
}
}
}
}
Everything works fine, the classes seem to be generated correctly and they even pop up in android studio's autocomplete. The problem is that I can't get the project to compile as I can't seem to find a way to resolve the "Unresolved Reference" for the methods generated (like getDefaultInstance(), parseFrom(), writeTo() Even by writing the full class path it won't work.
Am I missing something? I've tried to play around with build.gradle and the proto file with some settings I found in their documentation but I still couldn't get it to work
Thank you!
