Use of buildconfig. debug in Android

Source: Internet
Author: User

ADT (R17) adds a new function that allows developers to only allow some code in debug mode. The build system generates a class named buildconfig, which contains a DEBUG constant, which is automatically set based on your build type. You can use the (buildconfig. Debug) constant to compile the code that runs only in debug mode.

If some code does not want to be executed after release, you can use this function.

For example, you do not want to see debugging logs after the software is released by other developers. In the past, you set a global variable to mark the software as the debug mode or the release mode.

    public static boolean DEBUG = true;

Then write in the code

        if(DEBUG==true){            Log.d(TAG,"output something");        }

In this way, you need to modify the value of the debug variable before packaging and publishing. Sometimes you don't remember to re-compile and release the variable, which is very time-consuming.

With buildconfig. debug, you can directly write

      if (BuildConfig.DEBUG) {                Log.d(TAG, "output something");            }

Before release,

The value of buildconfig. debug is automatically true,

In the package published by Android tools> export signed application package,

The value of buildconfig. debug is automatically set to false.
Developers do not need to modify anything else.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.