Skip to content

从源码构建

本页介绍如何从源码构建 Local Dream。构建结果与 GitHub Releases 发布的 APK 完全一致。

TIP

推荐在 LinuxWSL 上构建。macOS 和 Windows 也可以构建,但验证较少。

前置要求

需要以下工具:

  • Rust — 通过 rustup 安装,然后固定版本为 1.84.0

    bash
    rustup default 1.84.0   # 必须使用 1.84.0;更新的版本会导致构建失败
    rustup target add aarch64-linux-android
  • Ninja — 构建系统

  • CMake — 构建配置

  • Android Studio — 用于最终的 APK 打包

1. 克隆仓库

bash
git clone --recursive https://github.com/xororz/local-dream.git

--recursive 参数是必需的——子模块包含构建依赖。

2. 准备 SDK

  1. QNN SDK 2.39 — 下载 v2.39.0.250926.zip 并解压。
  2. Android NDK — 从 Android NDK 下载页获取并解压。
  3. 在以下两个文件中更新 SDK 路径:
    • app/src/main/cpp/CMakeLists.txt 中的 QNN_SDK_ROOT
    • app/src/main/cpp/CMakePresets.json 中的 ANDROID_NDK_ROOT

3. 构建原生库

Linux

bash
cd app/src/main/cpp/
bash ./build.sh

Windows

powershell
# 如需安装构建工具:
# winget install Kitware.CMake
# winget install Ninja-build.Ninja
# winget install Rustlang.Rustup

cd app\src\main\cpp\

# 转换补丁文件的换行符(如需安装 dos2unix:
#   winget install -e --id waterlan.dos2unix)
dos2unix SampleApp.patch
.\build.bat

macOS

bash
# 使用 Homebrew 安装构建工具:
# brew install cmake rust ninja

# 修复 macOS 上较新版本 CMake 的策略兼容性问题
sed -i '' '2s/$/ -DCMAKE_POLICY_VERSION_MINIMUM=3.5/' build.sh
bash ./build.sh

4. 构建 APK

在 Android Studio 中打开项目,然后:

Build → Generate App Bundles or APKs → Generate APKs

APK 输出到 app/build/outputs/apk/