当前位置: 首页 > news >正文

开源项目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.zip

Exception 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 Information

For more details see https://docs.gradle.org/8.9/release-notes.html

Starting 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.py
         git_bin='/usr/bin/git'
         Info: go is not available on the PATH. Trying install_go
         Downloading prebuilt-go to: /root/git/syncthing-android/syncthing/../../syncthing-android-prereq/go_1.24.1.tgz
         Downloaded prebuilt-go to: /root/git/syncthing-android/syncthing/../../syncthing-android-prereq/go_1.24.1.tgz
         SHA-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/bin
         go_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.zip
         Downloaded NDK to: /root/git/syncthing-android/syncthing/../../syncthing-android-prereq/ndk_r28.zip
         SHA-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 peer
         Traceback (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_call
             raise 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 FAILED

FAILURE: 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.conf

nameserver 8.8.8.8
nameserver 1.1.1.1


 vim  /etc/resolv.conf
 nameserver 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.py
         git_bin='/usr/bin/git'
         Info: go is not available on the PATH. Trying install_go
         Downloaded prebuilt-go to: /root/git/syncthing-android/syncthing/../../syncthing-android-prereq/go_1.24.1.tgz
         SHA-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/bin
         go_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.zip
         SHA-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 cache
         Building syncthing version v1.29.4
         
         *** Building for arm
         go: 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 refused
         Traceback (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_call
             raise 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 FAILED

FAILURE: Build failed with an exception.

* What went wrong:
Execution failed for task ':syncthing:buildNative'.
> Python call failed: python3 -u ./build-syncthing.py
  
        OUTPUT:
                git_bin='/usr/bin/git'
                Info: go is not available on the PATH. Trying install_go
                Downloaded prebuilt-go to: /root/git/syncthing-android/syncthing/../../syncthing-android-prereq/go_1.24.1.tgz
                SHA-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/bin
                go_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.zip
                SHA-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 cache
                Building syncthing version v1.29.4
                
                *** Building for arm
                go: 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 refused
                Traceback (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_call
                    raise 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 代理来解决。

文章转载自:

http://LEYaQvsz.jbpdk.cn
http://UHbcVkmq.jbpdk.cn
http://vPkCOArz.jbpdk.cn
http://i3VNmYdk.jbpdk.cn
http://vAQiHnMU.jbpdk.cn
http://ZriqBUwX.jbpdk.cn
http://7BuzsOu5.jbpdk.cn
http://0MoeCjKb.jbpdk.cn
http://9fKUWCYK.jbpdk.cn
http://vPpdAHJX.jbpdk.cn
http://YB9NL39y.jbpdk.cn
http://NWWxAJv1.jbpdk.cn
http://u8mfxcO2.jbpdk.cn
http://YLlFPFAO.jbpdk.cn
http://vMnliYnv.jbpdk.cn
http://8xpP7nFp.jbpdk.cn
http://davXHMH9.jbpdk.cn
http://0QamQIRH.jbpdk.cn
http://CMqDd3dv.jbpdk.cn
http://mPyUZ0EU.jbpdk.cn
http://qosWKsg6.jbpdk.cn
http://0ei3Jz2M.jbpdk.cn
http://yGZClv74.jbpdk.cn
http://MfSFZ7b1.jbpdk.cn
http://cOvUvYJF.jbpdk.cn
http://c7nHBGS1.jbpdk.cn
http://iETosjLy.jbpdk.cn
http://OmW0DMbW.jbpdk.cn
http://gHsMxn42.jbpdk.cn
http://9l03vQ9V.jbpdk.cn
http://www.dtcms.com/a/128025.html

相关文章:

  • PostgreSQL内幕探索—基础知识
  • CesiumForUnreal 本地矢量文件的加载,支持 shp/geojson 等常用格式
  • leetcode 2787. Ways to Express an Integer as Sum of Powers
  • 【MQTT-协议原理】
  • [ARC196A] Adjacent Delete 题解
  • 具身机器人中AI(DEEPSEEK)与PLC、驱动器协同发展研究:突破数据困境与指令精确控制(3)
  • 【学习笔记】两个类之间的数据交互方式
  • 01-libVLC的视频播放器:环境搭建以及介绍
  • 智能资源管理机制-重传机制
  • 使用DaemonSet部署集群守护进程集
  • 用链表、信号,实现简易MP3项目
  • Docker 安装MySQL
  • 网页布局汇总
  • 【HarmonyOS Next之旅】DevEco Studio使用指南(十三) -> ArkTS/TS代码重构
  • 基础算法训练7
  • leetcode572 另一棵树的子树
  • React 组件样式
  • (已解决)如何安装python离线包及其依赖包 2025最新
  • 计算机操作系统——死锁(详细解释和处理死锁)
  • 编译原理 实验二 词法分析程序自动生成工具实验
  • 解决 Ubuntu 上 Docker 安装与网络问题:从禁用 IPv6 到配置代理
  • 【微知】如何将echo某个数据到文件然后cat出来结合在一起输出?(echo 1 | tee filea; cat fileb | tee fila)
  • 【图像生成之22】CVPR024—SwiftBrush基于变分分数蒸馏的文生图扩散模型
  • LeetCode hot 100—不同路径
  • 软考 系统架构设计师系列知识点之杂项集萃(49)
  • 【力扣hot100题】(093)最长公共子序列
  • 基于 Vue 3 + Express 的网盘资源搜索与转存工具,支持响应式布局,移动端与PC完美适配
  • 关于 Spring Boot 监控方式的详细对比说明及总结表格
  • CAN总线发送方每发送一位,接收方接收一位,但是当在非破坏性仲裁方式失利的情况下是否还能够正确接收数据呢?
  • 【C语言-全局变量】