我在Mac上,在终端上进行Android开发。我已经成功地创建了HelloWorld项目,现在我试图从Android模拟器中的命令行运行它。哪个命令运行HelloWorld项目的模拟器?
我已经有Android工具和平台工具在我的路径。
编辑:
如何告诉模拟器从命令行运行HelloWorld项目?我已经用ant构建了这个项目。
我在Mac上,在终端上进行Android开发。我已经成功地创建了HelloWorld项目,现在我试图从Android模拟器中的命令行运行它。哪个命令运行HelloWorld项目的模拟器?
我已经有Android工具和平台工具在我的路径。
编辑:
如何告诉模拟器从命令行运行HelloWorld项目?我已经用ant构建了这个项目。
当前回答
打开命令提示符,进入<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
在这里补充一下,每当你得到“错误:设备离线”意味着与模拟器和adb桥接器的连接由于模拟器启动所花费的时间而中断。
而不是重新启动模拟器在这一点上,尝试以下两个命令停止&启动adb桥再次。
亚行kill-server 亚洲开发银行启动服务器
列出所有已安装的设备:emulator -list-avds
这将列出安装在Android Studio中的所有设备。
运行模拟器:emulator -avd device_name
例如,如果你在运行选项1中的命令后得到了Pixel_3a_API_30_x86,那么你运行模拟器的命令将是:emulator -avd Pixel_3a_API_30_x86
在Mac(我认为还有Linux)上,创建AVD后,你可以创建一个别名: alias run-android='~/Library/Android/sdk/tools/emulator -avd ${YOUR_AVD_NAME} &'
注意:别名的执行不会锁定你的终端,如果你想这样做,只需删除最后一个'&'。
运行模拟器它自己会给你一个错误,因为他期望,在你当前的位置,你有:/emulator/qemu/${YOUR_PATFORM}/qemu-system-x86_64'来启动模拟器。
对于自动化(CI),我们采取了如下步骤:
Frist, find SDK's tools location, and store in variable for later use. tools=$ANDROID_HOME/cmdline-tools/latest/bin arch="x86_64" package="system-images;android-23;google_apis;$arch" Ensure Android-image's downloaded. $tools/sdkmanager "$package" Accept the licenses. echo yes | $tools/sdkmanager --licenses Create AVD. echo no | $tools/avdmanager create avd --force --name MyAVD --abi google_apis/$arch --package "$package" Says "no" to "Do you wish to create a custom hardware profile? ..." Launch emulator parallel. $ANDROID_HOME/emulator/emulator -netdelay none -netspeed full -no-snapshot-load -no-snapshot -avd MyAVD > /dev/null & Build APK. ./gradlew assembleDebug At last, Android-tests (Instrumented tests) automatically detect and run on Emulator. ./gradlew connectedAndroidTest Note that because we launch Emulator parallel, you need to wait until Emulator is ready, and that before Step #7. Maybe count build-time with script, and if build takes less than what Emulator-launch takes, call sleep.