Lahiru Chandima Lahiru Chandima - 3 months ago 26x
Android Question

Android: App crashes frequently with instant run

In my android app, I am debugging it with instant run enabled.

The app gives me unexpected errors very frequently, which gets resolved if I did a clean build.

For an example, there are sometimes class not found exceptions where the class is actually there. Also, sometimes there are class cast exceptions when trying to cast the

returned by
to the target type (probably android studio has misinterpreted the element IDs when hot deploying the layouts).

All these errors get resolved without no code change, just by doing a full build. Instant run has successfully made the build process two or three times slower for me.

Why am I getting these errors? Does anyone know how to get instant run to working properly?


You are not the only one. Instant Run is little stable, or we can say unreliable, currently.

Instant Run has several swap steps as this document describes. In your case, Instant Run could not recognize your changes well, so did warm swap even it required cold swap, and so on.

Instant Run is useful when editting minor GUI placement, I want to say it is the only useful scenario currently, so I recommend you to turn it off during general development. You can make it disable by unchecking Settings > Build, Execution, Deployment > Enable Instant Run to hot swap... checkbox.

If you think Instant Run is fancy and still want to use it, you will likely be faced such a problem many times. For that, just rebuild all as you experienced. That's all we can do now.