Taier
Taier

Reputation: 2119

Compiling C++ gRPC for Android

How to compile C++ gRPC code for Android? I have seen several tutorials on how Protobuf itself can be compiled using the Android Native Development Kit, such as in the answer from Swapnil: How to integrate/install latest c++ protobuf (3.2) with Android NDK?

Or Google protobuf and Android NDK

But how to How to compile C++ gRPC code that is using Protobuf as well for Android? Taking into account that there's 20K lines of gRPC Makefile.

Upvotes: 5

Views: 1999

Answers (2)

JonasVautherin
JonasVautherin

Reputation: 8063

I do it with dockcross (which does not do anything fancy, it just sets up the toolchain in a convenient way).

Say for android-arm (but it works for android-arm64, android-x86 and android-x86_64 just the same):

$ git clone https://github.com/grpc/grpc --recursive
$ cd grpc
$ docker run --rm dockcross/android-arm > ./dockcross-android-arm
$ chmod +x dockcross-android-arm
$ ./dockcross-android-arm cmake -DgRPC_BUILD_CODEGEN=OFF -Bbuild -S.
$ ./dockcross-android-arm cmake --build build

It will build all the dependencies in the gRPC submodules. It should work in your project if you add gRPC as a submodule (well, up to some point depending on your transitive dependencies situation, I guess).

This said, I am not a big fan of using git submodules for dependencies with CMake. Instead I like to build the dependencies separately and have my project find them with find_package. I explain that in more details here, and more importantly I have an example doing exactly that for gRPC here.

Upvotes: 3

4ntoine
4ntoine

Reputation: 20422

I've done it here.

In brief: git submodule gRPC C++, add "CMakeLists.txt" file to your project on how to build C++ gRPC (and your code that uses it), add a externalNativeBuild/cmake it to your "build.gradle" - voila!

Upvotes: 0

Related Questions