Buildconfig.Debug Always False When Building Library Projects with Gradle

BuildConfig.DEBUG always false when building library projects with gradle

This is expected behavior for this.

Library projects only publish their release variants for consumption by other projects or modules.

We're working at fixing this but this is non trivial and requires a significant amount of work.

You can track the issue at https://code.google.com/p/android/issues/detail?id=52962

BuildConfig.DEBUG always return false

In your Android Studio build variant are you on debug variant?

That is applied when you use flavors, either for debug or release.

in the debug mode, BuildConfig.BUILD is true, and in the release mode, it is false.

When does ADT set BuildConfig.DEBUG to false?

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.

Why is BuildConfig.DEBUG set to false when executing local unit tests via Gradle?

I assume you have two flavors, debug and release.
If you run ./gradlew test, it will run two test task which are testDebugUnitTest and testReleaseUnitTest.

There are simple test case like following.

@Test fun test() {
assertTrue(BuildConfig.DEBUG)
}

It will succeed in the testDebugUnitTest task and fail in the testReleaseUnitTest task.
Also test task will fail.
Because test task dependsOn testReleaseUnitTest.

BuildConfig not getting created correctly (Gradle Android)

Please, be sure that you are building "dev" or "prod" variant. There is no BuildConfig definition in default "debug" and "release" variant. In Android Studio, you can select current variant in bottom left corner:

Build Variants

To simplify your build.gradle file, you can define:

buildTypes {
debug {
buildConfigField "String", "URL_SEARCH", "\"https://dev-search.example.com\""
// etc.
}
release {
buildConfigField "String", "URL_SEARCH", "\"https://search.example.com\""
// etc.
}
}

and then just use default "debug" and "release" variants.

At last, delete semicolon (sign: ';') from the value of buildConfigField parameter.

buildType goes always to release even I choose debug

According to Gradle documentation:

Library Publication:
By default a library only publishes its release variant. This variant will be used by all projects referencing the library, no matter which variant they build themselves. This is a temporary limitation due to Gradle limitations that we are working towards removing. You can control which variant gets published:

android {
defaultPublishConfig "debug"
}

So if you have a local lib and you want to debug it, you should add this parameter.

Gradle : how to use BuildConfig in an android-library with a flag that gets set in an app

You can't do what you want, because BuildConfig.SOME_FLAG isn't going to get propagated properly to your library; build types themselves aren't propagated to libraries -- they're always built as RELEASE. This is bug https://code.google.com/p/android/issues/detail?id=52962

To work around it: if you have control over all of the library modules, you could make sure that all the code touched by callToBigLibraries() is in classes and packages that you can cleave off cleanly with ProGuard, then use reflection so that you can access them if they exist and degrade gracefully if they don't. You're essentially doing the same thing, but you're making the check at runtime instead of compile time, and it's a little harder.

Let me know if you're having trouble figuring out how to do this; I could provide a sample if you need it.



Related Topics



Leave a reply



Submit