如何从命令行启动Android模拟器? [英] How do I launch the Android emulator from the command line?

查看:409
本文介绍了如何从命令行启动Android模拟器?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在Mac上,从终端工作在Android开发。我已成功创建 HelloWorld 项目,现在我尝试从命令行运行它在Android模拟器。

I'm on Mac, working on Android development from the terminal. I have successfully created the HelloWorld project and now I'm trying to run it from the command line in the Android emulator. Which command runs the emulator for my HelloWorld project?

我已经在我的PATH中安装了Android工具和平台工具。

I already have the Android tools and platform-tools in my PATH.

编辑:

如何告诉仿真器从命令行运行HelloWorld项目?我已经用蚂蚁建立了这个项目。

How do I tell the emulator to run my HelloWorld project from the command line? I've already built the project with ant.

推荐答案

我假设你已经建立了你的项目,但是您没有创建任何AVD,并且必须对所有操作使用命令行。您必须执行以下操作。

I assume that you have built your project and just need to launch it, but you don't have any AVDs created and have to use command line for all the actions. You have to do the following.


  1. 为所需的平台创建新的虚拟设备(AVD)。如果你必须使用命令行创建你的AVD,你可以调用 android create avd -n< name> -t< targetID> 其中targetID是您需要的API级别。如果你可以使用GUI,只需键入 android avd ,它会启动管理器,在那里你可以做同样的。您可以详细了解通过GUI管理AVD 通过命令行

  2. 运行或者通过使用命令 emulator -avd< name> 或通过先前启动的GUI来执行AVD。等待仿真器完全加载,需要一些时间。您可以在这里阅读其他选项。 li>
  3. 现在您必须将应用程序安装到AVD。通常在开发期间,您只需使用与用于构建项目相同的Ant脚本,只需选择 install target。但是,您可以使用命令 adb install< path-to-your-APK> 手动安装应用程序。

  4. 仿真器和启动您的应用程序,如在任何正常的设备,通过启动器。或者,您也可以使用以下命令: adb shell am start -a android.intent.action.MAIN -n< package> /< activity class> 。例如: adb shell am start -a android.intent.action.MAIN -n org.sample.helloworld / org.sample.helloworld.HelloWorld 。正如评论者所建议的,你也可以用 .HelloWorld 替换上面一行中的 org.sample.helloworld.HelloWorld ,它也会工作。

  1. Create a new virtual device (AVD) for the platform you need. If you have to use command line for creating your AVD, you can call android create avd -n <name> -t <targetID> where targetID is the API level you need. If you can use GUI, just type in android avd and it will launch the manager, where you can do the same. You can read more about AVD management through GUI and through command line.
  2. Run the AVD either by using command emulator -avd <name> or through previously launched GUI. Wait until the emulator fully loads, it takes some time. You can read about additional options here.
  3. Now you have to install the application to your AVD. Usually during development you just use the same Ant script you used to build the project, just select install target. However, you can install the application manually using command adb install <path-to-your-APK>.
  4. Now switch to emulator and launch your application like on any normal device, through the launcher. Or, as an alternative, you can use the following command: adb shell am start -a android.intent.action.MAIN -n <package>/<activity class>. For example: adb shell am start -a android.intent.action.MAIN -n org.sample.helloworld/org.sample.helloworld.HelloWorld. As a commenter suggested, you can also replace org.sample.helloworld.HelloWorld in the line above with just .HelloWorld, and it will work too.

这篇关于如何从命令行启动Android模拟器?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆