Skip to content

Latest commit

 

History

History
 
 

examples

gRPC Kotlin examples

Examples

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:

Instructions for the remaining examples are provided below.

File organization

The example sources are organized into the following top-level folders:

Instructions for running other examples

  • 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:

    1. Download Android Command Line Tools

    2. 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
    3. Set an env var pointing to the android-sdk

      export ANDROID_SDK_ROOT=PATH_TO_SDK/android-sdk
    4. Run the build from this project's dir:

      ./gradlew :android:build
    5. 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 on MainActivity and select Run.

      • Physical Device + Local Server:

        • From the command line:

          1. Setup adb
          2. ./gradlew :android:installDebug -PserverUrl=http://YOUR_MACHINE_IP:50051/
        • From Android Studio / IntelliJ:

          1. Create a gradle.properties file in your root project directory containing:

            serverUrl=http://YOUR_MACHINE_IP:50051/
          2. Navigate to android/src/main/kotlin/io/grpc/examples/helloworld and right-click on MainActivity and select Run.

      • Emulator or Physical Device + Cloud:

        • From the command line:

          1. setup adb
          2. ./gradlew :android:installDebug -PserverUrl=https://YOUR_SERVER/
        • From Android Studio / IntelliJ:

          1. Create a gradle.properties file in your root project directory containing:

            serverUrl=https://YOUR_SERVER/
          2. Navigate to android/src/main/kotlin/io/grpc/examples/helloworld and right-click on MainActivity and select Run.