欢迎来到尧图网

客户服务 关于我们

您的位置:首页 > 财经 > 创投人物 > 开源项目Syncthing-Android环境搭建与编译

开源项目Syncthing-Android环境搭建与编译

2025/4/19 8:58:11 来源:https://blog.csdn.net/ItJavawfc/article/details/147162394  浏览:    关键词:开源项目Syncthing-Android环境搭建与编译

NAS - SyncthingAndroid

文章目录

  • NAS - SyncthingAndroid
  • 参考资料
  • 编译
  • 解决编译遇到的各种问题
    • gradle 无法下载
    • syncthing.git 访问不可达
    • golang 访问不可达
    • 防坑
  • 总结


NAS - SyncthingAndroid

之所以了解SyncthingAndroid 开源项目,是因为最近两年关注到一款产品 NAS产品,恰好有朋友在做这款产品,就去研究了一下基于NAS产品的一些技术实现。

国内已经有非常成熟的生产厂商了,也在大面积铺货。 从时间技术上 SyncthingAndroid 并不是唯一技术实现,服务端可以用samba或者webdav 文件挂载,穿透方案可以用
n2n,Android和ios 叫hin2n,国外用syncthing 开源整体方案来做。

这里针对 SyncthingAndroid 端来讲一下环境搭建问题。
在这里插入图片描述

参考资料

syncthing-android
syncthing-android-fdroid

这里将的是syncthing-android-fdroid 环境搭建,其实它就是基于 syncthing-android 实现的。

编译

其实开源软件已经说明了 用 Linux 或者 SSL 推荐的编译方式,且编译步骤已经说明了的。


Build on Debian Linux / WSL - recommended way
A Linux VM, for example running Debian, is recommended to build this.Build SyncthingNative and the Syncthing-Android wrapper using the following commands:#
# Install prerequisites.
apt-get -y install gcc git openjdk-17-jdk python3 unzip
#
# Clone repository.
mkdir -p ~/git && cd ~/git
git clone https://github.com/Catfriend1/syncthing-android.git --recursive
## git stash && git pull origin Catfriend1-patch-1 && git checkout Catfriend1-patch-1
#
# Build
cd ~/git/syncthing-android
python3 install_minimum_android_sdk_prerequisites.py
./gradlew buildNative
export ANDROID_HOME=~/git/syncthing-android-prereq
echo -e "\norg.gradle.jvmargs=-Xmx4096m" >> gradle.properties
./gradlew lintDebug
./gradlew assembleDebug

解决编译遇到的各种问题

上面Build 已经说明了步骤,但是实际操作中会遇到各种问题,下面一一例举并说明修改方案。
为什么会遇到这些问题? 毕竟是在国内,开源项目会造成各种依赖条件不可达呗…

gradle 无法下载

root@wfc-VMware-Virtual-Platform:~/git/syncthing-android# ./gradlew buildNative
Downloading https://services.gradle.org/distributions/gradle-8.9-bin.zipException in thread "main" java.io.IOException: Downloading from https://services.gradle.org/distributions/gradle-8.9-bin.zip failed: timeout

解决方案,替换成阿里镜像:
修改文件:syncthing-android/gradle/wrapper/gradle-wrapper.properties

#Thu Sep 29 21:34:28 CEST 2022
# https://gradle.org/release-checksums/
distributionBase=GRADLE_USER_HOME
distributionUrl=https\://mirrors.cloud.tencent.com/gradle/gradle-8.9-bin.zip
distributionPath=wrapper/dists
zipStorePath=wrapper/dists
#distributionSha256Sum=d725d707bfabd4dfdc958c624003b3c80accc03f7037b5122c4b1d0ef15cecab
zipStoreBase=GRADLE_USER_HOME

syncthing.git 访问不可达

具体报错如下:

./gradlew buildNative
Downloading https://mirrors.cloud.tencent.com/gradle/gradle-8.9-bin.zip
............10%.............20%.............30%.............40%.............50%.............60%.............70%.............80%.............90%.............100%Welcome to Gradle 8.9!Here are the highlights of this release:- Enhanced Error and Warning Messages- IDE Integration Improvements- Daemon JVM InformationFor more details see https://docs.gradle.org/8.9/release-notes.htmlStarting a Gradle Daemon (subsequent builds will be faster)> Task :syncthing:checkPython
Using python 3.12.3 from /usr (python3)> Task :syncthing:buildNative
[python] python3 -u ./build-syncthing.pygit_bin='/usr/bin/git'Info: go is not available on the PATH. Trying install_goDownloading prebuilt-go to: /root/git/syncthing-android/syncthing/../../syncthing-android-prereq/go_1.24.1.tgzDownloaded prebuilt-go to: /root/git/syncthing-android/syncthing/../../syncthing-android-prereq/go_1.24.1.tgzSHA-256: /root/git/syncthing-android/syncthing/../../syncthing-android-prereq/go_1.24.1.tgz cb2396bae64183cdccf81a9a6df0aea3bce9511fc21469fb89a0c00470088073[ok] Checksum of /root/git/syncthing-android/syncthing/../../syncthing-android-prereq/go_1.24.1.tgz matches expected value.Extracting prebuilt-go ...Adding to PATH: /root/git/syncthing-android/syncthing/../../syncthing-android-prereq/go_1.24.1/bingo_bin='/root/git/syncthing-android/syncthing/../../syncthing-android-prereq/go_1.24.1/bin/go'ANDROID_NDK_HOME env var is not defined. Then, NDK_VERSION and ANDROID_SDK_ROOT env vars must be defined.Downloading NDK to: /root/git/syncthing-android/syncthing/../../syncthing-android-prereq/ndk_r28.zipDownloaded NDK to: /root/git/syncthing-android/syncthing/../../syncthing-android-prereq/ndk_r28.zipSHA-1: /root/git/syncthing-android/syncthing/../../syncthing-android-prereq/ndk_r28.zip 894f469c5192a116d21f412de27966140a530ebc[ok] Checksum of /root/git/syncthing-android/syncthing/../../syncthing-android-prereq/ndk_r28.zip matches expected value.Extracting NDK ...Adding ANDROID_NDK_HOME='/root/git/syncthing-android/syncthing/../../syncthing-android-prereq/android-ndk-r28'ANDROID_NDK_HOME='/root/git/syncthing-android/syncthing/../../syncthing-android-prereq/android-ndk-r28'Invoking git fetch ...fatal: unable to access 'https://github.com/syncthing/syncthing.git/': Recv failure: Connection reset by peerTraceback (most recent call last):File "/root/git/syncthing-android/syncthing/./build-syncthing.py", line 338, in <module>subprocess.check_call([File "/usr/lib/python3.12/subprocess.py", line 413, in check_callraise CalledProcessError(retcode, cmd)subprocess.CalledProcessError: Command '['git', '-C', '/root/git/syncthing-android/syncthing/src/github.com/syncthing/syncthing', 'fetch', '--tags']' returned non-zero exit status 128.> Task :syncthing:buildNative FAILEDFAILURE: Build failed with an exception.

这里一定要看清问题的本质:是 访问不可达,而不是 python 脚本问题,这个问题自己在开源平台上咨询过都是答非所问…

 fatal: unable to access 'https://github.com/syncthing/syncthing.git/': Recv failure: Connection reset by peer

所以,要怎么分析问题和解决问题?
这里有个天坑 ,因为我是国内环境,ubuntu 无法访问github,这个才是问题的本质,这里也是为什么 github 的 syncthing.git 无法访问的原因。

尝试解决方案:更改DNS 路由

vim /etc/systemd/resolved.confnameserver 8.8.8.8
nameserver 1.1.1.1vim  /etc/resolv.confnameserver 8.8.8.8
nameserver 1.1.1.1

然后尝试看看github 是否能访问,当然如果还是不行,尝试其它方法看看。

golang 访问不可达

报错日志如下:

root@wfc-VMware-Virtual-Platform:~/git/syncthing-android# ./gradlew buildNative> Task :syncthing:checkPython
Using python 3.12.3 from /usr (python3)> Task :syncthing:buildNative
[python] python3 -u ./build-syncthing.pygit_bin='/usr/bin/git'Info: go is not available on the PATH. Trying install_goDownloaded prebuilt-go to: /root/git/syncthing-android/syncthing/../../syncthing-android-prereq/go_1.24.1.tgzSHA-256: /root/git/syncthing-android/syncthing/../../syncthing-android-prereq/go_1.24.1.tgz cb2396bae64183cdccf81a9a6df0aea3bce9511fc21469fb89a0c00470088073[ok] Checksum of /root/git/syncthing-android/syncthing/../../syncthing-android-prereq/go_1.24.1.tgz matches expected value.Adding to PATH: /root/git/syncthing-android/syncthing/../../syncthing-android-prereq/go_1.24.1/bingo_bin='/root/git/syncthing-android/syncthing/../../syncthing-android-prereq/go_1.24.1/bin/go'ANDROID_NDK_HOME env var is not defined. Then, NDK_VERSION and ANDROID_SDK_ROOT env vars must be defined.Downloaded NDK to: /root/git/syncthing-android/syncthing/../../syncthing-android-prereq/ndk_r28.zipSHA-1: /root/git/syncthing-android/syncthing/../../syncthing-android-prereq/ndk_r28.zip 894f469c5192a116d21f412de27966140a530ebc[ok] Checksum of /root/git/syncthing-android/syncthing/../../syncthing-android-prereq/ndk_r28.zip matches expected value.Adding ANDROID_NDK_HOME='/root/git/syncthing-android/syncthing/../../syncthing-android-prereq/android-ndk-r28'ANDROID_NDK_HOME='/root/git/syncthing-android/syncthing/../../syncthing-android-prereq/android-ndk-r28'Invoking git fetch ...From https://github.com/syncthing/syncthing+ e2973ff2f...fa0d933e4 release-nightly -> origin/release-nightly  (forced update)Invoking git describe ...Cleaning go-build cacheBuilding syncthing version v1.29.4*** Building for armgo: github.com/AudriusButkevicius/recli@v0.0.7-0.20220911121932-d000ce8fbf0f: Get "https://proxy.golang.org/github.com/%21audrius%21butkevicius/recli/@v/v0.0.7-0.20220911121932-d000ce8fbf0f.mod": dial tcp 142.250.217.113:443: connect: connection refusedTraceback (most recent call last):File "/root/git/syncthing-android/syncthing/./build-syncthing.py", line 384, in <module>subprocess.check_call([go_bin, 'mod', 'download'], cwd=syncthing_dir)File "/usr/lib/python3.12/subprocess.py", line 413, in check_callraise CalledProcessError(retcode, cmd)subprocess.CalledProcessError: Command '['/root/git/syncthing-android/syncthing/../../syncthing-android-prereq/go_1.24.1/bin/go', 'mod', 'download']' returned non-zero exit status 1.> Task :syncthing:buildNative FAILEDFAILURE: Build failed with an exception.* What went wrong:
Execution failed for task ':syncthing:buildNative'.
> Python call failed: python3 -u ./build-syncthing.pyOUTPUT:git_bin='/usr/bin/git'Info: go is not available on the PATH. Trying install_goDownloaded prebuilt-go to: /root/git/syncthing-android/syncthing/../../syncthing-android-prereq/go_1.24.1.tgzSHA-256: /root/git/syncthing-android/syncthing/../../syncthing-android-prereq/go_1.24.1.tgz cb2396bae64183cdccf81a9a6df0aea3bce9511fc21469fb89a0c00470088073[ok] Checksum of /root/git/syncthing-android/syncthing/../../syncthing-android-prereq/go_1.24.1.tgz matches expected value.Adding to PATH: /root/git/syncthing-android/syncthing/../../syncthing-android-prereq/go_1.24.1/bingo_bin='/root/git/syncthing-android/syncthing/../../syncthing-android-prereq/go_1.24.1/bin/go'ANDROID_NDK_HOME env var is not defined. Then, NDK_VERSION and ANDROID_SDK_ROOT env vars must be defined.Downloaded NDK to: /root/git/syncthing-android/syncthing/../../syncthing-android-prereq/ndk_r28.zipSHA-1: /root/git/syncthing-android/syncthing/../../syncthing-android-prereq/ndk_r28.zip 894f469c5192a116d21f412de27966140a530ebc[ok] Checksum of /root/git/syncthing-android/syncthing/../../syncthing-android-prereq/ndk_r28.zip matches expected value.Adding ANDROID_NDK_HOME='/root/git/syncthing-android/syncthing/../../syncthing-android-prereq/android-ndk-r28'ANDROID_NDK_HOME='/root/git/syncthing-android/syncthing/../../syncthing-android-prereq/android-ndk-r28'Invoking git fetch ...From https://github.com/syncthing/syncthing+ e2973ff2f...fa0d933e4 release-nightly -> origin/release-nightly  (forced update)Invoking git describe ...Cleaning go-build cacheBuilding syncthing version v1.29.4*** Building for armgo: github.com/AudriusButkevicius/recli@v0.0.7-0.20220911121932-d000ce8fbf0f: Get "https://proxy.golang.org/github.com/%21audrius%21butkevicius/recli/@v/v0.0.7-0.20220911121932-d000ce8fbf0f.mod": dial tcp 142.250.217.113:443: connect: connection refusedTraceback (most recent call last):File "/root/git/syncthing-android/syncthing/./build-syncthing.py", line 384, in <module>subprocess.check_call([go_bin, 'mod', 'download'], cwd=syncthing_dir)File "/usr/lib/python3.12/subprocess.py", line 413, in check_callraise CalledProcessError(retcode, cmd)subprocess.CalledProcessError: Command '['/root/git/syncthing-android/syncthing/../../syncthing-android-prereq/go_1.24.1/bin/go', 'mod', 'download']' returned non-zero exit status 1.* Try:
> Run with --stacktrace option to get the stack trace.
> Run with --info or --debug option to get more log output.
> Run with --scan to get full insights.
> Get more help at https://help.gradle.org.BUILD FAILED in 17m 42s
2 actionable tasks: 2 executed

当我们满心欢喜声明问题已经解决,开始build arm ,结果又报错了:
dial tcp 142.250.217.113:443: connect: connection refused

这里是还有个坑,无法访问这个地址,go 相关的,千万不要理解为python 脚本问题了。

大家可以看看尝试 网上搜一搜解决方案, 最终我自己也是不断倒腾出来的,设置代理解决。 当然遇到无法解决,再次尝试其它方法

echo 'export GOPROXY=https://goproxy.cn' >> ~/.bashrc
source ~/.bashrc
go env -w GO111MODULE=on
go mod vendor
apt install udo

在这里插入图片描述

防坑

这里能不开代理软件千万不要开代理软件,比如会遇到 无法访问github 就去打开代理软件,虽然能访问github了,但是还是无法访问github中的其它资源了。 慎用

总结

自己花了好几周,找了好多资料,测试无数测最终解决了编译问题:其实就是两个大问题,需要看到具体日志,然后解决。

  • github 依赖的资源无法访问,需要解决ubuntu 访问github 问题,修改dns 路由解决
  • go 在编译过程中编译不成功,需要解决网络接口不可达,设置go 代理来解决。

版权声明:

本网仅为发布的内容提供存储空间,不对发表、转载的内容提供任何形式的保证。凡本网注明“来源:XXX网络”的作品,均转载自其它媒体,著作权归作者所有,商业转载请联系作者获得授权,非商业转载请注明出处。

我们尊重并感谢每一位作者,均已注明文章来源和作者。如因作品内容、版权或其它问题,请及时与我们联系,联系邮箱:809451989@qq.com,投稿邮箱:809451989@qq.com

热搜词