ARTICLE DETAIL

资讯详情

深耕网站建设、视觉设计与SEO优化的一线实战洞察。

Ente 移动应用自托管构建指南:使用 --dart-define 连接自定义服务器

Ente 移动应用自托管构建指南:使用 --dart-define 连接自定义服务器 Ente 移动应用自托管构建指南使用 --dart-define 连接自定义服务器【免费下载链接】ente End-to-end encrypted cloud for everything.项目地址: https://gitcode.com/GitHub_Trending/en/ente导读本文是 Ente 自托管文档中《Building mobile apps》的完整实战指南讲解如何从源码构建 Ente Photos 与 Ente Auth 移动应用并通过--dart-defineendpoint参数让应用连接到你自己部署的服务器而非官方api.ente.com。读完本文你将掌握从环境准备、源码构建到 release 包产出的完整流程并理解 endpoint 参数在客户端源码中的解析机制。一、核心原理endpoint参数如何生效自托管用户最大的诉求是把应用指向自己的服务器。在 Ente 移动端这个诉求通过 Flutter 的--dart-define编译期参数实现其底层由 endpoint_config.dart 解析static const defaultEndpoint String.fromEnvironment( endpoint, defaultValue: kDefaultProductionEndpoint, );即构建时传入--dart-defineendpointhttp://localhost:8080该值会被编译进应用若不传则回退到生产默认值。生产默认值定义在 constants.dartconst kDefaultProductionEndpoint https://api.ente.com; const kLegacyProductionEndpoint https://api.ente.io;EndpointConfig还提供了运行时覆盖能力存储在SharedPreferences的endpoint键会优先于编译期默认值详见EndpointConfig.endpointgetter这也是后文开发设置中手动填 endpoint 的原理。isProduction则依据 endpoint 是否等于生产值来判断当前构建是否连接官方服务。二、环境准备构建 Ente 移动应用前请确认以下依赖Flutter v3.47.2Ente Photos 与 Ente Auth 的 README 均指定此版本见 photos/README.md 与 auth/README.mdRust 工具链Photos 应用依赖 Rust 生成的 FRB 绑定rust/bindings/frb/Git submoduleAuth 应用构建前需初始化子模块。Ente 采用 Flutter workspace 组织多应用mobile/pubspec.yaml 中声明了 Dart SDK 版本约束sdk: 3.10.0 4.0.0并将apps/auth、apps/locker、apps/photos及大量内部包纳入同一个 workspace。因此依赖安装需在工作区内执行flutter pub get --enforce-lockfile说明--enforce-lockfile要求严格按pubspec.lock解析依赖保证与官方 CI 构建一致。对 Photos 应用若 FRB 导出面rust/bindings/frb/有变更还需重新生成绑定(cd $(git rev-parse --show-toplevel)/rust cargo codegen frb)三、构建 Photos 应用并连接自托管服务器在 mobile/apps/photos/README.md 的指导下完整流程如下cd ente/mobile flutter pub get # Android flutter run --dart-defineendpointhttp://localhost:8080 --flavor independent --debug -t lib/main.dart # iOS flutter run --dart-defineendpointhttp://localhost:8080关键点拆解--dart-defineendpointhttp://localhost:8080将 endpoint 编译进应用替换默认的https://api.ente.com。http://localhost:8080是本地开发服务器的典型地址实际部署时应替换为你的服务器地址局域网 IP 或域名如http://192.168.1.100:8080--flavor independentAndroid必须指定 flavor。从 android/app/build.gradle 可见 Photos 定义了independent、dev、playstore、fdroid四个 flavor其中independent对应 GitHub Releases 中的独立发行版applicationIdSuffix .independent-t lib/main.dart显式指定入口文件。iOS 构建无需 flavorflutter run即可。仓库中的性能测试脚本也印证了该参数的标准用法例如 app_init_perf_test.sh 中export ENDPOINThttps://api.ente.com flutter drive \ --drivertest_driver/perf_driver.dart \ --targetintegration_test/app_init_test.dart \ --dart-defineendpoint$ENDPOINT \ --profile --flavor independent四、构建 Auth 应用2FA 应用Ente Auth 的构建流程与之类似但多一步 submodule 初始化cd ente/auth git submodule update --init --recursive flutter pub get flutter run --dart-defineendpointhttp://localhost:8080 # Android flutter run --dart-defineendpointhttp://localhost:8080 --flavor independent --debug -t lib/main.dart # iOS flutter run --dart-defineendpointhttp://localhost:8080auth/README.md 同样要求 Flutter v3.47.2并明确 Android 下flutter run --flavor independent、iOS 下直接flutter run、macOS 下flutter run -d macos。Auth 应用的开发设置界面也会读取当前 endpoint并在非生产值非kDefaultProductionEndpoint时显示服务器地址提示见 developer_settings_widget.dart。五、构建 release非 debug包调试完成后产出正式安装包的命令如下Android APKflutter build apk --release --flavor independent -t lib/main.dart构建前需先配置签名密钥库按 Flutter 官方文档创建 upload keystore在仓库根目录的key.properties或环境变量中配置签名信息。Photos 的 Gradle 配置支持两种来源见 build.gradle优先读取key.properties否则读取SIGNING_KEY_ALIAS、SIGNING_KEY_PASSWORD、SIGNING_STORE_PASSWORD环境变量若需要连接自托管服务器同样追加--dart-defineendpoint...。iOSflutter build ios提示iOS 构建需在 macOS 上进行更新 Flutter 依赖后需在ios/目录执行pod install并提交ios/Podfile.lock的变更Photos 与 Auth 的 README 均有说明。六、运行期备用方案开发设置切换服务器--dart-define属于编译期配置重新编译才能更改。如果只是临时体验自托管服务器Ente 还提供了运行期方案在应用启动/欢迎页连续点击 7 次进入开发设置Developer Settings直接填写服务器 endpoint无需重新构建。该方案对应的完整说明见 post-install/index.md 的 Step 6: Configure apps to use your server其底层正是EndpointConfig.setEndpoint将值写入本地偏好并广播EndpointUpdatedEvent。七、常见问题与注意事项flavor 缺失报错Android 构建必须带--flavor independent否则无法匹配 Gradle 中定义的productFlavorssubmodule 未初始化Auth 应用若跳过git submodule update --init --recursiveflutter pub get会因缺失依赖包而失败endpoint 必须客户端可达localhost:8080仅适用于模拟器或同一台机器真机调试请使用局域网 IP 或域名并确认服务器已按 self-hosting 快速开始 启动。若自托管服务器使用对象存储如 MinIO还需注意 endpoint 需同时被 museum 与客户端解析否则上传会静默失败详见 post-install 文档中对 S3 endpoint 可达性的说明生产默认值回退不带--dart-defineendpoint构建的应用默认连接https://api.ente.com请勿将未定制的 debug 包分发为自托管版本开发设置与编译参数的关系开发设置运行时写入优先级高于编译期--dart-define默认值两者同时存在时以开发设置中的值为准。参考文档Ente Photos 构建说明Ente Auth 构建说明自托管后配置应用 endpoint自托管快速开始【免费下载链接】ente End-to-end encrypted cloud for everything.项目地址: https://gitcode.com/GitHub_Trending/en/ente创作声明:本文部分内容由AI辅助生成(AIGC),仅供参考
返回列表