Instant Run浅析

  • Post author:
  • Post category:其他


Instant Run


Instant run是在android studio 2.0引入的,能让我们快速构建运行app。其中包含了四种情况:hot swap、warm swap、cold swap以及无法使用instant run的情况。下面部分引用官方文档进行说明:

*

hot swap


This is the fastest type of swap and makes changes visible much more quickly. Your application keeps running and a stub method with the new implementation is used the next time the method is called.

只对已存在的方法实现进行修改时支持hot swap,这种情况无需重启app或者是activity。但如果当前app被切换了,则会退化到cold swap。

*

warm swap


This swap is still very fast, but Instant Run must restart the current activity when it pushes the changed resources to your app.

对已存在的资源文件进行修改时支持warm swap,这种情况需要重启当前activity。

*

cold swap


This swap is a bit slower because, although a new APK is not required, Instant Run must restart the whole app when it pushes structural code changes.

For target devices running API level 20 or lower, Android Studio deploys a full APK.

对成员变量、注解、方法签名进行增删改时支持cold swap,需要重启app。

*

new build


When making changes to the app’s manifest or resources referenced by the manifest, Android Studio automatically deploys a new build in order to apply these changes. 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.

对manifest等进行修改,或者usb断开,则无法使用instant run。

编译

  • 首次编译

    1. 将instant-run.jar编译成dex,打入apk。
    2. 修改manifest文件,将application替换为instant-run.jar中的BootstrapApplication。
    3. app的所有类都添加类型为IncrementalChange的








      c


      h


      a


      n


      g




      e












































































版权声明:本文为sgwhp原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接和本声明。