Question: BuildConfig.DEBUG is not working (= logically set to false) when I run my app in debug mode.
I use Gradle to build. I have a library project where I do this check. BuildConfig.java looks like this in the build debug folder:

```
/** Automatically generated the file. DO NOT MODIFY */
package common.myProject;

public final class BuildConfig {
    public static final boolean DEBUG = Boolean.parseBoolean("true");

}

```

and in the release folder:

```
public static final boolean DEBUG = false;

```

both in the library project and in the application project.

I tried to get around this by checking a variable which is set a class of my project. This class inherits from the library and starts on startup.

```
<application
        android:name=".MyPrj" ...

```

This leads to another problem: is that I use my DEBUG variable in a DataBaseProvider which runs before the application class, and it will not run properly due to this bug.

Answer: 
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.**
Not really the correct way to check if you are in debug flavor, but you can check if the app itself is debuggable via:

```
private static Boolean sIsDebuggable;

public static boolean isDebuggable(Context context) {
    if (sIsDebuggable == null)
        sIsDebuggable = (context.getApplicationInfo().flags & ApplicationInfo.FLAG_DEBUGGABLE) != 0;
    return sIsDebuggable;
}

```

The default behavior of apps and libraries will match it perfectly. 

If you need a better workaround, you can use this instead:

```
public static boolean isInDebugFlavour(Context context) {
    if (sDebugFlavour == null) {
        try {
            final String packageName = context.getPackageName();
            final Class<?> buildConfig = Class.forName(packageName + ".BuildConfig");
            final Field DEBUG = buildConfig.getField("DEBUG");
            DEBUG.setAccessible(true);
            sDebugFlavour = DEBUG.getBoolean(null);
        } catch (final Throwable t) {
            sDebugFlavour = false;
        }
    }
    return sDebugFlavour;
}

```