我在Mac上,在终端上进行Android开发。我已经成功地创建了HelloWorld项目,现在我试图从Android模拟器中的命令行运行它。哪个命令运行HelloWorld项目的模拟器?
我已经有Android工具和平台工具在我的路径。
编辑:
如何告诉模拟器从命令行运行HelloWorld项目?我已经用ant构建了这个项目。
我在Mac上,在终端上进行Android开发。我已经成功地创建了HelloWorld项目,现在我试图从Android模拟器中的命令行运行它。哪个命令运行HelloWorld项目的模拟器?
我已经有Android工具和平台工具在我的路径。
编辑:
如何告诉模拟器从命令行运行HelloWorld项目?我已经用ant构建了这个项目。
当前回答
在这里,你可以通过命令行查看执行该命令的选项:
emulator -avd avd_name [-option [value]] ... [-qemu args]
例如,我是这样使用它的:
emulator -avd ICS_ARM -wipe-data -no-boot-anim -cpu-delay 0
其他回答
我假设你已经构建了你的项目,只需要启动它,但你没有创建任何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.
使用dns帮助从命令行启动模拟器
模拟器程序位置:/Users/{{UserName}}/Library/Android/sdk/tools
检查现有avd:- 模拟器-list-avds 启动模拟器,设置dns /Users/{{UserName}}/Library/Android/sdk/tools/emulator -avd Pixel_API_26 -dns-server 8.8.8.8
在这里补充一下,每当你得到“错误:设备离线”意味着与模拟器和adb桥接器的连接由于模拟器启动所花费的时间而中断。
而不是重新启动模拟器在这一点上,尝试以下两个命令停止&启动adb桥再次。
亚行kill-server 亚洲开发银行启动服务器
如果您严格地试图从命令行运行模拟器,请在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 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