Getting started with JRebel for Android

介紹

無意中發現zeroturnaround公司發佈了一神器JRebel for Android,僅支持Android Studio,雖然這個JRebel for Android 目前來看功能還是比較有限的,主要作用就是類和UI的改動能夠自動reload無需從新安裝運行apk,已經算是大大的提高了工作效率,以及Android studio 2.0之後google發佈的 Instant Run兩者的區別
One thing you can try is JRebel for Android. It takes a different approach by not introducing a new apk after each change. Instead apk gets installed once and delta packages are shipped over to the device or emulator and are applied during runtime. This logic is nothing new and has been present in the Java EE/SE with JRebel for more than 8 years.
Let’s take the Google IO 2015 app and see how the JRebel for Android setup works as well as how it can save you valuable time.

安裝

打開Android Studio -> Preferences -> Plugins -> Browse repositories… -> Search “JRebel for Android” -> Install plugin 安裝好後重啓導入證書即可 安裝
這裏寫圖片描述

使用方法

用法很簡單,就是原本的Run和Debug按鈕替換成JRebel的Run和Debug按鈕,看動畫就可以理解 使用方法 有個地方需要注意的是就是每次修改完後要手動點Make按鈕(或者快捷鍵是Command+F9)模擬器那邊的程序纔會重新渲染
這裏寫圖片描述

Why should I try JRebel for Android?

  • There are loads of reasons! Here are some of the most persuasive reasons as to why you should give it a go:
    • Reduce the time it takes to see your changes on the device
    • Polishing UI and getting that pixel perfect result no longer takes hours because of long build times
    • No need to change anything in your project to make JRebel for Android work
    • Use debugger and update code and resources at the same time! That’s right JRebel for Android comes with full debugger support!

比對JRebel 和Android Instant Run兩者的區別:這裏寫鏈接內容how to update code and resources in Android application without wasting time on restarts.

兩者的共同點都是Swapping code

Both Instant Run and JRebel for Android are all about “swapping” code or resources, live, inside a runtime environment. This means that you install the APK just once. When the APK is present on the target device, you can start sending over small, incremental patches that will be applied.
This is a huge timesaver in a multitude of ways:
The build process no longer needs to package and build the code parts that have not changed — just rebuild the deltas.
Less data needs to be pushed to the device over ADB.
Once on the device, the dex2oat has a lot less work to do, compared to a full APK install.

Hot, warm, and cold swap

Here is the short version, code changes are handled this way:
  • Hot Swap — New code is executed in the next call.
  • Warm Swap — New code is executed after the activity restarts.
  • Cold Swap — New code is executed after the application restarts.
Changes to resources have fewer options:
  • Warm Swap — New resources are used after the activity restarts.
  • Cold Swap — New resources are used after the application restarts.

Comparing JRebel for Android and Instant Run

當你update code 運行到設備時:Instant Run的執行過程是perform a hot or warm swap這關鍵決定在於Android studio

 This depends on the Android Studio > Preferences > Build, Execution, Deployment > Build Tools > Instant Run “Restart activity on code changes” setting

JRebel 沒有“Restart activity on code changes” setting,改變code 和resource都是執行warm swap。

JRebel for Android does not have a separate “Restart activity on code changes” setting. Code and resource changes will always be handled by a warm swap. This is an acknowledged user experience decision that we made a long time ago. The main reason for why JRebel for Android does not “hot swap” is to make it easier for the user to understand what is happening — and what to expect after code or resources have been updated.

詳細查看原文:https://medium.com/@shelajev/getting-started-with-jrebel-for-android-426633cde736#.qes7gy8za

發佈了51 篇原創文章 · 獲贊 11 · 訪問量 15萬+
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章