The C based gRPC (C++, Python, Ruby, Objective-C, PHP, C#) https://grpc.io/
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

76 lines
3.0 KiB

gRPC Hello World Tutorial (Android Java)
========================
BACKGROUND
-------------
For this sample, we've already generated the server and client stubs from [helloworld.proto](https://github.com/grpc/grpc-common/blob/master/protos/helloworld.proto).
PREREQUISITES
-------------
- [Java gRPC](https://github.com/grpc/grpc-java)
10 years ago
- [Android Tutorial](https://developer.android.com/training/basics/firstapp/index.html) if you're new to Android development
- We only have Android gRPC client in this example. Please follow examples in other languages to build and run a gRPC server.
INSTALL
-------
10 years ago
**1 Clone the gRPC Java git repo**
```sh
$ git clone https://github.com/grpc/grpc-java
```
10 years ago
**2 Install gRPC Java, as described in [How to Build](https://github.com/grpc/grpc-java#how-to-build)**
```sh
$ # from this dir
$ cd grpc-java
$ # follow the instructions in 'How to Build'
```
10 years ago
**3 [Create an Android project](https://developer.android.com/training/basics/firstapp/creating-project.html) under your working directory.**
- Set Application name to "Helloworld Example" and set Company Domain to "grpc.io". Make sure your package name is "io.grpc.helloworldexample"
- Choose appropriate minimum SDK
- Use Blank Activity
- Set Activity Name to HelloworldActivity
- Set Layout Name to activity_helloworld
10 years ago
**4 Prepare the app**
- Clone this git repo
```sh
$ git clone https://github.com/grpc/grpc-common
```
- Replace the generated HelloworldActivity.java and activity_helloworld.xml with the two files in this repo
10 years ago
- Copy GreeterGrpc.java and Helloworld.java under your_app_dir/app/src/main/java/io/grpc/examples/
- In your AndroidManifest.xml, make sure you have
```sh
<uses-permission android:name="android.permission.INTERNET" />
```
added outside your appplication tag
10 years ago
**5 Add dependencies. gRPC Java on Android depends on grpc-java, protobuf nano, okhttp**
- Copy grpc-java .jar files to your_app_dir/app/libs
```sh
$ cp grpc-java/core/build/libs/*.jar your_app_dir/app/libs/
$ cp grpc-java/stub/build/libs/*.jar your_app_dir/app/libs/
$ cp grpc-java/nano/build/libs/*.jar your_app_dir/app/libs/
$ cp grpc-java/okhttp/build/libs/*.jar your_app_dir/app/libs/
```
- Copy or download other dependencies to your_app_dir/app/libs/
10 years ago
- [Guava 18](http://search.maven.org/remotecontent?filepath=com/google/guava/guava/18.0/guava-18.0.jar)
- [okhttp 2.2.0](http://repo1.maven.org/maven2/com/squareup/okhttp/okhttp/2.2.0/okhttp-2.2.0.jar)
10 years ago
- [okio](http://search.maven.org/remotecontent?filepath=com/squareup/okio/okio/1.2.0/okio-1.2.0.jar)
- [jsr305](http://search.maven.org/remotecontent?filepath=com/google/code/findbugs/jsr305/3.0.0/jsr305-3.0.0.jar)
- protobuf nano:
```sh
10 years ago
$ cp ~/.m2/repository/com/google/protobuf/nano/protobuf-javanano/3.0.0-alpha-2/protobuf-javanano-3.0.0-alpha-2.jar your_app_dir/app/libs/
```
- Make sure your_app_dir/app/build.gradle contains:
```sh
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
}
```
10 years ago
**6 [Run your Helloworld Example app](https://developer.android.com/training/basics/firstapp/running-app.html)**