Hey all, I have some logic that executes inside k...
# android
h
Hey all, I have some logic that executes inside koltin [buildSrc] module, but this logic depends on BuildConf.DEBUG. And I can't find BuildConfig class inside this module. How can I achieve this? Thank you
w
It’s not possible.
buildSrc
is evaluated before the project is configured. You can think of
buildSrc
as a separate plugin you’d import, it doesn’t have any knowledge about the project where it’s used. What kind of logic is it?
Overall there’s also no such thing as
BuildConfig.DEBUG
in the context of Gradle configuration — what if you build both debug and release variants in the same Gradle invocation? (for example
./gradlew app:assembleDebug app:assembleRelease
)
😀 1
h
Oh! Thank you mate. I just figured out another way to do that
Copy code
applicationVariants.all { variant ->
            
            if (variant.buildType.name == "release"){
                variant.assemble.doFirst {
                    executeSomething()
                }
            } else if (variant.buildType.name == "homolog") {
                variant.assemble.doFirst { 
                }
            }
        }
That's interesting. I'm gonna try
Thank you
I think your solution it's a better way
😄
w
What you pasted is one way to do it. Remember though that you want to use Gradle’s lazy APIs for these things:
applicationVariants.configureEach { }
🙌 1
Otherwise you’re creating the release variant object during configuration even if you’re only building debug version. More details here: https://docs.gradle.org/current/userguide/task_configuration_avoidance.html
But also for the snippet you’ve pasted, you can simply configure
assembleRelease
and
assembleHomolog
tasks — these are well defined and part of the API (I think). So you don’t need to search for variants first, just do
project.tasks.named("assembleDebug") { taskProvider -> taskProvider.dependsOn("yourTaskName") }
. You then also need to register a
yourTaskName
task in the project, but that’s what you shoud aim to do with Gradle anyway (model your work using Tasks, not doFirst/doLast blocks)
h
Cool, I'm gonna try it