Is assert reliable on android or not?

女生的网名这么多〃 提交于 2019-12-12 16:22:38

问题


there is this question and answer:

Can I use assert on Android devices?

However, then I ran across this:

http://tools.android.com/recent/androidstudio045released

which says:

Some new lint checks, and in particular one which flags uses of the assertion keyword. This does not work reliably on devices and you should use BuildConfig.DEBUG to do conditional checks instead.

There is no "assertion" keyword, there is only an "assert" keyword, so I'm not sure what to even make of that release note.

Anyway, what I'm curious about is:

If I follow the first link and do:

adb shell setprop debug.assert 1

before installing the app on the device, and compile the app as debug with assertions turned on, then are they reliably expected to work on all devices? Or, should I believe the release notes for Android Studio 0.4.5?


回答1:


I think it's this difficulty getting assertions to work that the lint check is referring to. The workaround you linked to isn't officially supported, and it's recommended to use conditional checks as the lint check recommends.

The workaround to enable assertions will only work for rooted devices, and I don't know whether or not it will work on ART. There's more discussion at https://code.google.com/p/android/issues/detail?id=17324, the gist of which is that assertions were never really designed to be supported on Dalvik.




回答2:


Assertions are unreliable on Android. The runtime offers no reliable mechanism to enable them and the developers keep disavowing support. See issues 175697, 65183, 36786, and 17324.

To reliably use assert statements, you would have to translate the code, e.g. before compiling it.



来源:https://stackoverflow.com/questions/26510834/is-assert-reliable-on-android-or-not

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!