How to use assert in android?

后端 未结 6 2206
日久生厌
日久生厌 2020-12-08 09:35

I want to use assert obj != null : \"object cannot be null\" on Android device. The assert doesn\'t seem to work, so I searched online and I found this local so

6条回答
  •  野趣味
    野趣味 (楼主)
    2020-12-08 10:01

    Tested on Android 4.x device, it is possible to use Java assert on Android device:

    • Edit /system/build.prop (for example by X-plore), add line at end of file: debug.assert=1
    • Reboot phone

    Now your Android device is sensible to assert checks, and will throw AssertionError when assert check fails.

    EDIT:

    Another easy approach, enabling asserts from PC until device is restarted:

    platform-tools\adb shell setprop debug.assert 1
    

    You may for example create a .bat file (on Windows) and run it when device is attached.

提交回复
热议问题