<span id="Label3"></p>ps:http://www.cnblogs.com/kangyi/p/4448398.html Application Scenarios<p><p>normally, when our apps are released, log is not displayed in release mode, and log is displayed in debug mode, but in special cases we need log when we test the release Package. It is not possible to use Buildconfig.debug to achieve the requirements, because in release mode is automatically set to False,debug mode is true, this time we need to customize the controllable log Switch.</p></p>Buildconfig.java location for Android Studio<p><p>In the catalog generated in Studio: in the product catalog under the <strong>/app/build/generated/source/buildconfig/</strong> file, The Buildconfig.java file is automatically generated by locating the desired package Name. We can look at the contents of the file under release Mode.</p></p><pre class="brush:java;gutter:true;"><pre class="brush:java;gutter:true;">/* * automatically generated File. Do not MODIFY */package com.leo.kang.cetfour; Public final class Buildconfig {public static final Boolean DEBUG = false; public static final String application_id = "com.leo.demo"; public static final String Build_type = "release"; public static final String FLAVOR = "baidu"; public static final int version_code = n; public static final String version_name = "3.6.1"; public static Final Boolean leo_log = false;}</pre></pre><p><p> </p></p><p><p><span style="font-size: 1.5em; line-height: 1.5;">How to customize the Buildconfig field</span></p></p><p><p><em id="__mceDel" style="font-size: 14px; line-height: 1.5; background-color: #ffffff;">Add the following code to our Build.gradle:</em></p></p><pre class="brush:java;gutter:true;"><pre class="brush:java;gutter:true;">Buildtypes { release { ///do not display LOG, in Java code is called: buildconfig.log_debug Buildconfigfield "boolean", "leo_ DEBUG "," false " minifyenabled true zipalignenabled true shrinkresources true proguardfiles Getdefaultproguardfile (' proguard-android.txt '), ' Proguard-rules.pro ' signingconfig signingconfigs.release } Debug { //display log buildconfigfield "boolean", "leo_debug", "true" versionnamesuffix "-debug" Minifyenabled false zipalignenabled false shrinkresources false signingconfig Signingconfigs.debug } }</pre></pre><p><p> </p></p><p><p><span style="line-height: 1.5;">The syntax is:</span></p></p><pre><pre><code>buildConfigField "boolean", "LEO_DEBUG", "true"</code></pre></pre><p><p>The syntax above defines a Boolean leo_debug field with a value of true, after which we can use the Buildconfig.leo_debug field in our program to determine the API environment in which we are located. For example:</p></p><pre class="brush:java;gutter:true;"><pre class="brush:java;gutter:true;"> @Override protected void onCreate (Bundle Savedinstancestate) { super.oncreate (savedinstancestate); Setcontentview (r.layout.activity_main); Commonutils.getversionname (this); Initviews (); If (buildconfig.leo_debug) { log.i ("LEO", "mainactivity.oncreate ()"); } }</pre></pre><p><p> </p></p><p><p>Android Studio--Gradle Build settings automatically</p></p></span>
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