首页 > 解决方案 > 如何在用于启动 Android 模拟器的 AVD 管理器中获取等效命令行

问题描述

我认为 AVD 管理器实际上是在后台调用模拟器CLI 来启动模拟器。有没有办法查看调用的实际命令(如详细打印输出)?显然,人们总是可以相应地构造命令行参数,这个问题只是要求一种简单的方法来使用 AVD 管理器作为 GUI 生成命令。

标签: androidandroid-studioavdavd-manager

解决方案


在运行它之前以某种方式运行set -ex,以获得详细的输出。曾经写过一个包装模拟器的脚本。一般的名称AVD足以运行它;这是我用于运行测试的脚本:

#!/bin/bash
# it starts the Nexus 7 emulator.
# export ANDROID_SERIAL=emulator-5554
PROJECT=/some/project
AVD=Nexus_7_API_22

/home/google/android-sdk/emulator/emulator \
 -avd $AVD \
 -gpu host \
 -use-system-libs \
 -no-boot-anim \
 -verbose &
EMULATOR_PID=$!

adb wait-for-device

# wait for Android to finish booting
A=$(adb shell getprop sys.boot_completed | tr -d '\r')
while [ "$A" != "1" ]; do
    sleep 2
    A=$(adb shell getprop sys.boot_completed | tr -d '\r')
done
printf "emulator: boot completed."

# unlock the Lock Screen
# adb shell input keyevent 82

sleep 10

cd $PROJECT

# clear and capture logcat
adb logcat -c
adb logcat > ./results/logcat.log &
LOGCAT_PID=$!

# run connected tests
./gradlew mobile:connectedDebugAndroidTest -i

# stop the background processes
kill $LOGCAT_PID
kill $EMULATOR_PID

推荐阅读