A simple project to create a simple bootstrap for Android apps using gRPC and Protocol Buffers.
proto
contains proto definitions and generated classesapi-server
serves as a gRPC endpointuser-app
is an android application
To connect with running local gRPC instance you will have to forward back device localhost port to PC port:
adb reverse tcp:8800 tcp:8800
Server can be run straight from gradle, or as a part of the distribution.
cd <root folder>
gradle :api-server:build # Only builds
gradle :api-server:run # Builds and starts the server
cd <root folder>
gradle :api-server:distZip
cp api-server/build/distributions/api-server.zip <destination>
cd <destination>
unzip api-server.zip
cd api-server
./bin/api-server
Gradle cannot handle two projects with common dependency at the same time. You can use api-server
run configuration (or type gradle :api-server:runServer
) to start server from Android Studio.
You can use Polyglot to test calls. Just send JSON-formatted input to the script:
echo {} | java -jar polyglot.jar --command=call --endpoint=localhost:8800 \
--full_method="com.kantoniak.examplegrpc.proto.EntryService/GetAll" \
--proto_discovery_root="<project-root>/proto/src/main/proto"
java -jar polyglot.jar --command=list_services \
--proto_discovery_root="<project-root>/proto/src/main/proto"
If your module needs to use classes generated from proto, remember to add
apply from: project(':proto').file("proto-deps.gradle")
dependencies {
implementation project(":proto")
}
to build.gradle
of the module.