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

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

问题描述

我使用 Mac,从终端进行 Android 开发.我已经成功创建了 HelloWorld 项目,现在我正在尝试运行它从 Android 模拟器中的命令行.哪个命令为我的 HelloWorld 项目运行模拟器?

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 是您需要的 API 级别.如果您可以使用 GUI,只需输入 android avd 它将启动管理器,您可以在其中执行相同的操作.您可以阅读更多关于通过 GUI 进行 AVD 管理通过命令行.
  2. 使用命令 emulator -avd 或通过先前启动的 GUI 运行 AVD.等到模拟器完全加载,这需要一些时间.您可以在此处了解其他选项.
  3. 现在您必须将应用程序安装到您的 AVD.通常在开发过程中,您只需使用与构建项目相同的 Ant 脚本,只需选择 install 目标.但是,您可以使用命令 adb install 手动安装该应用程序.
  4. 现在切换到模拟器并通过启动器像在任何普通设备上一样启动您的应用程序.或者,作为替代,您可以使用以下命令:adb shell am start -a android.intent.action.MAIN -n /.例如:adb shell am start -a android.intent.action.MAIN -n org.sample.helloworld/org.sample.helloworld.HelloWorld.正如评论者所建议的那样,您还可以将上面一行中的 org.sample.helloworld.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天全站免登陆