Reputation: 31
I want to print a protobuf message to json. I do the following:
JsonFormat.Printer jsonPrinter = JsonFormat.printer();
StringBuilder toStore = new StringBuilder();
toStore.append("[");
toStore.append(jsonPrinter.print(pointRecord.build())); // point record is a builder of protoMessage.
I get the following error:
:app:compileDebugJavaWithJavac - is not incremental (e.g. outputs have changed, no previous execution, etc.).
/app/src/main/java/com/example/exampleapp/RecordsCollector.java:131: error: incompatible types: PointRecord cannot be converted to MessageOrBuilder
toStore.append(jsonPrinter.print(pointRecord.build()));
^
Note: Some input files use unchecked or unsafe operations.
Note: Recompile with -Xlint:unchecked for details.
Note: Some messages have been simplified; recompile with -Xdiags:verbose to get full output
1 error
:app:compileDebugJavaWithJavac FAILED
I think I need to build full protobuf and not only lite protobuf. However, I don't know how to do it. I put here a part of the gradle.build file of the application:
apply plugin: 'com.android.application'
apply plugin: 'com.google.protobuf'
...
protobuf {
protoc {
artifact = 'com.google.protobuf:protoc:3.0.0'
}
plugins {
javalite {
artifact = 'com.google.protobuf:protoc-gen-javalite:3.0.0'
}
}
generateProtoTasks {
all().each { task ->
task.builtins {
remove java
}
task.plugins {
javalite { }
}
}
}
}
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
androidTestCompile('com.android.support.test.espresso:espresso-core:2.2.2', {
exclude group: 'com.android.support', module: 'support-annotations'
})
compile 'com.android.support:appcompat-v7:25.3.1'
compile 'com.google.protobuf:protobuf-java:3.0.0'
compile 'com.google.protobuf:protobuf-java-util:3.0.0'
testCompile 'junit:junit:4.12'
}
Upvotes: 2
Views: 1949
Reputation: 143
Use the following snippet to compile full protobuf version:
protobuf {
protoc {
artifact = 'com.google.protobuf:protoc:3.0.0'
}
generateProtoTasks {
all().each { task ->
task.builtins {
java {}
}
}
}
}
…
dependencies {
implementation 'com.google.protobuf:protobuf-java:3.5.0'
implementation 'com.google.protobuf:protobuf-java-util:3.5.0'
}
Upvotes: 1