返回首页

Android 上的 OpenClaw:Termux 指南

使用 Termux 和 proot-Ubuntu 在 Android 上部署 OpenClaw 网关的说明。描述 Node.js 安装、Bionic 错误绕过、安全设置和消息集成。适合将旧智能手机改造成 AI 服务器。

智能手机上的 OpenClaw AI 服务器:完整指南
Advertisement 728x90

在 Android 上通过 Termux 和 proot 部署 OpenClaw 网关

开发者可以将闲置的 Android 智能手机改造成 OpenClaw(一款开源 AI 助手)的网关。本指南已在小米 11T(搭载天玑 1200 处理器、8GB RAM、HyperOS 1.0.14.0)上测试通过。该方法使用 Termux 配合 proot-Ubuntu 环境来运行 Node.js 22 LTS 和 OpenClaw,从而绕过 Android 系统对托管网关的限制。

要求:Android 10 及以上版本、4GB 以上 RAM、稳定的 Wi-Fi 连接、来自 OpenRouter 或 Gemini 的 API 密钥。存储空间:约 4 GB。

准备环境

首先安装 F-Droid,然后从中安装 Termux 和 Termux:API。

Google AdInline article slot

在 Termux 中运行:

pkg update && pkg upgrade -y
pkg install proot-distro -y
proot-distro install ubuntu
proot-distro login ubuntu

在 Ubuntu 环境中:

apt update && apt upgrade -y
apt install -y curl git build-essential
curl -fsSL https://deb.nodesource.com/setup_22.x | bash -
apt install -y nodejs
node -v  # 应为 v22.16 及以上版本

安装 OpenClaw:

Google AdInline article slot
npm install -g openclaw@latest
openclaw --version

绕过 Bionic 错误

如果网关因 os.networkInterfaces() 或 EACCES 错误而崩溃,请应用此补丁:

创建 /root/bionic-bypass.js

const os = require('os');
const _originalNetworkInterfaces = os.networkInterfaces;

os.networkInterfaces = function() {
  try {
    return _originalNetworkInterfaces.call(os);
  } catch (e) {
    return {
      lo: [{
        address: '127.0.0.1',
        netmask: '255.0.0.0',
        family: 'IPv4',
        mac: '00:00:00:00:00:00',
        internal: true,
        cidr: '127.0.0.1/8'
      }]
    };
  }
};

创建文件的命令:

Google AdInline article slot
cat <<'EOF' > /root/bionic-bypass.js
const os = require('os');
const _originalNetworkInterfaces = os.networkInterfaces;

os.networkInterfaces = function() {
  try {
    return _originalNetworkInterfaces.call(os);
  } catch (e) {
    return {
      lo: [{
        address: '127.0.0.1',
        netmask: '255.0.0.0',
        family: 'IPv4',
        mac: '00:00:00:00:00:00',
        internal: true,
        cidr: '127.0.0.1/8'
      }]
    };
  }
};
EOF
echo 'export NODE_OPTIONS="-r /root/bionic-bypass.js"' >> ~/.bashrc
source ~/.bashrc

如需恢复:sed -i '/bionic-bypass/d' ~/.bashrc && rm -f /root/bionic-bypass.js && source ~/.bashrc

配置并启动网关

启动设置向导:

openclaw onboard

选择:

  • 网关绑定:回环地址(无需 root 权限的唯一安全选项)。
  • 提供商:OpenRouter(免费模型)、Gemini、OpenAI。
  • 输入您的 API 密钥。

在 tmux 中启动(通过 apt install tmux 安装):

tmux new -s oc
openclaw gateway --verbose

分离会话:Ctrl+B,D。重新连接:tmux attach -t oc

Web 控制面板:http://127.0.0.1:18789。令牌:openclaw config get gateway.auth.token

防止 Android 终止进程

  • 在 Termux 中运行 termux-wake-lock
  • 设置 → 电池 → Termux → 无限制。
  • 对于小米/HyperOS:

- 电池 → 后台活动 → Termux → 无限制。

- 应用 → Termux → 自启动:启用。

验证清单:

| 命令/操作 | 预期结果 |

|------------------|---------------------|

| openclaw --version | 显示版本号且无错误 |

| openclaw gateway --verbose | 运行超过 30 秒 |

| http://127.0.0.1:18789 | 控制界面加载成功 |

| 在界面中输入令牌 | 连接成功 |

| 发送测试消息 | 收到 AI 回复 |

消息平台集成

支持平台:Telegram(grammY)、WhatsApp(Baileys)、Discord、Slack、Signal 等。通过设置向导或控制界面配置。免费模型的响应延迟:5–10 秒。

关键要点

  • 使用回环地址绑定以降低安全风险。
  • 将 API 密钥存储在安全配置中。
  • 通过 docs.openclaw.ai 更新 Node.js 和 OpenClaw。
  • tmux 对会话持久性至关重要。
  • 完全禁用电池优化。

— Editorial Team

Advertisement 728x90

继续阅读