有没有一种方法可以在不启动Android Studio的情况下运行模拟器。也许是从命令行。我知道这个功能在旧版本中是可用的,但从那以后就消失了。但也许有人已经知道怎么做了?


当前回答

试试这个

1. 完整的视频教程(适用于所有windows版本)

OR

2. 文本教程

Open the command prompt and change the directory where your sdk is placed D:\Softwares\Android\sdk\tools\bin> now add your avdmanager in this,now your full code is D:\Softwares\Android\sdk\tools\bin>avdmanager list avd it will show you a list of emulator device that you have already created after few seconds now typecd.. and run your emulator with this cmd, Here my emulator name is Tablet_API_25 so I have typed this name after the -avd. D:\Softwares\Android\sdk\tools>emulator -avd Tablet_API_25

编辑:对于Android Studio 3.2或更高版本,路径更改为D:\Softwares\Android\sdk\emulator\emulator -avd Tablet_API_25

例如:%ANDROID_HOME%\tools\emulator -avd [AVD NAME]

其他回答

对于Windows

如果任何人正在寻找快捷方式/批处理脚本- Gist -下载批处理文件。

@echo off
IF [%1]==[] (GOTO ExitWithPrompt)
set i=1
FOR /F "delims=" %%i IN ('emulator -list-avds') DO (
    set /A i=i+1
    set em=%%i
    if %i% == %1 (
        echo Starting %em%
        emulator -avd %em%
        EXIT /B 0
    )
)
GOTO :Exit
:ExitWithPrompt
emulator -list-avds
echo Please enter the emulator number to start

:Exit
EXIT /B 0

使用

D:\>start-emulator
Nexus_5_API_26
Please enter the emulator number to start

D:\>start-emulator 1
Starting Nexus_5_API_26
HAX is working and emulator runs in fast virt mode.

以下是我在windows中快速运行模拟器所做的: 我创建了一个这样的windows批处理文件:

start C:\Users\{Username}\AppData\Local\Android\Sdk\tools\emulator.exe -avd {Emulator_Name}

每次需要模拟器时运行批处理文件。

在Ubuntu 20.04中,我找到了以下解决方案

首先你需要导出Android路径变量。为此:

export ANDROID_SDK=~/Android/Sdk
export PATH=$ANDROID_SDK/emulator:$ANDROID_SDK/tools:$PATH

根据您的安装路径不同,路径可能会有所变化。如果Android Studio是使用Ubuntu软件安装的,那么路径将与上面所述相同。

如果导出工作正常,那么下面的命令应该列出您的AVD名称。

emulator -list-avds

在我的例子中,我得到了结果

Nexus_5_API_30

这是我的AVD的名字。

如果上面的命令列出了您的AVD名称,那么您可以通过以下方式运行您的AVD:

emulator @YOUR_AVD_NAME

对我来说

emulator @Nexus_5_API_30

您可以将导出命令添加到.bashrc文件中,以避免每次需要运行AVD时都输入导出命令。

你可以创建一个shell脚本并把它放在你的桌面:

Dim WinScriptHost
Set WinScriptHost = CreateObject("WScript.Shell")
WinScriptHost.Run "C:\Users\<user>\AppData\Local\Android\Sdk\emulator\emulator -avd <AVD_NAME>", 0
Set WinScriptHost = Nothing

用你的用户id替换<user>,用你的avd文件的名字替换<AVD_NAME>,例如pixel_2_api_28。

更新:2020/05 Windows 10

首先获取一个模拟器列表,打开CMD并运行:

cd %homepath%\AppData\Local\Android\Sdk\emulator

then

emulator -list-avds

接下来在上面的目录中创建emulator.exe的快捷方式,然后通过编辑Target:文本框更改其中的属性,如下所示

模拟器。. exe @YourDevice