android studio Instant Run 问题

有的真机在android studio 编译运行apk的时候会出现

Error while executing: am startservice com.hikchina.police/com.android.tools.fd.runtime.InstantRunService
Starting service: Intent { act=android.intent.action.MAIN cat=[android.intent.category.LAUNCHER] cmp=com.hikchina.police/com.android.tools.fd.runtime.InstantRunService }
Error: Not found; no service started.

的错误,究其原因 是因为android studio2.3版本添加了Instant Run(快速运行)  意在android studio使用开发者提高开发效率,不需要重新打包即可看见运行效果



Instant Run

根据官方文档说明:

Although your first build may take longer to complete, Instant Run pushes subsequent updates to your app without building a new APK, so changes are visible much more quickly. 
尽管第一次build的时间会花费更长的时间,但是Instant Run可以在后续更新APP时不需要创建新的APK,所以改变是快速可见的.


Instant Run的缺陷

在测试的时候对代码进行修改时,再运行会很快打开当前已经打开的Activity并更新内容(当修改UI时会非常明显).更新APK的速度确实是会非常快.但是他的缺点也是很明显的:

Instant Run is supported only when you deploy the debug build variant, use Android Plugin for Gradle version 2.0.0 or higher, and set minSdkVersion to 15 or higher in your app’s module-level build.gradle file. For the best performance, set minSdkVersion to 21 or higher. 
首先只有使用Gradle 2.0以上版本可用,最低minSdkVersion必须是15或者以上,需要得到更好体验应该设置SDK 21以上.另外,只会在部署变化的调试版本时支持 
(部分翻译有误请指出)

所以这就说明了当系统API并没有达到21时非常有可能是无法支持的.虽然在实际中不能用的机子有一部分是5.0系统的,但并没有什么卵用…


解决方案

解决方案是建议在发部测试版本的时候如果测试的机子系统覆盖范围比较大(包括很多低版本系统时),可以关闭该功能并重新打包发布即可. 
官方说明关闭方法如下:

To disable Instant Run:

  • Open the Settings or Preferences dialog.
  • Navigate to Build, Execution, Deployment > Instant Run.
  • Uncheck the box next to Enable Instant Run. 
    打开设置->Build->Execution->Deployment->Instant Run->取消Enable即可

我在我的Android Studio上并没有发现这个结构层次,建议用以下的办法会更容易也比较适用所有类型的Android Studio

  • 打开Preferences或者Settings
  • 在左上角搜索框中搜索Instant Run
  • 左侧边选择Instant Run选项,选择第一个Enable取消打勾

我的选项显示的是:

Enable Instant Run to hot swap code/resource changes on deploy(default enabled)


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值