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的调试定 ...
随机推荐
- c 深度剖析 4
1 预处理 1#define 1.不能用 #define 定义注释,因为注释先于预处理被处理. 2 .宏定义表达式 1,注意展开后结合顺序,尽量多加括号 2,常量定义时注意是否溢出 1 #define ...
- leetcode 155. Min Stack --------- java
Design a stack that supports push, pop, top, and retrieving the minimum element in constant time. pu ...
- 1-4-1 Windows应用程序组成及编程步骤
主要内容:介绍Windows应用程序的组成以及编程步骤 1.应用程序的组成 <1>一个完整的应用程序通常由五种类型的文件组成 1.源程序文件 2.头文件 3.模块定义文件 4.资源描述文件 ...
- php文件删除
<?php $dirname="shangchuan/uploads"; deldir($dirname); function deldir($dirname){ if(fi ...
- POJ-3107 Godfather
题目大意:给一棵无根树,找出所有满足下面的条件的点:删除它后,最大子树中的个数最少. 题目分析:两次深搜,第一次找出子树中节点的个数,第二次维护最大子树. ps:边用vector保存时会超时... 代 ...
- glsl计算sprite的亮度饱和度对比度
//glsl计算sprite的亮度饱和度对比度 #ifdef GL_ES precision mediump float; #endif uniform sampler2D u_texture; va ...
- 论文笔记之: Bilinear CNN Models for Fine-grained Visual Recognition
Bilinear CNN Models for Fine-grained Visual Recognition CVPR 2015 本文提出了一种双线性模型( bilinear models),一种识 ...
- Tutorial: Triplet Loss Layer Design for CNN
Tutorial: Triplet Loss Layer Design for CNN Xiao Wang 2016.05.02 Triplet Loss Layer could be a tri ...
- win7下安装配置tomcat,java运行环境
转 http://www.cnblogs.com/pannysp/archive/2012/03/07/2383364.html 1.下载JDK,安装 官网下载地址:http://java.sun.c ...
- Unix 入门
说明:转自以为大神的笔记. 首先,我们一起看看UNIX的目录,因为清楚了目录,才能对UNIX的框架有个大概的印象!当然这里讲的是系统正常运转所必须的,并且一定不能删除或者修改. / 是系统的根目录: ...