當一回Android Studio 2.0的小白鼠
上個星期就放出了Android studio出2.0的消息,看了一下what's new 簡直抓到了那個蛋疼的編譯速度痛點.在網上稍微搜索了一下后發現基本都是介紹視頻.一番掙扎后(因為被這IDE坑過幾次),于是決定自己當一回小白鼠實驗一下.
instant run
準備
首先,是把升級跳到最不穩定的頻道,check 一下然后 update and restart,這不必說.唯一值得講的一點在于,下完安裝的時候會耗盡磁盤的資源,很卡.然后第一次打開的時候記得導入之前的設置.
床說中的瞬間執行
instant run需要gradle 2.8+好在ide認識到這一點,點自動更新工程,等待結果完成即可.
更新之后,會發現gradle用上了2.8.然后下面的設置也不再是灰色.表明設置可用.我建議只勾選第一項
此外,應用instant run的AVD需要api14+
不足
但是目前,該功能還是有些不完善的.這里引用原文
Here are some code changes that Instant Run does not currently support:
-
Add/remove/change annotations
-
Add/remove/change an instance field
-
Add/remove/change a static field
-
Add/remove a static method signature
-
Change a static method signature
-
Add/remove an instance method
-
Change an instance method signature
-
Changing which parent class the current class inherits from
-
Change the list of implemented interfaces
-
Changing static initializer of a class
使用和體會
代碼改動之后,點擊run(此時的run左邊有個小閃電的圖標),之后即可完成迅速編譯.我這邊試了一下,大概2s以內.
11:23:46 Executing tasks: [:app:incrementalDebugSupportDex]
11:23:48 Gradle build finished in 1s 948ms
11:23:48 Instant Run: Instant Run applied code changes.
You can restart the current activity by clicking here or pressing Ctrl+Shift+R anytime.
You can also configure restarts to happen automatically. (Dismiss, Dismiss All)
還是比較快的~
至于GPU Profiler,暫時用不到,就不作說明了
這玩意大概就是用來 預覽和跟蹤渲染效果的吧,具體的指導可以看第三個鏈接.
此外,編輯器的一些細節(窗體的大小,etc)有些許的變化,這個就自己慢慢體會了.
總結
總的來說instant run只是加速了項目的構建,這就是本來應該做的事情嘛~驚喜不是很多,我期待的是更快的AVD,但是目前還看不到相關消息.
微軟最近也出了AVD,但是正當我激動之時,發現這玩意要hyper-v.也就是專業版win8.1/10才有,而當初8.1升級過來全特么變成家庭版,心涼了一截.
參考鏈接:
https://sites.google.com/a/android.com/tools/tech-docs/instant-run%20
https://sites.google.com/a/android.com/tools/tech-docs/gpu-profiler%20