在模拟器中重新加载 Android 应用程序而不在 Eclipse 中重新启动模拟器?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/728077/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Reload Android application in emulator without restarting emulator in Eclipse?
提问by Tai Squared
Is there a way to reload an Android application in the emulator without closing the emulator, saving any code changes, and running the emulator again? If I make even a simple change to the layout, it takes about 30 seconds by time I run it in Eclipse and Android "boots", and I can unlock the emulator to run the application. Is there any way to shorten this time when making changes, or is it something I just have to deal with?
有没有办法在不关闭模拟器、保存任何代码更改并再次运行模拟器的情况下在模拟器中重新加载 Android 应用程序?如果我对布局进行简单的更改,我在 Eclipse 和 Android“启动”中运行它大约需要 30 秒,并且我可以解锁模拟器以运行应用程序。有什么办法可以在进行更改时缩短这个时间,还是我必须处理的事情?
回答by Kevin Williams
The Android emulator is hot-deployable. Once you save and click 'run'
(assuming no compile errors) it will package and re-deploy to the emulator which will then restart the app to run the new version. The same is true if you have an Android Developer Phone connected via USB.
Android 模拟器是可热部署的。保存并单击'run'
(假设没有编译错误)后,它将打包并重新部署到模拟器,然后模拟器将重新启动应用程序以运行新版本。如果您有通过 USB 连接的 Android 开发者手机,情况也是如此。
If you get the message "Warning: Activity not started, its current task has been brought to the front", it helps to quit/move from the front the running app in the emulator by pressing the back button. Seems like Android does not overwrite the running app in this case.
如果您收到消息“警告:活动未启动,其当前任务已被带到前面”,这有助于通过按后退按钮从前面退出/移动模拟器中正在运行的应用程序。在这种情况下,Android 似乎不会覆盖正在运行的应用程序。
回答by Adil Malik
In Eclipse go to Run -> Run Configuration ...
在 Eclipse 中,转到运行 -> 运行配置...
For the very first time you need to set the following highlighted option because you don't have any emulator already launched.
第一次您需要设置以下突出显示的选项,因为您还没有启动任何模拟器。
After the first run now you have an emulator already running. Now when you make a change again go to Run -> Run Configuration ...
在第一次运行之后,您现在已经运行了一个模拟器。现在,当您再次进行更改时,请转到 Run -> Run Configuration ...
and Set the following highlighted option:
并设置以下突出显示的选项:
Now the already running emulator will be used every time to relaunch your application and it takes a way less time.
现在每次都将使用已经运行的模拟器来重新启动您的应用程序,并且花费的时间更少。
Note:Every time before clicking the Runbutton press the backbutton in your emulator once. So, your application is no more running on emulator. Otherwise you might see the following warning:
注意:每次单击运行按钮之前,请按一次模拟器中的后退按钮。因此,您的应用程序不再在模拟器上运行。否则,您可能会看到以下警告:
Warning: Activity not started, its current task has been brought to the front
警告:Activity 未启动,其当前任务已被置于最前面
回答by Gustavo
You have already been told that you don't need to restart the emulator, but now with Android Studio 2.0 you don't even need to restart your app. It has a new feature called Instant Runthat allows you to update your app without having to restart it.
您已经被告知不需要重新启动模拟器,但现在使用 Android Studio 2.0,您甚至不需要重新启动应用程序。它有一项名为Instant Run的新功能,可让您无需重新启动即可更新您的应用程序。
Simply enable it in Preferences:
只需在首选项中启用它:
And run:
并运行:
More info in this link.
此链接中的更多信息。
回答by Vijay C
instead of running from eclipse, use following batch files in project directory to install and uninstall the apk. Those work great and fast.
不要从 Eclipse 运行,而是使用项目目录中的以下批处理文件来安装和卸载 apk。那些工作得又好又快。
Install.bat
安装.bat
cd bin
adb install *.apk
Uninstall.bat
卸载.bat
adb uninstall this.is.package.name