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


当前回答

mac专用解决方案(applescript)

下面的applescript将显示一个简单的GUI,允许你选择你想要启动的android图像。

该脚本可以从终端或ootb脚本编辑器中运行。运行▶。

你可以通过从脚本编辑器中选择将脚本转换为独立的Mac应用程序。app文件>导出…>文件格式:应用>保存到“/应用”文件夹。

### TODO! Set the correct path to your `emulator` command
set avds to paragraphs of (do shell script "~/Library/Android/sdk/emulator/emulator -list-avds")
set avd to (choose from list avds with prompt "Please select an AVD to start" default items "None" OK button name {"Start"} cancel button name {"Cancel"})
do shell script "~/Library/Android/sdk/emulator/emulator -avd " & avd & " -no-boot-anim > /dev/null 2>&1 &"

注意:要查找模拟器的正确路径,请在终端中运行-a模拟器。

为了从终端运行脚本,让它可执行(例如chmod +x android_launcher.sh),并在顶部添加以下shebang行:

#!/usr/bin/osascript

其他回答

你可以创建一个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。

以下是你需要做的:

1.Download and extract the SDK. 2.Open a terminal and navigate to the “tools” directory. 3.Launch the “android” tool (./android if you are currently in the tools directory). 4.Tick off the “SDK Platform” for each version of Android that you’d like to use in your emulator. 5.Click the “Install N Packages” button. 6.Click each package and tick off “Accept License” (legally, I’m probably required to tell you that this step may take several hours as you read each license ;). 7.Done with those licenses? Great. Click “Install”. Wait for the SDK manager to finish installing your packages, then you can close it. 8.Back in your terminal, still in the tools directory, enter ./android avd which will launch the Android Virtual Device Manager. 9.Click “New” and fill out the form to build the device you’d like to emulate. In the “Target” dropdown, you’ll see the SDK Platforms that you installed earlier. If the version you need is missing, you need to go back and install it. Click OK when you’re done. 10.Click on the device that you just created and click the “Start” button, tweak any options that you need on the Launch Options window, and click “Launch”.

也检查一下这个问题的答案。

我正在做一个React Native项目,我也遇到了这个问题

我在桌面上制作了一个可以快速打开的.bat文件,解决了这个问题

.bat文件的内容是

C:\Users\haria\AppData\Local\Android\sdk\emulator\emulator -avd Pixel_2_XL_API_27

haria是我的Windows用户名和 Pixel_2_XL_API_27是我的模拟器名称


如果您想查看模拟器名称,请打开CMD(或PowerShell)并键入(在Windows中)

cd C:\Users\haria\AppData\Local\Android\sdk\emulator

然后查看模拟器的名称

。/模拟器-list-avds

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

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

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

更新:2020/05 Windows 10

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

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

then

emulator -list-avds

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

模拟器。. exe @YourDevice