我在Mac上,在终端上进行Android开发。我已经成功地创建了HelloWorld项目,现在我试图从Android模拟器中的命令行运行它。哪个命令运行HelloWorld项目的模拟器?

我已经有Android工具和平台工具在我的路径。

编辑:

如何告诉模拟器从命令行运行HelloWorld项目?我已经用ant构建了这个项目。


当前回答

列出所有已安装的设备:emulator -list-avds

这将列出安装在Android Studio中的所有设备。

运行模拟器:emulator -avd device_name

例如,如果你在运行选项1中的命令后得到了Pixel_3a_API_30_x86,那么你运行模拟器的命令将是:emulator -avd Pixel_3a_API_30_x86

其他回答

(Linux) 在你的终端复制粘贴和改变三个蓝色的字段

/home/YouUser/Folder/adt-bundle-linux-x86_64-20140702/sdk/tools/emulator64-x86 -avd Android5.1.1

YouUser = user of session in linux
Folder = path of folfer
Android5.1.1 = You version of android in the emulator,for example (Android4.4.2)

你可以在你的文件夹home中查看模拟器 cd /home/Youuser/.android/avd/

对于自动化(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.

我假设你已经构建了你的项目,只需要启动它,但你没有创建任何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.

Windows 10对我的帮助:

1 cd C:\Users\xxx\AppData\Local\Android\Sdk\emulator

列出所有可用的:emulator -list-avds

3启动NON-GUI模式:模拟器-avd Pixel_3a_API_30_x86 -no-window

如果你已经有模拟器,并想使用使用命令,只需使用这一行代码

cd  C:\Users\yourUserName\AppData\Local\Android\Sdk\emulator | ./emulator -avd Pixel_5_API_32

回头谢谢我……