Android Studio 2.0及其以后版本中的instant run功能 介绍

转 https://blog.csdn.net/zy987654zy/article/details/51496199

Studio 2.0 之后就有了instant run 功能

说说 instant run  功能:字面意思就能明白 即时运行

这个功能在2.1是默认开启的 而它的相关设置界面呢如下:

就是右边的是个设置了

如何判断是否可以呢 通过 看到了 运行案例左边的⚡️ 了吗? 那就是可以了

先给 大家贴上 官方介绍文档

https://sites.google.com/a/android.com/tools/tech-docs/instant-run#TOC-What-s-Supported-by-Instant-Run-

这个功能就是当你修改了代码或者布局的时候 点击运行 它不会将整改项目都进行重新打包,而是能直接在你的测试机上体现。

比如我们以前调整了布局后 需要看到效果就得重新打包运行了。

而现在呢就不用了,当然了使用方法是一样的 。但是呢速度要快很多。几秒内就能完成。

而如果是整体打包的话那速度就慢了。以前1.4版本的时候一分钟就能打包完了。现在得3分钟。

Code Change Instant Run Behavior
  • Change implementation code of an existing instance method or static method(改变现有的实例方法或静态方法的实现代码。前提是这个实现方法和static方法是存在的,如果不存在 那就是新增了,新增请参考第三条)
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.
如果是左边的这种情况,那就是热插拔模式了,修改后能马上看到效果(热插拔大家都了解,就是现在的U盘的那种模式,插上就能用)
  • Change or remove an existing resource(你修改了布局中的资源信息,其实主要是layout文件中的修改,比如这个布局不要了, 我进行删除啊,这个view 文字不正确 我就想修改等。如果是添加的话 那就是第三行的情况了)
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.
(如果是这种情况的话,那速度也挺快的 但是没有上面的快,如果你要修改的这个页面是正在显示的页面 它就会闪一下,然后你的修改就能看到你。 这种情况 你的app 不会重新启动的。成功后 你的设备中就会弹出一个Toash)
Structural code changes, such as:
(代码结构进行了变化)

  • Add, remove, or change: (比如下面的这些情况下的 添加,删除和修改)

    • an annotation(注释)
    • an instance field(实例字段)
    • a static field(静态字段)
    • a static method signature(就是static方法被修改了,比如改名啦,改变传参啦。)
    • an instance method signature(就是实例的签名被修改的情况,比如类包名修改了,类名被修改了,实例名称被修改了)
  • Change which parent class the current class inherits from(比如修改了被继承的父类)
  • Change the list of implemented interfaces(修改列表实现的接口啦)
  • Change a class static initializer(改变类的static 初始化方法啦)
  • Reorder layout elements that utilize dynamic resource IDs(利用动态生成的id 来调整布局元素 等)

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.

就是说 如果发生了左边说的那种情况,而刚好你的api登记是在21或以上,那就会将修改结构代码更改推到目标设备运行。这个时候你的app会重新启动。但是耗时不会很长。

但是如果你的版本是20版本或以下,那就没什么好说的你。 重新生成构建整个apk了。那速度 可真是相当慢了。

  • Change the app manifest (如果你修改了androidmanifest文件)
  • Change resources reference by the app manifest(如果你修改了manifes文件引用的资源文件)
  • Change an Android widget UI element (requires a Clean and Rerun)(如果你改变了一个UI控件的元素 比如说自定义控件 你给它新增加了个属性 )

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 versionCode orversionName, you will not be able to benefit from the full performance of Instant Run. We recommend that you disable automatic updates to any part in the app manifest in your debug build variants.

这边就告诉你说,这种情况下 instant run 就不起作用了。得重新打包生成整个项目了

Android Studio 2.1及其以上版本中的instant run功能 介绍的更多相关文章

  1. 1.运行Android Studio,一直提示:Error running app: Instant Run requires 'Tools | Android | Enable ADB integration' to be enabled.

    1.解决问题办法:菜单栏,Tools -> Adnroid -> enable ADB integration勾上 2.暂时性的解决方案:在Android Studio中的:Prefere ...

  2. Android Studio更改项目SDK的版本

    Elipse 中的安卓项目,在Android Studio中可以通过File -->new -- > Import Project的方法建立起来.但是有时候需要用到更改项目的API Lev ...

  3. Android Studio稍微较新的版本下载

    ALL ANDROID STUDIO PACKAGES-V1.4.1.2422023 Select a specific Android Studio package for your platfor ...

  4. 告别编译运行 ---- Android Studio 2.0 Preview发布Instant Run功能

    以往的Android开发有一个头疼的且拖慢速度的问题,就是你每改一行代码要想看到结果必须要编译运行到手机或者模拟器上,而且需要从头(可能是登录界面)一直点击到你修改的界面为止.开发一个完整的Andro ...

  5. [Android Pro] 告别编译运行 ---- Android Studio 2.0 Preview发布Instant Run功能

    reference to : http://www.cnblogs.com/soaringEveryday/p/4991563.html 以往的Android开发有一个头疼的且拖慢速度的问题,就是你每 ...

  6. Android Studio 2.2.2导入Eclipse中创建的项目

    最近随视频教程学习Android,原本都是用Adt写Android程序,中途教程换成了Android Studio,于是我自己下了android studio 2.2.2安装好,并下载好sdk,也跟着 ...

  7. Android 项目利用 Android Studio 和 Gradle 打包多版本APK

    在项目开发过程中,经常会有需要打包不同版本的 APK 的需求. 比如 debug版,release版,dev版等等. 有时候不同的版本中使用到的不同的服务端api域名也不相同. 比如 debug_ap ...

  8. 利用 Android Studio 和 Gradle 打包多版本APK

    在项目开发过程中,经常会有需要打包不同版本的 APK 的需求. 比如 debug版,release版,dev版等等. 有时候不同的版本中使用到的不同的服务端api域名也不相同. 比如 debug_ap ...

  9. Android Studio 3.0 及以上版本使用技巧总结

    1.更新Android Studio后下载Gradle文件的技巧 更新到3.0版本后,可能会出现创建新项目一直停留在如下图的界面: 选择等待?不知道要等到什么时候,这时候怎么办呢?显然,不能一直等待下 ...

随机推荐

  1. 随机逻辑回归random logistic regression-特征筛选

    python信用评分卡(附代码,博主录制) https://study.163.com/course/introduction.htm?courseId=1005214003&utm_camp ...

  2. Exp6 信息收集与漏洞扫描

    一.实践过程 1.信息收集 1.1 通过DNS和IP查询目标网站的信息 (1)whois命令用来进行域名注册信息查询,可查询到3R注册信息,包括注册人的姓名.组织和城市等信息. whois baidu ...

  3. netcore项目在Windows部署:使用NSSM部署Windows服务

    NSSM部署Windows服务 1 准备工作 在Windows平台部署Asp.net core应用程序一般采用IIS,但是如果我们的net core应用执行的是定时任务,需要开机自启,稳定运行的话,使 ...

  4. python之路(9)反射、包装类、动态模块导入

    目录 反射 利用继承二次包装标准类 利用授权二次包装标准类 动态模块导入 反射 python提供自省的四个方法: hasattr(object,name)  判断object中有没有有个name字符串 ...

  5. linux路由表

    Linux 内核的路由表通过 route 命令查看 Linux 内核的路由表: [root@VM_139_74_centos ~]# routeKernel IP routing tableDesti ...

  6. 080、Weave Scope 容器地图(2019-04-28 周日)

    参考https://www.cnblogs.com/CloudMan6/p/7655294.html   Weave Scope 的最大特点是会自动生成一张 Docker 容器地图,让我们能够直接的理 ...

  7. springBoot和Mybatis输出sql日志

    利用slf4j来输出日志. 首先需要版本兼容的slf4j-log4j12.log4j.slf4j-api.slf4j-nop.slf4j-simple这5个包. 可以去maven知识库中找到这5个包的 ...

  8. 你们都在用IntelliJ IDEA吗?或许你们需要看一下这篇博文

    写在前面 以前一直用的elipce,如今入坑IntelliJ IDEA,没想到啊.深深的爱上了它,强大到无所不能: "工欲善其事必先利其器",IntelliJ IDEA作为一个非常 ...

  9. C#创建 WebApi 项目

    做web api 可以参考一下网友 C#进阶系列——WebApi 接口参数不再困惑:传参详解 - 懒得安分 - 博客园https://www.cnblogs.com/landeanfen/p/5337 ...

  10. 分布式系列十: Redis安装和命令

    redis是一个开源的, 内存数据结构存储, 一般用来作为数据库,缓存和消息代理. Redis的优势 多种数据结构 字符类型String 散列类型Hash 列表类型List 集合类型Set 有序集合类 ...