I have a Pixel-C that I am developing for. My minimum API level is 21, which is also the level at which ART replaced Dalvik. I have tried both of:
adb shell setprop dalvik.vm.enableassertions all
adb shell setprop debug.assert 1
And they seem to execute successfully. I have placed
assert false : "assertions are active!";
in my onStart, and I am not seeing any stack traces in logcat. I would expect the app to exit immediately after I install and run it. Please tell me how to get this assertion to execute.
Please do not mention JUnit or other ways to do assertions, nor any solution that requires explicitly throwing an Error. Production code should never throw Errors, nor attempt to catch and handle them. That's why assertions were added to the language, to have a way to cause the app to crash when invariants are violated in test environments without incurring any overhead or risk whatsoever in production.
This 6-year old question is basically the same, but for Dalvik (IE out of date) and the solutions are either not working or not good: Can I use assert on Android devices?