I am implementing datastore for the first time in my app but I have this error showing up onm all complex
class
incompatible types: NonExistentClass cannot be converted to Annotation
the .proto
file looks like this:
syntax = "proto3";
option java_package = "com.myapp.app";
option java_multiple_files = true;
message LastBackup {
bool valid = 1;
string time = 2;
bool enabled = 3;
int64 id = 4;
CustomData data = 5;
}
message CustomData {
int32 id = 1;
repeated CustomItem items = 2;
}
message CustomItem {
string name = 4;
string image = 5;
}
the error is basically happening on all complex message : CustomData
and CustomItem
I tried to rename them using My
just to make a difference and see if the error could come from a duplicate message but the message still appear.
The reason I renamed them is because, CustomData
is also a kotlin data class defined to handle the Json response from a server.
So overall goal was to backup in the protobuf datastore Json response. The app is having a data class named Backup.kt
which contain:
data class Backup(
val valid: Boolean,
val time : String,
val enable: Boolean,
val id : Long,
val data: CustomData
)
data class CustomData (
val id: int,
val items: List<CustomItem>
)
data class CustomItem (
val name: String,
val image: String
)
So I create a proto file
as defined above.
Then I also got the issue :
jetified-protobuf-java-4.26.0 (com.google.protobuf:protobuf-java:4.26.0) and jetified-protobuf-javalite-3.19.4 (com.google.protobuf:protobuf-javalite:3.19.4)
and my gradle look like this:
plugins {
id 'kotlinx-serialization'
id "com.google.protobuf" version "0.8.17"
}
dependencies {
implementation "androidx.datastore:datastore:1.1.0"
implementation "com.google.protobuf:protobuf-javalite:3.21.11"
plugins {
id 'kotlinx-serialization'
id "com.google.protobuf" version "0.8.17"
}
dependencies {
implementation "androidx.datastore:datastore:1.1.0"
implementation "com.google.protobuf:protobuf-javalite:3.19.4"
//implementation "com.google.protobuf:protobuf-kotlin-lite:3.21.11"
}
protobuf {
protoc {
artifact = "com.google.protobuf:protoc:3.19.4"
}
// Generates the java Protobuf-lite code for the Protobufs in this project. See
// https://github.com/google/protobuf-gradle-plugin#customizing-protobuf-compilation
// for more information.
generateProtoTasks {
all().each { task ->
task.builtins {
java {
option 'lite'
}
// kotlin {
// option 'lite'
// }
}
}
}
}
}
protobuf {
protoc {
artifact = "com.google.protobuf:protoc:3.21.11"
}
// Generates the java Protobuf-lite code for the Protobufs in this project. See
// https://github.com/google/protobuf-gradle-plugin#customizing-protobuf-compilation
// for more information.
generateProtoTasks {
all().each { task ->
task.builtins {
java {
option 'lite'
}
//kotlin {
// option 'lite'
//}
}
}
}
}
Any idea why the issue is happeneing ?
- Is it because the
proto message
have the same name that thedata class
? - something else ?
Thanls