Android Studio 2.1中的instant run功能 介紹
Studio 2.0 之後就有了instant run 功能
說說 instant run 功能:字面意思就能明白 即時執行
這個功能在2.1是預設開啟的 而它的相關設定介面呢如下:
就是右邊的是個設定了
如何判斷是否可以呢 通過 看到了 執行案例左邊的⚡️ 了嗎? 那就是可以了
先給 大家貼上 官方介紹文件
這個功能就是當你修改了程式碼或者佈局的時候 點選執行 它不會將整改專案都進行重新打包,而是能直接在你的測試機上體現。
比如我們以前調整了佈局後 需要看到效果就得重新打包運行了。
而現在呢就不用了,當然了使用方法是一樣的 。但是呢速度要快很多。幾秒內就能完成。
而如果是整體打包的話那速度就慢了。以前1.4版本的時候一分鐘就能打包完了。現在得3分鐘。
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. 如果是左邊的這種情況,那就是熱插拔模式了,修改後能馬上看到效果(熱插拔大家都瞭解,就是現在的U盤的那種模式,插上就能用) |
|
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: (程式碼結構進行了變化)
|
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了。那速度 可真是相當慢了。 |
|
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 這邊就告訴你說,這種情況下 instant run 就不起作用了。得重新打包生成整個專案了 |