How to use assert in Android Studio

Ilya Gazman

I been looking at this question, and I thought it would be a good idea of using assert only in debug build.

Is there any thing special that I need to configure in Android Studio in order to allow asserts? I also want to guarantee that they will not be presented in release build.

Florian Barth

The adb shell setprop debug.assert 1 from your referred question is to be executed on the device you are testing on, so you could whip up a script or even create a custom gradle task for that (gradle docu).

In general I'd recommend to also have your checks in production and handle them in a proper way. A simple solution would be to throw a RuntimeException. With checked Exception you could even handle the recovery from this errorneous states / misuses of your api.

Furthermore, it would make sense to add proper tests that ensure, that your code/APIs only emit "valid" values that can be handled by the rest of your code.

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

How to use Android studio

From Dev

How to use nodejs Assert

From Dev

How to use assert in OCaml?

From Dev

how to use assert and == in python?

From Dev

How to use this project in android studio?

From Java

How to use the ProGuard in Android Studio?

From Dev

How to use BoofCV in Android Studio?

From Dev

How to use BoofCV in Android Studio?

From Dev

How to use pocketsphinx in Android Studio

From Dev

How to use ObservableList in Android Studio?

From Dev

How to use mimeType Assert with VichUploader?

From Dev

Use of static_assert forbidden in Android project

From Dev

Android Studio 0.8.1 - how to use Facebook SDK?

From Java

How to use Scratch Files in Android Studio?

From Dev

How to use Git correctly in Android Studio?

From Dev

How to use a library project in android studio

From Dev

How to use a Android Studio project on two computers?

From Dev

How to use Gradle to generate JavaDoc in Android Studio?

From Dev

How to force Android Studio to use relative paths?

From Dev

how to use a proxy connection with android studio

From Dev

How to use the latest gradle version in Android Studio

From Dev

How to use a static import in Android Studio

From Dev

How to use git branch with Android Studio

From Dev

How to use latest FFMPEG in Android Studio project?

From Dev

how to use mikrotik-api in android studio

From Dev

How to compile and use FFMPEG library in Android Studio?

From Dev

How to use multiple repositories in Android Studio with GitHub

From Dev

How to use imported library project in Android Studio?

From Dev

How to use lombok plugin in Android Studio?