How to make External Storage work on Android

Based on the discussion on the Golang issue tracker and the documentation for gobind, it should be possible to make external storage accessible for Syncthing.

From what I understand, the following should work:

  1. compile Syncthing with gomobile bind
  2. create an implementation of filesystem.go in Syncthing that accesses Storage Access Framework APIs directly

I have been trying to implement this, but I can’t get step 1 (compilation with gomobile) to work.

$ gomobile bind -o out.apk
gomobile: binding 'main' package () is not supported

Does that mean we need to make a Syncthing package without a main() function?

It should also be possible to trigger the gomobile build directly from gradle (which is preferable), but that throws even weirder errors (gist link). Seems to be this open Golang issue.

So, what can we do to make this work?


You need to create a go library that does one thing, provides an Open function, which calls to java using reverse bindings, gets the fd and wraps it into os.File and gobind that.

Once that is in place you should just use that in syncthing fs package (syncthing itself doesn’t need gobind), and then build syncthing via grade/with NDK support and GOOS=android