Java Android does not have "pack" defined in Any class
[EDIT: I've tried to get a minimally reproducible sample by removing all grpc code and simply using protobuf code] I am using Grpc for Android, I have "Any" objects on my .proto file. On the C# server side I have pack and unpack methods, on the Android Java side my Any class does not have pack or unpack, it seems to have all the methods expected of it as listed in the following class reference except pack and unpack: https://developers.google.com/protocol-buffers/docs/reference/java/
I am using proto3, my proto files begin with: syntax = "proto3"; import "google/protobuf/any.proto";
My build.gradle files for the application has the following lines:
protobuf {
protoc {
// Download from repositories
artifact = 'com.google.protobuf:protoc:3.0.0'
}
plugins {
javalite {
// The codegen for lite comes as a separate artifact
artifact = 'com.google.protobuf:protoc-gen-javalite:3.0.0'
}
}
generateProtoTasks {
all().each { task ->
task.plugins {
javalite { }
}
}
}
}
My dependencies are:
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.android.support.constraint:constraint-layout:1.0.2'
compile 'com.google.protobuf:protobuf-lite:3.0.0'
compile 'javax.annotation:jsr250-api:1.0'
testCompile 'junit:junit:4.12'
}
Does anyone have any ideas on why this might be the case?
I am facing the same issue . Any one here can help us ?
Experiencing this as well, seems related to https://github.com/google/protobuf/issues/1974
@gerben-s is there any progress on this? We are running into the same issue. Are there any workarounds?
Pinging on this. The pack/unpack libraries have been available for a long time but there is still no support on Android for them. Could we get this prioritized please?
It seems that the current work-out for using Any is use protobuf instead of protobuf-lite in Android, which at least will double the size of compiled code of protos.
Unfortunately, the Lite java system does not have proto reflection. That makes it impossible to provide the same API as the non-Lite version.
This is what I did in Android Java on my project as a pack function:
String name = message.getClass().getSimpleName(); String packageName = message.getClass().getPackage().getName(); //needs to be the same as your proto package String fullName = packageName + '.'+ name; String typeURL = GetTypeUrl(fullName);
Any any = Any.newBuilder() .setValue(message.toByteString()) .setTypeUrl(typeURL) .build();
private String GetTypeUrl(String fullName) { String prefix = "type.googleapis.com"; return prefix + "/" + fullName; }