grpc-java icon indicating copy to clipboard operation
grpc-java copied to clipboard

feature request: support grpc servers on android

Open brandondutra opened this issue 6 years ago • 27 comments

Running a grpc server on android in java is not supported. Running an HTTP server on android is well supported and has many legitimate use cases. The same should be true for running a grpc server on android.

This need has come up in many issues. And the general suggestion is to use c++. Such as in #3041 #2273 #2227 and others. See also questions from stack overflow.

The docs are also misleading. In https://grpc.io/docs/quickstart/android.html it is not clearly stated that the server is not running in android, and this is not supported.

If the choice to not support android servers in java is continued, then the docs need to be made clear of this fact.

brandondutra avatar Apr 29 '18 04:04 brandondutra

I sent out some PRs to clarify the documentation. We can use this issue to track demand for on-device servers.

I'll note that we intend to support gRPC C++ servers on Android: this is known to work right now, and I'll be adding interop tests for on-device servers later this quarter. For many use cases requiring an on-device server, this should be sufficient.

Netty, as of 4.1, does officially support (but not test, see http://netty.io/wiki/new-and-noteworthy-in-4.1.html#wiki-h3-3) Android so we could consider the same with gRPC.

@brandondutra if you have any insight in the potential issues brought up with on-device Android servers in https://github.com/grpc/grpc-java/issues/2273, please share. Specifically, we've done a lot of work on network reliability for Android clients but it's unclear how any of this would translate to server implementations.

ericgribkoff avatar Apr 30 '18 16:04 ericgribkoff

Yes, it is very convenient if support grpc servers on android。

louiewh avatar May 03 '18 07:05 louiewh

Would be nice to support gRPC Servers on Android Things devices.

hameno avatar Aug 18 '18 09:08 hameno

+1

daviderickson avatar Dec 02 '18 04:12 daviderickson

+1

gpwclark avatar Feb 14 '19 15:02 gpwclark

It is very convenient to have gRPC servers on Android in java.

timtmlin avatar Feb 25 '19 10:02 timtmlin

For those who have commented on this thread: Have you tried the Netty server with Android?

carl-mastrangelo avatar Feb 25 '19 17:02 carl-mastrangelo

I have not commented but have recently been working with getting a grpc server working on android. I have been successful using Netty. I based the majority of my code on ejona86's "Play with Netty server on Android" branch with a few small changes and one significant change: I had to "import io.grpc.netty.NettyServerBuilder;" and change ServerBuilder to NettyServerBuilder throughout the code. Hopefully that might help others trying to get this to work. Android servers may not officially be support yet but with the support of Netty for android it has worked well for me so far.

MarieCaroline avatar Mar 25 '19 15:03 MarieCaroline

This would be useful for the project I'm working on right now.

ryderziola avatar Apr 19 '19 18:04 ryderziola

This feature is an urgent necessity for p2p network.

sbhunia avatar Apr 25 '19 17:04 sbhunia

Ok, we'll stick for now with release 1.10.1 as it works as expected with this version.

Originally posted by @Houf in https://github.com/grpc/grpc-java/issues/4513#issuecomment-392855984

What can be downside of using release 1.10.1 as android server can be run using this version?

AbhishekPantUK avatar Aug 30 '19 06:08 AbhishekPantUK

@AbhishekPantUK I think as commented by https://github.com/grpc/grpc-java/issues/4513#issuecomment-392863227 , if you use NettyServerBuilder directly you could still use higher version releases.

dapengzhang0 avatar Aug 30 '19 16:08 dapengzhang0

This would be useful for my project that runs a grpc server in an android foreground service that other apps on device connect to.

We're currently using the C++ implementation, but we're trying to move away from that as we need to integrate with more android system services using java.

abhishekamit avatar Oct 02 '19 16:10 abhishekamit

@abhishekamit Internally you can use gRPC over Parcelable / Binder, see go/grpc-parcelables and go/grpc-binderchannel (You might need to request for access). That feature might be available sooner than that of this feature request.

dapengzhang0 avatar Oct 02 '19 19:10 dapengzhang0

I was able to get this working.

  • Xamarin app that includes the dlls from the grpc~csharp/HelloworldXamarin running as the server on an android tablet. Server is running with port = 38100
  • issued "adb forward tcp:38300 tcp:38100" on my pc
  • Then using the grpc~python/helloworld client with a channel set to "localhost:38300" I can issue SayHello from the pc that is tethered via usb to the tablet.

jeffbradham avatar Jan 17 '20 20:01 jeffbradham

Anyone who managed to get a gRPC server to work on Android: Did you get it to work with TLS? If so, how?

We've got the server to work on Android using Netty but the only thing that doesn't work is TLS and we've narrowed it down to Netty requiring Java >= 8 when using conscrypt, but Android reports Java 6.

gnarea avatar Apr 09 '20 19:04 gnarea

@gnarea Netty Server on Android is possible but grpc-team don't officially support it. You can discuss it with community in https://groups.google.com/forum/#!forum/grpc-io and StackOverflow.

we've narrowed it down to Netty requiring Java >= 8 when using conscrypt, but Android reports Java 6

It would be reasonable to file an issue against netty to support Android case for that API.

dapengzhang0 avatar Apr 09 '20 19:04 dapengzhang0

I can confirm i'm able to run gRPC server on android device (though with some minor hacks like using directly NettyServerBuilder). Haven't tried with TLS so far

4ntoine avatar Jun 26 '20 07:06 4ntoine

I can confirm i'm able to run gRPC server on android device (though with some minor hacks like using directly NettyServerBuilder). Haven't tried with TLS so far

any code please?

liugangnhm avatar Aug 12 '20 06:08 liugangnhm

@liugangnhm https://github.com/relaycorp/relaynet-courier-android/blob/0313d28dfde84f4d728e8a5f26d3fe52b253c3cd/app/src/main/java/tech/relaycorp/cogrpc/server/CogRPCServer.kt#L52-L70

That's using TLS.

gnarea avatar Aug 12 '20 10:08 gnarea

@liugangnhm https://github.com/relaycorp/relaynet-courier-android/blob/0313d28dfde84f4d728e8a5f26d3fe52b253c3cd/app/src/main/java/tech/relaycorp/cogrpc/server/CogRPCServer.kt#L52-L70

That's using TLS.

thanks for your reply, I will have a try later

liugangnhm avatar Aug 16 '20 15:08 liugangnhm

I can confirm i'm able to run gRPC server on android device (though with some minor hacks like using directly NettyServerBuilder). Haven't tried with TLS so far

any code please?

Sorry for such a late reply (had to return back to it again). Better late than never, right? ;).

Here it is.

4ntoine avatar Dec 16 '20 10:12 4ntoine

Is this now in a good state? Anyone actively using it? Netty supports Android https://netty.io/wiki/new-and-noteworthy-in-4.1.html#android-support

Sounds positive from above.

yschimke avatar Apr 15 '22 07:04 yschimke

The docs still say unsupported...

yschimke avatar Apr 15 '22 07:04 yschimke

@ejona86 can comment on the plans to support OkHttp based servers....

sanjaypujare avatar Apr 15 '22 16:04 sanjaypujare

People have successfully used grpc-netty on Android for many years. But it is a "at your own risk" sort of thing. There's some concerns about whether future Netty versions will support the Android versions we need. TLS is non-operational. At the end of the day though, it is very poorly optimized for the non-OpenJDK, low-memory environment. grpc-netty has a huge code size. There are ways to improve it, but we consider it a dead-end for large-scale deployment.

There is some work that's started for a server in grpc-okhttp. There's been some hints of that, like in #9052.

ejona86 avatar Apr 15 '22 18:04 ejona86

This is happening in #9177. Still need to write more code and it will be an involved review.

ejona86 avatar May 27 '22 21:05 ejona86

I am also interested in this feature

RubenGarcia avatar Jun 22 '23 08:06 RubenGarcia

Fixed in #9177

ejona86 avatar Jun 22 '23 14:06 ejona86