androidkotlingrpcgrpc-kotlin

How to generate only Kotlin code (gRPC stubs and Protobuf messages) for an Android application using gRPC?


I am developing an Android application that uses gRPC for communication with a backend service. Currently, my build script generates both Java and Kotlin code from .proto files using the protoc-gen-grpc-java and protoc-gen-grpc-kotlin plugins. However, I would like to avoid generating any Java code and instead generate only pure Kotlin code for both gRPC stubs and Protobuf messages.

I'm using the build.gradle.kts configuration from the gRPC example: https://github.com/grpc/grpc-kotlin/blob/master/examples/stub-android/build.gradle.kts

My Question:

  1. Is it possible to configure the build script to generate only Kotlin code (both for gRPC stubs and Protobuf messages) without relying on any Java-generated classes?
  2. If yes, what changes should I make to my build.gradle.kts file to achieve this?

I'd also like to know more about what's going on in the protobuf {} block in my build.grdle.kts


Solution

  • I would like to avoid generating any Java code and instead generate only pure Kotlin code for both gRPC stubs and Protobuf messages.

    That does not appear to be an option right now. Quoting the documentation:

    Note: The Kotlin protoc plugin uses the Java protoc plugin behind the scenes to generate message types as Java classes. Generation of Kotlin sources for proto messages is being discussed in protocolbuffers/protobuf#3742.

    You might wish to consider Wire as an alternative.