Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

BuildConfig.DEBUG always false when building library projects with gradle

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.

like image 478
user1324936 Avatar asked Nov 24 '13 15:11

user1324936


People also ask

What is BuildConfig DEBUG?

In recent versions of the Android Developer Tools (ADT) for Eclipse, there's a class called BuildConfig which is automatically generated by the build. This class is updated automatically by Android's build system (like the R class), and it contains a static final boolean called DEBUG, which is normally set to true.

How is BuildConfig generated?

There's a class called BuildConfig. java which is automatically generated by the build system. This class is updated automatically by Android's build system (like the R class). It already contains a static final boolean called DEBUG, which is normally set to true.

Where is BuildConfig generated?

Using an IDE like Eclipse, IntelliJ, Studio, the class BuildConfig is auto generated in the gen folder.

What is a Buildtype in gradle?

A build type determines how an app is packaged. By default, the Android plug-in for Gradle supports two different types of builds: debug and release . Both can be configured inside the buildTypes block inside of the module build file.


1 Answers

With Android Studio 1.1 and having also the gradle version at 1.1 it is possible:

Library

android {     publishNonDefault true } 

App

dependencies {     releaseCompile project(path: ':library', configuration: 'release')     debugCompile project(path: ':library', configuration: 'debug') } 

Complete documentation can be found here http://tools.android.com/tech-docs/new-build-system/user-guide#TOC-Library-Publication

EDIT:

The issue has just been marked as fixed for the Android Studio Gradle Version 3.0. There you can just use implementation project(path: ':library') and it'll select the correct configuration automatically.

like image 50
Niklas Avatar answered Oct 17 '22 09:10

Niklas