我在Mac上,在终端上进行Android开发。我已经成功地创建了HelloWorld项目,现在我试图从Android模拟器中的命令行运行它。哪个命令运行HelloWorld项目的模拟器?
我已经有Android工具和平台工具在我的路径。
编辑:
如何告诉模拟器从命令行运行HelloWorld项目?我已经用ant构建了这个项目。
我在Mac上,在终端上进行Android开发。我已经成功地创建了HelloWorld项目,现在我试图从Android模拟器中的命令行运行它。哪个命令运行HelloWorld项目的模拟器?
我已经有Android工具和平台工具在我的路径。
编辑:
如何告诉模拟器从命令行运行HelloWorld项目?我已经用ant构建了这个项目。
当前回答
我假设你已经构建了你的项目,只需要启动它,但你没有创建任何avd,必须使用命令行进行所有操作。你必须做以下事情。
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. 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. 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>. 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.
其他回答
我使用Zenity编写了这个简单的shell脚本,允许您选择想要运行的avd。如果你没有定义ANDROID_HOME,你可以用模拟器的完整路径替换它。 使用select而不是Zenity也很容易做到这一点,但我选择了Zenity,因为我是从xfce-application菜单(虽然是.desktop-file)中运行它的。
#!/bin/sh
opt=$(zenity --title="Choose AVD" --text="Choose which emulator to start" --list \
--column="Devices" --separator="\n" `$ANDROID_HOME/emulator/emulator -list-avds`);
$ANDROID_HOME/emulator/emulator -avd $opt
打开CMD
打开命令提示符 在我的例子中输入模拟器的路径
C: \ adt - bundle - windows - x86_64 - 20140702 \ \ sdk工具
在我的例子中写“emulator -avd emulatorname”
-avd阿迪vd模拟器
我假设你已经构建了你的项目,只需要启动它,但你没有创建任何avd,必须使用命令行进行所有操作。你必须做以下事情。
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. 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. 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>. 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.
Mac使用zsh的说明:
打开终端窗口(CTRL+ALT+T) 运行命令 纳米~ / . zshrc 编辑您的个人资料 在打开的文件中添加如下行:
出口ANDROID_SDK_HOME = " ~ /图书馆/ Android Sdk”
别名模拟器=“ANDROID_SDK_HOME美元-模拟器,模拟器”
保存文件(CTRL+O, CTRL+X) 通过运行Source ~/命令获取概要文件的来源。或者注销再重新登录 运行以下命令进行测试:
模拟器-help或模拟器-list-avds 在终端中显示模拟器 运行Android模拟器:
模拟器-avd <name>
注意:将.zshrc替换为.bashrc对于bash也应该是一样的
打开命令提示符,进入<android-Home>\sdk\tools>emulator -avd <AVD_NAME>
这里“emulator”是用来打开Android虚拟设备的命令。