Search code examples
androideclipseassert

How to enable assertions in Eclipse v3.7.2


I can't seem to get assertions working in my eclipse android project. I have followed the directions at this site

But I still can't get them to work. My code looks like:

assert(false) : "PROGRAM ERROR - invalid dialog call";

any ideas?


Solution

  • Dalvik VM ignores Java assertions by default. To enable that, one must change debug.assert property, e.g by invoking command in command line:

    adb shell setprop debug.assert 1
    

    Please note that you have to restart VM after that (force stop application: Settings->Apps->click on the app->Force stop).

    Please also note that the setting is not persistent (assertions will be disabled again after phone reboot). However on rooted phones there's a way to make it persistent by putting /data/local.prop file containing line

    debug.assert=1