使用droidrun庫實現AI控制安卓手機
介紹
DroidRun 是一個框架,通過LLM代理控制 Android 設備。它允許您使用自然語言命令自動化 Android 設備交互。
安裝環境
安裝源碼依賴
git clone https://github.com/droidrun/droidrun.git
cd droidrun
conda create --name droidrun python=3.11 -y
conda activate droidrun
pip install -e .
安裝 ADB
-
Install ADB
-
macOS:
-
brew install android-platform-tools
-
Windows: 下載 Android SDK Platform Tools 平臺工具并解壓 ZIP 文件
-
-
驗證安裝
-
(droidrun) ? droidrun git:(main) adb version Android Debug Bridge version 1.0.41 Version 35.0.2-12147458 Installed as /opt/homebrew/bin/adb Running on Darwin 24.4.0 (arm64) (droidrun) ? droidrun git:(main)
-
安裝 DroidRun Portal 應用
- 下載地址
安裝到手機
這里我使用的安卓虛擬機
droidrun setup --path=/Users/hejh/Desktop/droidrun-portal-v0.1.0.apk
(droidrun) ? droidrun git:(main) ? droidrun devices
Found 1 connected device(s):? emulator-5554
(droidrun) ? droidrun git:(main) ? droidrun setup --path=/Users/hejh/Desktop/droidrun-portal-v0.1.0.apk
Using device: emulator-5554
Set DROIDRUN_DEVICE_SERIAL to: emulator-5554
Step 1/2: Installing APK: /Users/hejh/Desktop/droidrun-portal-v0.1.0.apk
Installation successful!
Step 2/2: Enabling accessibility service
Accessibility service enabled successfully!Setup complete! The DroidRun Portal is now installed and ready to use.
設置 API 密鑰
- 項目根目錄創建一個
.env
文件或設置環境變量
# Choose at least one of these based on your preferred provider
export OPENAI_API_KEY="your_openai_api_key_here"
export ANTHROPIC_API_KEY="your_anthropic_api_key_here"
export GEMINI_API_KEY="your_gemini_api_key_here"
可以只設置OPENAI_API_KEY
驗證設置
# Should list your connected device and show portal status
droidrun status
運行Demo
-
droidrun "打開設置" --provider openai --model gpt-4.1-mini
-
droidrun "打開Chrome,訪問 www.baidu.com, 然后搜索 Weather" --provider openai --model gpt-4o