我在Mac上,在终端上进行Android开发。我已经成功地创建了HelloWorld项目,现在我试图从Android模拟器中的命令行运行它。哪个命令运行HelloWorld项目的模拟器?

我已经有Android工具和平台工具在我的路径。

编辑:

如何告诉模拟器从命令行运行HelloWorld项目?我已经用ant构建了这个项目。


当前回答

如果您严格地试图从命令行运行模拟器,请在OSX中尝试此操作。

"/Applications/Android Studio.app/sdk/tools/emulator" -avd <NAMEOFDEVICE> -netspeed full -netdelay none

您可以通过向.bash_profile添加别名并将其发送到后台作业来简化它。

alias android='/Applications/Android\ Studio.app/sdk/tools/emulator <NAMEOFDEVICE> -netspeed full -netdelay none &'

让Bash知道这些变化。

source ~/.bash_profile

其他回答

打开命令提示符,进入<android-Home>\sdk\tools>emulator -avd <AVD_NAME>

这里“emulator”是用来打开Android虚拟设备的命令。

现在假设你已经安装了Android Studio(2.2)在我的情况下,只有一个模拟器,你可能会使用这一行

export ANDROID_SDK_ROOT=~/Library/Android/sdk/ && emulator '@'`emulator -list-avds`

如果你经常这样做,让它变得更容易:

$ echo 'export ANDROID_SDK_ROOT=~/Library/Android/sdk/' >> ~/.profile

向~.aliases添加别名

alias androidup="emulator '@'`emulator -list-avds`" 

召回到源~/。概要文件~ /。在测试之前使用别名

下次只需要$ androidup

如果您严格地试图从命令行运行模拟器,请在OSX中尝试此操作。

"/Applications/Android Studio.app/sdk/tools/emulator" -avd <NAMEOFDEVICE> -netspeed full -netdelay none

您可以通过向.bash_profile添加别名并将其发送到后台作业来简化它。

alias android='/Applications/Android\ Studio.app/sdk/tools/emulator <NAMEOFDEVICE> -netspeed full -netdelay none &'

让Bash知道这些变化。

source ~/.bash_profile

不建议使用android create avd命令。现在建议使用avdmanager来代替从命令行启动模拟器。

首先,如果模拟器不存在,创建一个新的模拟器:

avdmanager create avd --name "MyEmulator" -k "system-images;android-
26;google_apis;x86"

这里假设您已经安装了一个与API 26匹配的X86系统映像,并安装了谷歌API。

然后,您可以使用emulator @MyEmulator启动模拟器。

如果你有Git Bash,你可以双击打开模拟器,进行一些初始设置(仅在Windows 10中测试):

Open Git Bash. Run cd ~/AppData/Local/Android/sdk/emulator Run ./emulator -list-avds and keep note of the emulator's name. MY_EMULATOR for example. Open Notepad and add these two lines (insert your emulator's name instead of MY_EMULATOR): cd ~/AppData/Local/Android/sdk/emulator; ./emulator -avd MY_EMULATOR Save the file somewhere convinient as myfile.sh. You can change "myfile" as suits you best, but the extension .sh is needed. Open Git Bash at the directory where you stored myfile.sh and run chmod +x myfile.sh. Remember to put your file's name instead of myfile.

就是这样!从现在开始,每次你需要启动模拟器,只要找到你的myfile.sh,双击它,等待你的Android模拟器启动!