1

To disable generating BuildConfig with the Groovy DSL, one could do the following:

afterEvaluate {
    generateReleaseBuildConfig.enabled = false
    generateDebugBuildConfig.enabled = false
}

I am trying to find the equivalent when using Gradle's Kotlin DSL (build.gradle.kts). Anyone have any luck with this?

Programmer001
  • 2,240
  • 2
  • 19
  • 35

3 Answers3

5

If you have Android Studio 4.1 or greater you can use the Build Features Field to disable it per module.

android {
    ...

    buildFeatures {
        buildConfig = false
        resValues = false
    }
}
TheLuckyCoder
  • 536
  • 9
  • 10
2

I ended up finding this to work as well:

android { ... }

tasks.withType<GenerateBuildConfig> {
    isEnabled = false
}
Programmer001
  • 2,240
  • 2
  • 19
  • 35
1

You can remove BuildConfig from all variants by adding the following:

For library

android {
    ...

    // TODO replace with https://issuetracker.google.com/issues/72050365 once released.
    libraryVariants.all {
        generateBuildConfigProvider?.get()?.enabled = false
    }
}

For application

android {
    ...

    // TODO replace with https://issuetracker.google.com/issues/72050365 once released.
    applicationVariants.all {
        generateBuildConfigProvider?.get()?.enabled = false
    }
}

If you want to specify a build type , then:

libraryVariants
    .matching { it.buildType.name == "release"}
    .all {
        generateBuildConfigProvider?.get()?.enabled = false
    }
}
Furkan Akdemir
  • 101
  • 1
  • 6