Hot swap debugging with Android
Asked Answered
S

4

25

1) Is there any special setting/configuration required to enable hot swap debugging on Android?

Example case:

  • Add breakpoint just after entering activity's onCreate method.
  • Add new line on the fly after the breakpoint (dummy "if (1==1) return;" code)
  • Step to next instruction --> Problem: my debugger doesn't break at this line, instead skipping to the next leading me to believe the new line was not hot swapped into the VM.

2) Does only the emulator support hot swap? Are there any handsets which also support it?

Samba answered 3/5, 2012 at 10:36 Comment(0)
C
4

The emulator itself doesn't support code hotswap, but with additional tools like InstaReloader desired action can be achieved. You can use this Android hotswapping tool for free

Caldeira answered 21/11, 2013 at 23:34 Comment(3)
What happened to that project?Chartography
Link seems dead - site expired.Arndt
Link is dead, please repostBungalow
A
22

Every time the Android project is built, it's dexed and put into a debug-signed apk that is sent to your phone/emulator. Hence, hotswapping isn't exactly easy to do.

Hotswap is a product of a well-designed JVM, and it makes it possible to exchange classes. On Android, you have Dalvik VM, which does not currently support hot swapping.

I'm guessing the ADT team has this high-ish on their list, though.

EDIT: Even though it has been 2,5 years since this answer, not much has changed. ZeroTurnaround, however, have stuff up their sleeves, and JRebel for Android should give us a much needed method for hot swapping. http://zeroturnaround.com/software/jrebel-for-android/

EDIT2: With the release of Android Studio 2.0 Instant Run enables you to hot swap. Hot swap will i.e. change a class while your app is running.

They also support warm swap, which is doing a lot more than hot swap in terms of messing with your app. Warm swap still leaves your app running. Resource changes will trigger a warm swap.

Watch this talk from Android Dev Summit 2015 for more info: https://www.youtube.com/watch?v=fs0eira2pRY

Amphithecium answered 31/7, 2012 at 14:48 Comment(0)
R
8

Android Studio 2.0 preview introduced a hot swap feature. You get it by upgrading to:

        classpath group: 'com.android.tools.build', name: 'gradle', version: '2.0.0-alpha1'

And then setting it from the menu:

enter image description here

Redtop answered 25/11, 2015 at 1:7 Comment(0)
C
4

The emulator itself doesn't support code hotswap, but with additional tools like InstaReloader desired action can be achieved. You can use this Android hotswapping tool for free

Caldeira answered 21/11, 2013 at 23:34 Comment(3)
What happened to that project?Chartography
Link seems dead - site expired.Arndt
Link is dead, please repostBungalow
C
2

Not truly hot swapping but there is a library on Github which emulates that. You can find it here: https://github.com/mmin18/LayoutCast

It has some issues but is active as of the time of writing of this answer.

Also, ZeroTurnaround seems to be working on the problem with JRebel for Android. You can request beta access here: http://zeroturnaround.com/software/jrebel-for-android/

Chapman answered 18/8, 2015 at 17:14 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.