一. 介紹
Android Studio的Instant Run功能已經出來一段時間了. 為了節約編譯時間, 您應該盡快使用起來. 關于其介紹, 請參考這里 https://developer.android.com/studio/run/index.html#instant-run
二. 使用
使用非常簡單, Android Studio默認就是開啟Instant Run
功能的, 只要條件滿足, 便會自動應用上. 有些什么條件需要滿足呢 ?
使用Instant Run必須滿足下列條件:
- gradle插件必須2.0.0或以上 (Android Plugin for Gradle 2.0.0+)
- minSdkVersion要設置為15或以上 (未獲得最佳性能, 可以將minSdkVersion設置為21或更高. 從sdk21開始支持multidex不需要添加multidex的support包, 因此打包是不需要進行分包, 當然更高版本的buildtools肯定也做了某些優化吧)
- 第二此運行 (更改了某些內容后, 進行增量編譯, 這時候會應用Instant Run. 運行過一次后, 運行按鈕會變成這樣 (三角形左邊有個小閃電圖標):
Instant Run可用時運行按鈕的樣子.png
下面是關于Instant Run
使用條件的一張截圖:
使用Instant Run功能必須滿足的條件.png
如果你的Instant Run
不能使用, 你可以檢查是否滿足上面的條件. 另外檢查是否開啟Instant Run
, 檢查步驟如下:
? Preferences ...
-> Instant Run
-> 開啟Instant Run
(選中復選框) , 如下:
啟用Instant Run.png
? 關于哪些情況下會使用Instant Run 運行app, 您可以參考官網的詳細說明
另外, 如果你的minSdkVersion的值小于21 且 使用了multidex功能, 則不能使用Instant Run
, 那么如何解決這個問題呢, 你可以如此這般 ==> 解開錦囊
三. 原理
https://developer.android.com/studio/run/index.html#instant-run
努力更新中 ......
另外推薦alibaba的一個快速構建和發布工具: freeline
references:
https://developer.android.com/studio/run/index.html#instant-run