Creating a separate Kotlin DSL gradle file to store the flavors of the app

I am trying to declare my android flavors in a separate gradle.kts file and then just apply them in my apps module gradle. But i keep getting Unresolved reference for “android”, “flavors” etc. etc. I tried to use the buildScripts folder for this, still no luck. How should this be done?

Any help is greatly appreciated!
Thank you,

1 Like

Hi @nicusorflorin did you find any solution on this ? i am having same issue

Don’t use legacy script plugins (the things you use with apply from).
They are bad practice by now.
Instead use convention plugins, for example implemented as precompiled script plugins.

Type-safe accessors like android { ... } you never get in legacy script plugins.
So you would need to use configure<TypeOfTheExtension> { ... } instead.

In precompiled script plugins you get the accessors for plugins you applied using the plugins { ... } block in the same script.

For plugins you applied in another plugin, you should use pluginManager.withPlugin(...) { ... } to make sure you only do the configuration after the plugin was actually applied and then again have to use configure... as no accessor will be present.

1 Like

thanks for the reply @Vampire sorry but i am new to Kotlin DSL and didn’t exactly understood what you are trying to say i have tried configuring Extension in separate DSL file but i am not able to still access android block can you please provide some code or link that is useful and i can take reference from it?

Thanks again looking forward for your reply

How do you use that extra file?
If you use it with apply from, I said you shouldn’t do it but read about convention plugins in the userguide :slight_smile:

As mentioned in original question also i am using this file to store flavors and than so that i can directly apply it in multiple build.gradle,kts

That doesn’t answer my question. I asked how you use it, not what you do inside. :wink: