Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Android: How should I respond to "Hot Code Replace Failed" dialog in Eclipse?

When my Android application is already running and I change the code I get the "Hot Code Replace Failed" dialog.

  1. I'm wondering what the correct response is (terminate or disconnect) if I want Eclipse to update my code on the device when I encounter it.

  2. What is the difference between terminate and disconnect?

  3. Also, I'm wondering if I click the "Do not show error when hot code replace is not supported", what will Eclipse do in the future when this scenario occurs?

"Hot Code Replace Failed" dialog

like image 829
Jeff Axelrod Avatar asked Sep 16 '11 20:09

Jeff Axelrod


2 Answers

Depending on the VM used (Dalvik in this case), some code changes can be made whilst debugging that will 'hot deploy' or 'hot replace'. This means that the code changes will immediately take effect on the emulator and you can test them without the need to re-deploy your app. This sort of hot re-deployment is more commonly used when working with enterprise applications that may take 10 minutes to build and deploy and so wastes a lot of time during development.

The HotSpot VM (the VM usually used on PCs) allows only simple code replacement and fails if you try to add/rename a field member or method. I'm not sure what sort of support the Dalvik VM provides but if you make a change it does not support you'll get that dialog box.

Now, as for the buttons:

  • Continue: Accept that the changes you have made will not take effect immediately in the emulator and continue debugging
  • Terminate: Kill the app
  • Disconnect: Do not kill the app but end the debugging session (i.e. disconnect the debugger)

If you check the box, it will always Continue.

like image 118
Gyan aka Gary Buyn Avatar answered Nov 08 '22 10:11

Gyan aka Gary Buyn


I'm wondering what the correct response is (terminate or disconnect) if I want Eclipse to update my code on the device when I encounter it.

There's no direct way to have Eclipse update your running code on the emulator when you encounter this dialog as the Dalvik VM does not suppot hot swap, i.e. the update of running code. You'll have to redeploy the app to your emulator manually.

What is the difference between terminate and disconnect?

  • Terminate will terminate the app being debugged on the emulator/device.

  • Disconnect will just disconnect the debugger, and leave the app running on the emulator/device.

Also, I'm wondering if I click the "Do not show error when hot code replace is not supported", what will Eclipse do in the future when this scenario occurs?

It "won't show error when hot code replace is not supported" obviously ;) -- i.e. it won't warn you and any changes you do will not be hot-swapped into the running app (because the Dalvik VM doesn't support hot-swapping like Oracle's JVM for example).

like image 22
Philipp Reichart Avatar answered Nov 08 '22 10:11

Philipp Reichart