Writing to external SD card in Android 5.0 and above

(Cooad) #62

I have a Motorola MotoG3 running Android 6.0.1. I was not quite aware, that this should not be possible, so i’ve set up a folder to sync on my phone. I did it from the web interface (I’ve changed the bind address in the app, and logged in from my pc) - I set up the folder first on my PC, then shared it to the phone and confirmed through the web gui of the phone syncthing instance, giving the path to the folder (/storage/“card”/Music). Aaand… It works, flawlessly. It detects changes on the card, it can write new files, modify them - all is well. So why is it said, that it doesn’t work?



Did you format the card as portable storage, or as internal storage? Internal will always work, but portable only on some devices with non-standard implementations by the vendor.


(Audrius Butkevicius) #64

Also, some ROMs are known to fix the android limitation


(Cooad) #65

It’s set up as portable storage. So it works only because of Motorola’s changes to the system? Well good for me, I guess :slight_smile:


(Tom) #66

Well, it’s sad, that this golang issue still isn’t fixed.

Moving the .stfolder from /storage//Android/data/com.nutomic.syncthingandroid/files/ to SdCard root did the trick for me on Xiaomi device based on 6.0.1. I was able to sync the whole SdCard.


(Brian K White) #67

This, right here.



I’m going to chime in here. I’m able to fully sync (read & write) folders on my external SD card in Android 7.0 without root and WITHOUT formatting my SD card as adoptable storage (I kept it in it’s removable exfat format). Tested on my Moto X Pure running stock Android 7.0 and on my LG-G3 running Lineage 14.1 Android 7.1.2. In the Android app under Settings/Behavior there is an option to use the Advanced Folder Picker, check this off. My external sd card is labeled /storage/0123-4567 on my device. This number will vary depending on your phone. In this particular setup I’ll explain how I sync my entire 90gb music library to my external 128gb sd card on Stock Android 7.0, MotoXPure:

1: Add your computer to Android by scanning it’s ID. Wait for it to add, and don’t select any folders to share with it.

2: On your Android, create the folder you want to sync with and create a .stfolder inside the folder (or just add a .stfolder to an existing folder if you already have the folder created the device).

3: On the computer create a new folder share within Syncthing’s GUI. In my case it was my Music folder on my PC. Select the device to share the folder with (your Android) and choose all of your preferences. I turn all file versioning off for my needs and on my PC I was sure to set it as “Send Only” so that I can’t screw up and delete something from my PC’s master music folder.

4: Wait for the notification to appear on your Android, then click it when it arrives. Name the sync to whatever you want and then in the “Path” area select your external sd (which will be labeled something like /storage/0000-0000). Then once the SD is selected, navigate to the folder on the external sd that you’ll be syncing (in my case it’s /storage/0123-4567/Music).

5: Now wait for the devices to re-communicate with each other and syncing will begin. You may need to restart Syncthing on both devices to get it to initiate.

6: That’s it…both folders are now syncing. Any music file I add from my PC will write to my phone’s external SD if Syncthing is running. Even though I am rooted, root is not required.

Note: Both of my folders (music on PC and music on Android’s external sd) were both already on each device. After setting up the sync, the initial scan took quite a while to complete (about 40min), but after that it’s working properly. All changes are synced immediately based on your selected scan interval. I took one album and changed the tags & embedded a cover image into each mp3 file and they were synced to my Android almost immediately. Can’t be happier, this is working great.

1 Like

(Felix Ableitner) #69

That is not supposed to work. Maybe LineageOS has a change that allows this, or you installed some app or script that allows it.

1 Like


The only downside is that the computer shows that it’s still syncing (hangs at 95%) and the phone says it’s out of sync. But it’s not, all files/changes are synced correctly. I don’t know, seems to just work.


(Nathaniel Wesley Filardo) #71

A new (I think) proposal for using the Android SAF from go without having to do any cross-language calls. This is going to be a little odd, but as far as I can tell it will work. The ingredients in this insane plan are:

  1. UNIX domain sockets, to which both Android Java and Go have access (I think), and, in particular, the ability to pass file descriptors across UNIX domain sockets.

  2. Some code in the syncthing-android service which knows how to drive the SAF in response to commands received across a socket connection.

  3. Some code in syncthing itself to provide a synthetic mountpoint; a filesystem driver in parallel to basicfs which knows how to translate requests for files below the mountpoint into commands on the socket.

Does this seem like a reasonable plan? I’d be happy to start prototyping if so.


(Jakob Borg) #72

I think you should not. Instead, add your mind to New Android app "Syncthing Lite"


(Audrius Butkevicius) #73

So this should work in theory if you can pull it off, but I couldn’t find the right syscalls in java exposed to be able to send descriptors around.


(Nathaniel Wesley Filardo) #74

From a quick glance, it seems that Syncthing Lite, while interesting, is lacking a scanner and so is further away from my goal of “sync to SD card” than some mucking about with file descriptors and sockets in syncthing / syncthing-android? Could you expand on your comment?


(Nathaniel Wesley Filardo) #75

I fished around a little more and, yeah, it looks like they’re not plumbed up into Java, but people have had success using JNI bindings on Android for the requisite sendmsg() call. See, for example, https://github.com/PeterCxy/SocksDroid/blob/d572359ac55757e7956ff4806fea3fda70e8887f/app/src/main/jni/system.cpp . Golang has them plumbed through, too; see /src/syscall/syscall_unix_test.go 's TestUnixRightsRoundtrip. (The one link per message thing is a drag, though I understand why.)


(Audrius Butkevicius) #76

Yeah, that will most likely work, but I don’t expect it to be easy, as you have to devise an RPC for creating files as well as opening existing ones, make sure the pipe is always there, etc, which might require a separate service. How do you start that service from go, etc.


(Audrius Butkevicius) #77

The idea is that a native java implementation of syncthing is potentially a better place to spend the effort.


(Felix Ableitner) #78

I have never used unix sockets myself, so I’m not sure if those would work. Maybe an HTTP api could also be used instead?

And yes, syncthing-lite is only meant to be a client, without any functionality for synchronization. It might be possible to add that, but it would probably involve a lot of extra effort.


(Audrius Butkevicius) #79

No, you pass file handles between processes you need to use special syscalls via a unix socket (or potentially a pipe).



not sure where everyone is at with this, but the on version 0.9.11 (4121) on Android I was able to get syncthing to sync one way to the external SD card on my LGV20 running 7.0 Nougat while running as root. the only problem was I couldn’t do it consistently in that after enabling root and restarting syncthing, I was able to get a complete sync once. after exiting syncthing any attempts to start it up again resulted in a failure to read the config. I’ve tried changing the ownership of all the files in /data/data/com.nutomic.syncthingadroid, but no dice leaving the only way to restore everything from a TitaniumBackup. even copying this folder’s contents elsewhere and restoring it after would not work for some reason. now on version 0.10.2 and all the versions in between, I can enable/disable root entering and exiting syncthing with no problems, however with root enabled it gets stuck at the “Loading” stage in the beginning never pulling up the list of directories I’ve set for sync. anyone have any suggestions?


(Hans Peter Jansen) #81

@dimmok yes, root option is attributed experimental, because nobody found time to get it working properly yet.

Since you already rooted your device, you might have some success with ExtSD fix. v1.9b worked well for a couple of LineageOS installations here lately.