Pure Golang Android Service

1,363 views
Skip to first unread message

rlai...@gmail.com

unread,
Nov 24, 2015, 3:45:53 AM11/24/15
to golang-nuts
Hello Everyone,

I'm curious if it is possible to write an all-golang background service for android. Reviewing https://godoc.org/golang.org/x/mobile/app  it seems we may only have options to launch a golang android application from user interaction in the foreground.

Any insight would be greatly appreciated!

Daniel Skinner

unread,
Nov 24, 2015, 4:45:32 AM11/24/15
to rlai...@gmail.com, golang-nuts
The short answer is no. This isn't a limitation of gomobile but rather of the platform. At minimum, you would need a Service class implementation to load output lib of gobind and perform work. The longer answer is you could, but not in a way that's easily redistributable and the exact details would be dependent on the device manufacturer and model.

--
You received this message because you are subscribed to the Google Groups "golang-nuts" group.
To unsubscribe from this group and stop receiving emails from it, send an email to golang-nuts...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

C Banning

unread,
Nov 24, 2015, 12:51:02 PM11/24/15
to golang-nuts, rlai...@gmail.com
You can run linux-arm services on Android but it's a bit of a kludge.  
1. root the device
2. install a console app that gives you "su" access
3. install your binary in a file-system with execute permission
4. manually start your service: > my_app &

You'll be missing a lot of useful commands - iinitd, grep, etc. - by default; so you've got to add additional utilities to make it really useful.  But I've done this to demo Go services running on an Android media server.  (The Raspberry Pi 2 Model B will let you deploy to a linux-arm environment comparable to many Android devices effortlessly.)

Seth Moeckel

unread,
Oct 24, 2017, 7:55:05 PM10/24/17
to golang-nuts
Has anything here changed? Given that Go mobile apps are really just Go apps, I wonder if a service could be made by simply having the correct manifest...

Daniel Skinner

unread,
Oct 24, 2017, 8:41:27 PM10/24/17
to Seth Moeckel, golang-nuts

The manifest can specify hooks for Service implementations, such as to start on-boot, but the platform still requires the implementation of the Service class. One could write a generic NativeService implementation for easy reuse and launching of native processes, but otherwise nothing has changed with the Android platform that I'm aware of.


--
Reply all
Reply to author
Forward
0 new messages