Instant Run
http://tools.android.com/tech-docs/instant-run
N Developer Preview users: Instant Run is currently incompatible with the Jack toolchain. This new toolchain is required to use Java 8 language features supported by Android N. To learn more, read about the new Java 8 language features and Jack.
Introduced in Android Studio 2.0, Instant Run is a behavior for the Run and Debug
commands that significantly reduces the time between updates to your app. Instant Run pushes changes to methods and existing app resources without building a new APK, so code changes are visible almost instantly.
Instant Run is supported only while deploying a debug build variant, using Android Plugin for Gradle version 2.0.0 or higher, and targeting devices running Android 4.0 (API level 15) and higher.
After deploying an app, a small, yellow thunderbolt icon appears within the Run button (or Debug
button), indicating that Instant Run is ready to push updates the next time you click the button. Instead of building a new APK, it pushes just those new changes and, in some cases, the app doesn't even need to restart but immediately shows the effect of those code changes.
Note: Instant Run temporarily disables the Java Code Coverage Library (JaCoCo) and ProGuard. Because Instant Run only works with debug builds, this should not affect your release build.
Instant Run pushes updated code and resources to your connected device or emulator by performing a hot swap, warm swap, or cold swap. It automatically determines the type of swap to perform based on the type of change you made. The following table describes how Instant Run behaves when certain code changes are pushed to a target device.
Code Change | Instant Run Behavior |
---|---|
|
Supported with hot swap: This is the fastest type of swap and makes changes visible almost instantly. Your application keeps running and a stub method with the new implementation is used the next time the method is called. |
|
Supported with warm swap: This swap is still very fast, but requires an automatic activity restart when Instant Run pushes the changed resources to the target device. Your app keeps running, but a small flicker may appear on the screen as the activity restarts—this is normal. |
Structural code changes, such as:
|
Supported with cold swap (API level 21 or higher): Instant Run pushes the structural code changes to the target device and restarts the whole app. For target devices running API level 20 or lower, Android Studio deploys a full build of the APK. |
|
When making changes to the app manifest or resources referenced by the manifest, Android Studio automatically deploys a new build in order to push changes to your target device. This is because certain information about the app, such as its name, app icon resources, and intent filters, are determined from the manifest when the APK is installed on the device. If your build process automatically updates any part of the app manifest, such as automatically iterating |
By default, Android Studio automatically restarts the current activity after performing a hot swap, while the app keeps running. To disable this setting:
- Open the Settings or Preferences dialog.
- Navigate to Build, Execution, Deployment > Instant Run.
- Uncheck the box next to Restart activity on code changes.
If automatic activity restart is disabled, you can manually restart the current activity from the menu bar by selecting Run > Restart Activity.
Using Rerun
When pushing certain code changes, such as changes to an app's onCreate()
method, you will need to restart your running app for the changes to take effect. You can click Rerun to stop the app, perform an incremental build, and restart the app.
If you need to deploy a clean build, select Run > Clean and Rerun 'app' from the main menu, or hold down the Shift key while clicking Rerun
. This action stops the running app, performs a full clean build, and deploys the new APK to your target device.
Setting up your project for Instant Run
Android Studio enables Instant Run by default for projects built using Android Plugin for Gradle 2.0.0 and higher.
To update an existing project with the latest version of the plugin:
- Open the Settings or Preferences dialog:
- On Windows or Linux, select File > Settings from the menu bar.
- On Mac OSX, select Android Studio > Preferences from the menu bar.
Navigate to Build, Execution, Deployment > Instant Run and click Update Project, as shown in figure 1.
If the option to update the project does not appear, it’s already up-to-date with the latest Android Plugin for Gradle.
Figure 1. Updating the Android Plugin for Gradle for an existing project.
Things you should know
Instant Run is designed to work in most situations and to speed up the build and deploy process on a best-effort basis. However, there are some aspects to using Instant Run that you should be aware of.
Legacy Multidex with Android 5.0 or higher
When using Instant Run with a project configured for Legacy Multidex—that is, when build.gradle
is configured withmultiDexEnabled true
and minSdkVersion 20
or lower—build performance may decrease when deploying a clean build to target devices running Android 5.0 (API level 21) or higher.
After the initial clean build, incremental builds are significantly faster, and Instant Run deploys code and resource changes as normal. To improve clean build performance during development, consider creating a product flavor withminSdkVersion 21
.
Exceeding the 64K DEX limit
In order to push updates to a running app, Instant Run needs to add additional methods to every debug APK–approximately 140 plus three times the number of classes and their local dependencies. This also increases the total number of methods referenced by the app’s DEX file.
If an app was previously approaching the 64K reference limit, enabling Instant Run may push it over this limit and cause a build error. Learn how to overcome this issue by configuring apps for Multidex.
Deploying to multiple devices
Instant Run uses different techniques to perform hot, warm, and cold swaps that are specific to the API level of the target device. For this reason, while deploying an app to multiple devices at once, Android Studio temporarily turns off Instant Run.
Instrumentation tests
Instrumentation tests load both the debug APK and a test APK into the same process on a test device, allowing control methods to override the normal lifecycle of the app and perform tests. While running or debugging instrumentation tests, Android Studio does not inject the additional methods required for Instant Run and turns the feature off.
While profiling an app, you should disable Instant Run. There is a small performance impact when using Instant Run and a slightly larger impact when overriding methods with a hot swap. This performance impact could interfere with information provided by performance profiling tools. Additionally, the stub methods generated with each hot swap can complicate stack traces.
Disabling Instant Run
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.
We Want Your Feedback!
Instant Run is currently available only in Android Studio 2.0, which is still in the Beta Channel (and Android Studio 2.1 in Canary.) Over the next little while, we will continue to improve the feature, stabilize it as we move the release to the Stable channel.
Here are also some known issues that we are working on:
Apps that are using legacy multi-dex (with minSdkVersion < 21), with a main dex file near the 65K method limit may not build. This would require reworking the app to make room in the main dex list by reducing the number of classes required in the main dex file.
We have tested Instant Run on many devices, but it’s impossible to try it on every single device model. Please let us know if Instant Run doesn’t work on your device.
We have seen some intermittent issues where the IDE loses connection with the app which will trigger a full rebuild.
We have not yet tested this feature with 3rd party Gradle plugins, especially those that have not been updated to use the new transforms API. If you run into issues, please let us know.
Data-binding is broken in this build; we will restore this shortly.
If you run into any additional issues, please help by logging bugs in our public Issues Tracker. You can create an issue viathis link or by clicking on Help → Submit Feedback directly in Android Studio.
Instant Run的更多相关文章
- Error running app: This version of Android Studio is incompatible with the Gradle Plugin used. Try disabling Instant Run.
转自:http://blog.csdn.net/qq_15807167/article/details/51984920 参考:http://stackoverflow.com/questions/3 ...
- This version of android studio is incompatible with the gradle version used.Try disabling the instant run解决办法
今天打开android studio又碰到一个奇怪的问题:This version of android studio is incompatible with the gradle version ...
- 告别编译运行 ---- Android Studio 2.0 Preview发布Instant Run功能
以往的Android开发有一个头疼的且拖慢速度的问题,就是你每改一行代码要想看到结果必须要编译运行到手机或者模拟器上,而且需要从头(可能是登录界面)一直点击到你修改的界面为止.开发一个完整的Andro ...
- [Android Pro] 告别编译运行 ---- Android Studio 2.0 Preview发布Instant Run功能
reference to : http://www.cnblogs.com/soaringEveryday/p/4991563.html 以往的Android开发有一个头疼的且拖慢速度的问题,就是你每 ...
- [原创]Android Studio的Instant Run(即时安装)原理分析和源码浅析
Android Studio升级到2.0之后,新增了Instant Run功能,该功能可以热替换apk中的部分代码,大幅提高测试安装的效率. 但是,由于我的项目中自定义了一些ClassLoader,当 ...
- AS 2.0新功能 Instant Run
Instant Run上手 作为一个Android开发者,很多的时候我们需要花大量的时间在bulid,运行到真机(虚拟机)上,对于ios上的Playground羡慕不已,这种情况将在Android S ...
- Android新特性Instant Run详解
关于 Instant Run Android Studio 2.0 中引入的 Instant Run 是 Run 和 Debug 命令的行为,可以大幅缩短应用更新的时间.尽管首次构建可能需要花费较长的 ...
- android studio2.0出现的gradle问题,instant Run即时运行不了.
android studio 2.0出现的gradle问题: instant Run即时运行不了.经历了几乎9个preView版本的AS2.0,终于迎来了正式版,然而晴天我的霹雳,好不容易装好的2.0 ...
- Android Studio 2.3 instant run与miui冲突问题的解决
Android Studio最近发布的2.3版本,由于这个版本改进后的Instant Run功能和很多国内ROM存在兼容问题,所以导致不得不做一些妥协策略,具体在小米Rom上,就是把小米rom的调试定 ...
随机推荐
- JavaWeb学习记录(二十五)——权限管理总结
一.面向对象思想简化数据库操作 public List<Role> getObjectsByIds(List<AdminRole> adminRoles) { L ...
- php脚本时 linux命令获取服务器IP
exec("netstat -anp | grep smtp",$sendList); //php脚本获取服务器邮件进程数 exec("netstat -anp |g ...
- PHP设置图片文件上传大小的具体实现方法
PHP默认的上传限定是最大2M,想上传超过此设定的文件,需要调整PHP.apache等的一些参数 我们简要介绍一下PHP文件上传涉及到的一些参数: •file_uploads :是否允许通过HTTP上 ...
- 最短路--floyd算法模板
floyd算法是求所有点之间的最短路的,复杂度O(n3)代码简单是最大特色 #include<stdio.h> #include<string.h> ; const int I ...
- CSS3教程:pointer-events属性值详解 阻止穿透点击
转:http://www.poluoluo.com/jzxy/201109/142876.html 在某个项目中,很多元素需要定位在一个地图层上面,这里就要用到很多绝对定位或者相对定位的元素,但是这样 ...
- Nanopore sensors for nucleic acid analysis 论文阅读笔记
Nanopore sensors for nucleic acid analysis Bala Murali Venkatesan and Rashid Bashir 用于核酸分析的纳米孔传感器 纳米 ...
- JSBinding / Run Samples
This document shows you how to run JSBinding 2048 sample in Editor. First of course, create an empty ...
- mysql启动与关闭(手动与自动)
手动管理mysql的启动与关闭 [root@mysql ~]# service mysql start --手动启动mysqlStarting MySQL. SUCCESS![root@mysql ~ ...
- Bootstrap 3兼容IE8浏览器(转)
Bootstrap是一个响应式的布局,你可以在宽屏电脑.普通电脑,平板电脑,手机上都得到非常优秀的布局体验.这种响应式的布局正是通过CSS3的媒体查询(Media Query)功能实现的,根据不同的分 ...
- 15条变量&方法命名的最佳实践【转】
原文地址:15 Best Practices of Variable & Method Naming 不同的代码段采用不同的命名长度.通常来说,循环计数器(loop counters)采用1位 ...