score:56
Currently you can get the correct behavior by disabling "Build Automatically", cleaning the project and then export via "Android Tools -> Export Signed Application Package". When you run the application BuildConfig.DEBUG
should be false.
score:0
I've seen some strange behavior that has to do with when the values in BuildConfig are set to their final values. This may have something to do with your issue.
The simple explanation is that default values are set initially before Proguard is run, then after Proguard runs, the BuildConfig file is regenerated with the proper values. However, Proguard has already optimized your code by this point and you have issues.
Here is a bug I created against Gradle. https://code.google.com/p/android/issues/detail?id=182449
score:0
will you check your app level build.gradle
enable debuggable true
for release
buildTypes {
release {
debuggable true
}
}
instead you keep false or comment that line
buildTypes {
release {
//debuggable true
}
}
now you will get BuildConfig.DEBUG false for release build
score:1
Does not work properly as far as I understood (Android issue 22241)
I had some trouble on a project (working with Eclipse), that constant was not set to true when exporting a signed APK of my project :(
Would love to hear it works though
score:1
a good way is creating your own class :
public class Log {
public static void d(String message) {
if (BuildConfig.DEBUG)
android.util.Log.d(
"[" + (new Exception().getStackTrace()[1].getClassName()) + "]",
"{" + (new Exception().getStackTrace()[1].getMethodName()) + "} "
+ message
);
}
}
score:3
I would want to propose a simple workaround if you use proguard during APK export.
Proguard provides a way to remove calls to specific functions in release mode. Any calls for debugging logs can be removed with following setting in proguard-project.txt
.
# Remove debug logs
-assumenosideeffects class android.util.Log {
public static *** d(...);
public static *** v(...);
}
And optimization setting in project.properties
.
proguard.config=${sdk.dir}/tools/proguard/proguard-android-optimize.txt:proguard-project.txt
With this, you don't need to concern any unnecessary String computation passing to debug log to which @Jeremyfa pointed. The computations are just removed in release build.
So the workaround for BuildConfig.DEBUG uses the same feature of proguard like following.
public class DebugConfig {
private static boolean debug = false;
static {
setDebug(); // This line will be removed by proguard in release.
}
private static void setDebug() {
debug = true;
}
public static boolean isDebug() {
return debug;
}
}
And following setting in proguard-project.txt
.
-assumenosideeffects class com.neofect.rapael.client.DebugConfig {
private static *** setDebug();
}
I would prefer using this to disabling the Build Automatically
option, because this doesn't depend on the builder's individual IDE setting but is maintained as committed file which are shared among developers.
score:5
From Preparing for Release:
Turn off logging and debugging
Make sure you deactivate logging and disable the debugging option before you build your application for release. You can deactivate logging by removing calls to Log methods in your source files. You can disable debugging by removing the android:debuggable attribute from the tag in your manifest file, or by setting the android:debuggable attribute to false in your manifest file. Also, remove any log files or static test files that were created in your project.
Also, you should remove all Debug tracing calls that you added to your code, such as startMethodTracing() and stopMethodTracing() method calls.
More information is following the link.
score:5
The solution for me:
- Project -> Build Automatically
- Project -> Clean
- Project -> Build
- Project Export Android application
It's work in r20
score:11
It does work, but note that the code file never changes, even when exporting the signed file. The export process changes the value of this variable to false, which might give you the false impression that it is not working. I tested this with logging statements like
if (com.mypackage.BuildConfig.DEBUG)
Log.d(TAG, location.getProvider() + " location changed");
When testing, my Log statements no longer produce any output.
score:16
Check for imports
, sometimes BuildConfig is imported from any class of library unintentionally. For example:
import io.fabric.sdk.android.BuildConfig;
In this case BuildConfig.DEBUG will always return false;
import com.yourpackagename.BuildConfig;
In this case BuildConfig.DEBUG will return your real build variant.
p.s I just copy this one from my answer here:BuildConfig.DEBUG always false when building library projects with gradle
score:33
It doesn't work properly:
Issue 27940: BuildConfig.DEBUG is "true" for exported application package
It's disappointing that they sometimes release buggy features.
score:44
With Eclipse, I always disable "Build Automatically" option before Exporting the app in release. Then I clean the project and export. Otherwise it starts compiling in debug mode, and then the value of BuildConfig.DEBUG may be wrong.
With Android Studio, I simply add my own custom variable in the build.gradle:
buildTypes {
debug {
buildConfigField "Boolean", "DEBUG_MODE", "true"
}
release {
buildConfigField "Boolean", "DEBUG_MODE", "false"
}
}
When I build the project, the BuildConfig.java is generated as follows:
public final class BuildConfig {
// Fields from build type: debug
public static final Boolean DEBUG_MODE = true;
}
Then in my code I can use:
if (BuildConfig.DEBUG_MODE) {
// do something
}
I recommand to clean after switching debug/release build.
Source: stackoverflow.com
Related Query
- When does ADT set BuildConfig.DEBUG to false?
- Set Eclipse to automatically switch to Java perspective when terminating debug
- What does it mean when Android ADT is unsigned (Eclipse)
- Errors when I return false inside html tags. Eclipse does not like returns outside functions or methods
- Eclipse does not set ups for Android development. (No tools(sdk manager,avd manager) , no adt installed.)
- Android Eclipse ADT Release building project does not remove debug fields
- ADT does not product source files when I create a new android project
- Why does Android Lint warn about String.format using default locale when explicitly using Locale.US?
- Eclipse does not start when I run the exe?
- When I load ADT why do I receive the error "The Android SDK requires Android Developer Toolkit version XX.X.X or above?"
- Why does Ubuntu 14.04 stick with (old) Eclipse 3.8 when 4.3 is out?
- Is there a maximum number you can set Xmx to when trying to increase jvm memory?
- How to debug Java code when using ANT script in Eclipse
- Eclipse "Enhanced Class Decompiler" plugin does not decompile when debugging
- Why does Eclipse 'filter results from view' when searching?
- Why does heap space run out only when running JUnit tests?
- 'required items could not be found' error when installing ADT plugin
- Unable to Debug Library Projects with ADT v14 - Source Not Found
- Eclipse runs debug mode even when I click "run"
- Why Eclipse doesn't show local variables values when I debug class file from JDK?
- How to set 'File Search' as the default dialog when pressing CTRL + H in Eclipse or STS?
- does netbeans have something like Eclipse Debug display view
- Where does Maven store the source and javadocs when downloaded via the Eclipse plugin
- Why when starting GWT in debug mode, my break points don't break
- How to avoid Eclipse importing a class when putting the class name in the comments, so that checkstyle does not complain later?
- Disable the second, empty console labeled [Debug Console] when starting a debug target
- Why does the android apk size differs when built from windows and mac
- How do I configure Eclipse to launch a browser when Run or Debug is selected using Pydev plugin
- Stop Eclipse From Stealing Focus when debug starts
- Why does eclipse automatically add a java super() method in a constructor when I use the editors code generator?
More Query from same tag
- Creating game gravity in Android (continued)?
- Implement Growl in Java Application
- AVD emulator launches but does not load new application
- Eclipse Indigo SR2 ships with m2e, do i need to install something more?
- Connect Oracle MAF app to server database
- Maven package structure changed after build Eclipse
- Eclipse Oxygen: How to automatically upload php files on remote server
- Using Intent, to enable GPS doens't always work correctly. How do I fix
- FAILED CONFIGURATION: @BeforeMethod setUp : java.lang.NullPointerException
- Is it possible to run an Android JUnit test with errors in the project?
- Eclipse Output Folder Not Working
- Eclipse does not recognize an android API level 9 call even though I'm using API level 10
- eclipse, refresh files edited by external editor
- How do you get Eclipse to auto-generate a main method for a new Java class?
- JavaFXPorts and eclipse
- "Java for Windows missing" dialogue while installing Eclipse
- NullPointerException when editing Android Layout in Eclipse
- Is there a quick way to add gettext() calls to strings in PyDev?
- How get ctrl + space to autocomplete in eclipse
- Eclipse CDT / GDB - open core dump?
- how can I build an android project without eclipse?
- Eclipse : How to copy contents of project explorer to clipboard using eclipse copy
- Tomcat in eclipse generated a war file with .war? extension
- Remote debugging error with eclipse CDT
- Apache Tika and Apache Solr integration through Java API
- Remove multiple lines in a set of classes
- Can't find Eclipse RCP bundle
- How to generate serialVersionUID for Serializable?
- error after imported google play service
- Unable to download ADT Plugin for Eclipse Indigo 3.7.2