This directory contains several Kotlin gRPC examples. You can find detailed instructions for building and running the two main examples from the grpc.io Kotlin/JVM pages:
- Greeter ("hello world"): for details, see Quick start.
- Route guide: for details, see Basics tutorial
Instructions for the remaining examples are provided below.
The example sources are organized into the following top-level folders:
- protos:
.proto
files (shared across examples) - stub: regular Java & Kotlin stub artifacts from protos
- stub-lite: lite Java & Kotlin stub artifacts from protos
- stub-android: Android-compatible Java & Kotlin stub artifacts from protos
- client: Kotlin clients based on regular stub artifacts
- server: Kotlin servers based on regular stub artifacts
- native-client : GraalVM Native Image clients based stub-lite
- android: Kotlin Android app based on stub-android
-
Multiple-services animals example
Start the server:
./gradlew :server:AnimalsServer
In another console, run the client against the "dog", "pig", and "sheep" services:
./gradlew :client:AnimalsClient --args=dog ./gradlew :client:AnimalsClient --args=pig ./gradlew :client:AnimalsClient --args=sheep
-
GraalVM native image example
Start the server:
./gradlew :server:HelloWorldServer
In another console, create the native image client and run it:
./gradlew :native-client:nativeImage native-client/build/graal/hello-world
-
Android example
NOTE: You must use JDK 11 or higher
Start the server:
./gradlew :server:HelloWorldServer
Run the Client:
-
Install the SDK:
mkdir android-sdk cd android-sdk unzip PATH_TO_SDK_ZIP/sdk-tools-linux-VERSION.zip mv cmdline-tools latest mkdir cmdline-tools mv latest cmdline-tools cmdline-tools/latest/bin/sdkmanager --update cmdline-tools/latest/bin/sdkmanager "platforms;android-31" "build-tools;31.0.0" "extras;google;m2repository" "extras;android;m2repository" cmdline-tools/latest/bin/sdkmanager --licenses
-
Set an env var pointing to the
android-sdk
export ANDROID_SDK_ROOT=PATH_TO_SDK/android-sdk
-
Run the build from this project's dir:
./gradlew :android:build
-
You can either run on an emulator or a physical device and you can either connect to the server running on your local machine, or connect to a server you deployed on the cloud.
-
Emulator + Local Server:
-
From the command line:
./gradlew :android:installDebug
-
From Android Studio / IntelliJ, navigate to
android/src/main/kotlin/io/grpc/examples/helloworld
and right-click onMainActivity
and selectRun
.
-
-
Physical Device + Local Server:
-
From the command line:
- Setup adb
./gradlew :android:installDebug -PserverUrl=http://YOUR_MACHINE_IP:50051/
-
From Android Studio / IntelliJ:
-
Create a
gradle.properties
file in your root project directory containing:serverUrl=http://YOUR_MACHINE_IP:50051/
-
Navigate to
android/src/main/kotlin/io/grpc/examples/helloworld
and right-click onMainActivity
and selectRun
.
-
-
-
Emulator or Physical Device + Cloud:
-
From the command line:
- setup adb
./gradlew :android:installDebug -PserverUrl=https://YOUR_SERVER/
-
From Android Studio / IntelliJ:
-
Create a
gradle.properties
file in your root project directory containing:serverUrl=https://YOUR_SERVER/
-
Navigate to
android/src/main/kotlin/io/grpc/examples/helloworld
and right-click onMainActivity
and selectRun
.
-
-
-