Skip to content

feat: support building for Android/Termux - #581

Open
JasonHuang79 wants to merge 2 commits into
MaaAssistantArknights:mainfrom
JasonHuang79:feat/android-termux-support
Open

JasonHuang79 wants to merge 2 commits into
MaaAssistantArknights:mainfrom
JasonHuang79:feat/android-termux-support

Conversation

@JasonHuang79

@JasonHuang79 JasonHuang79 commented Sep 26, 2026 •

Copy link
Copy Markdown
Member

我烧了一点token把 MAA-Meow 的一些功能搬过来了,考虑到这边一直没有 Android 适配,我加了一些东西
绝对不是我已经被llm惯坏了导致不会写代码了

以下是AI总结:

Add a workflow that cross-compiles maa-cli for Android and packages it together with the official MaaCore component, so maa-cli can run inside Termux on the device itself.

What's included:

  • .github/workflows/build-android.yml: builds aarch64/x86_64-linux-android with the Android NDK, downloads the official MAAComponent-android-*.tar.gz for MaaCore, converts the OCR models to ncnn (Android uses OcrPackNcnn; the shared resource only ships onnx), and assembles a runnable package.
  • android/maa-android-connect.sh: helper that connects MaaCore to the local adb (mDNS / root-set tcp port / common ports), since Termux cannot use the Android native control path.
  • Fix TLS on Android: rustls-platform-verifier needs an Android Context via JNI to initialize, which a plain Termux process has no access to; every HTTPS request panicked with "Expect rustls-platform-verifier to be initialized". Android now uses the bundled Mozilla roots, other platforms keep the platform verifier (so self-signed certs in corporate networks still work).

Verified on a rooted Android 12 x86_64 emulator: after deployment, maa fight 1-7 --times 10 ran to completion and reported drops. The packages set RPATH ($ORIGIN for libs, $ORIGIN/../lib for bin/maa) so no LD_LIBRARY_PATH is needed -- setting it leaked into the adb child process and made it load the NDK libc++, which broke the connection.

Sourcery 摘要

支持 maa-cli 在 Android 上的 Termux 中使用捆绑的 MaaCore 组件进行构建和运行,并支持 adb 连接以及兼容 Android 的网络功能。

新功能:

  • 为 aarch64 和 x86_64 Termux 环境添加定时和手动触发的 Android 构建,使用官方 MaaCore 组件和转换后的 OCR 资源对 maa-cli 进行打包。
  • 添加 Termux 辅助工具,可通过 adb 自动发现或连接本地 Android 设备。

错误修复:

  • 使用兼容 Android 的捆绑 TLS 根证书,避免在没有 Android 运行时上下文时 HTTPS 请求失败。

增强:

  • 使用自包含的库搜索路径打包 Android 二进制文件,并在非 Android 目标平台上保留平台证书验证。

构建:

  • 在 GitHub Actions 工作流中添加 Android NDK 交叉编译、MaaCore 组装、OCR 模型转换、构件打包、校验和生成以及构建验证。

CI:

  • 为 Android 构建流水线添加代码检查和工作流验证。

文档:

  • 在打包后的 README 中加入 Android Termux 安装、adb 连接、使用方法和已知限制的说明。
Original summary in English

Sourcery 总结

支持 maa-cli 在 Android 的 Termux 中构建和运行,并捆绑 MaaCore 支持、adb 连接功能以及兼容 Android 的网络功能。

新功能:

  • 为 aarch64 和 x86_64 Termux 环境添加定时和手动触发的 Android 构建流程,将 maa-cli 与官方 MaaCore 组件及转换后的 OCR 资源打包在一起。
  • 添加 Termux 辅助工具,用于通过 adb 发现并连接本地 Android 设备。

错误修复:

  • 使用兼容 Android 的内置 TLS 根证书,防止在没有 Android 运行时上下文的 Termux 中 HTTPS 请求失败。

增强功能:

  • 使用自包含的库路径打包 Android 二进制文件,同时在其他目标平台上保留平台证书验证功能。

构建:

  • 添加 Android NDK 交叉编译和打包工作流,包括 MaaCore 组装、OCR 模型转换、构建产物验证和校验和生成。

CI:

  • 为 Android 构建流水线添加代码检查和工作流验证。

文档:

  • 在 Android 软件包 README 中加入安装、adb 连接、使用方法和已知限制等说明。
Original summary in English

Summary by Sourcery

Enable maa-cli to build and run in Termux on Android with bundled MaaCore support, adb connectivity, and Android-compatible networking.

New Features:

  • Add scheduled and manually triggered Android builds for aarch64 and x86_64 Termux environments, bundling maa-cli with the official MaaCore components and converted OCR resources.
  • Add a Termux helper for discovering and connecting to the local Android device through adb.

Bug Fixes:

  • Use Android-compatible bundled TLS roots to prevent HTTPS requests from failing in Termux without an Android runtime context.

Enhancements:

  • Package Android binaries with self-contained library paths while retaining platform certificate verification on other targets.

Build:

  • Add an Android NDK cross-compilation and packaging workflow, including MaaCore assembly, OCR model conversion, artifact validation, and checksums.

CI:

  • Add linting and workflow validation for the Android build pipeline.

Documentation:

  • Include installation, adb connection, usage, and known-limit guidance in the Android package README.
Add a workflow that cross-compiles maa-cli for Android and packages it
together with the official MaaCore component, so maa-cli can run inside
Termux on the device itself.

What's included:
- .github/workflows/build-android.yml: builds aarch64/x86_64-linux-android
  with the Android NDK, downloads the official MAAComponent-android-*.tar.gz
  for MaaCore, converts the OCR models to ncnn (Android uses OcrPackNcnn;
  the shared resource only ships onnx), and assembles a runnable package.
- android/maa-android-connect.sh: helper that connects MaaCore to the local
  adb (mDNS / root-set tcp port / common ports), since Termux cannot use
  the Android native control path.
- Fix TLS on Android: rustls-platform-verifier needs an Android Context via
  JNI to initialize, which a plain Termux process has no access to; every
  HTTPS request panicked with "Expect rustls-platform-verifier to be
  initialized". Android now uses the bundled Mozilla roots, other platforms
  keep the platform verifier (so self-signed certs in corporate networks
  still work).

Verified on a rooted Android 12 x86_64 emulator: after deployment,
`maa fight 1-7 --times 10` ran to completion and reported drops. The
packages set RPATH ($ORIGIN for libs, $ORIGIN/../lib for bin/maa) so no
LD_LIBRARY_PATH is needed -- setting it leaked into the adb child process
and made it load the NDK libc++, which broke the connection.

@sourcery-ai sourcery-ai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

嗨——我已经审阅了你的更改,看起来非常棒!


Sourcery 对开源项目免费——如果你喜欢我们的审查结果,请考虑分享 ✨
Original comment in English

Hey - I've reviewed your changes and they look great!


Sourcery is free for open source - if you like our reviews please consider sharing them ✨
@codecov

codecov Bot commented Sep 26, 2026 •

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 72.58%. Comparing base (aebb5e9) to head (2001756).

Additional details and impacted files
@@            Coverage Diff             @@
##             main     #581      +/-   ##
==========================================
+ Coverage   72.36%   72.58%   +0.21%     
==========================================
  Files          72       72              
  Lines        6804     6756      -48     
  Branches     6804     6756      -48     
==========================================
- Hits         4924     4904      -20     
- Misses       1537     1557      +20     
+ Partials      343      295      -48     

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
@JasonHuang79

Copy link
Copy Markdown
Member Author

@wangl-cc 请求审查,我在这个仓库没有权限

`cargo deny check advisories` started failing with RUSTSEC-2026-0285:
rustls accepted TLS 1.3 handshake messages sent at the wrong encryption
level when they followed a key-changing message in the same record.
The advisory requires >= 0.23.45.

Note that a plain `cargo update -p rustls` is not enough: it only picks
0.23.43, which is still vulnerable. An explicit precise version is needed:

    cargo update -p rustls --precise 0.23.45

This also bumps rustls-webpki 0.103.13 -> 0.103.15 as a side effect.
@wangl-cc

Copy link
Copy Markdown
Member

为什么写了这么多的注释,而且我怎么感觉是把文档写进了脚本里呢?

@wangl-cc

Copy link
Copy Markdown
Member

另外,没必要单独建 Workflow,我们可以在 CI 和 Release 中都加上 Android。还有,我觉得没必要把 maa-cli 和 MaaCore 一起编译,能不能让 maa-cli 在 Android 上下载 MaaMeow 发布的 Core(如果他们发布了的话)?

@JasonHuang79

Copy link
Copy Markdown
Member Author

为什么写了这么多的注释,而且我怎么感觉是把文档写进了脚本里呢?

等我回去拷打大肥鱼()

@JasonHuang79

Copy link
Copy Markdown
Member Author

另外,没必要单独建 Workflow,我们可以在 CI 和 Release 中都加上 Android。还有,我觉得没必要把 maa-cli 和 MaaCore 一起编译,能不能让 maa-cli 在 Android 上下载 MaaMeow 发布的 Core(如果他们发布了的话)?

我本来是这么想的,但是后面发现他们的 Core 似乎有点不适配,等我一会去看看

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

2 participants