zoukankan      html  css  js  c++  java
  • Android Studio 2.1及其以上版本中的instant run功能 介绍

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

    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 ChangeInstant 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 就不起作用了。得重新打包生成整个项目了

  • 相关阅读:
    湖湘杯2020misc
    BUUOJ(Misc)
    BUUOJ(Web)
    网络信息安全攻防学习平台
    CTFHub web部分题解
    BugkuCTF 部分WP(搬运了很多WP)
    Web安全之机器学习入门 第2章-第5章学习笔记
    结构体
    排序的使用
    字符串和日期
  • 原文地址:https://www.cnblogs.com/it-tsz/p/10763312.html
Copyright © 2011-2022 走看看